-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete left-over Game Objects when changing LOD levels and when tiles… #2
Conversation
… are destroyed before the Game Object was spawned
else | ||
if (tiles.TryGetValue(tileKey, out tile)) | ||
{ | ||
if (tile.gameObject) RemoveGameObject(tile.gameObject); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fix #1 where a prior gameobject will be cleaned up, for example when changing the LOD
else | ||
{ | ||
// Tile was destroyed in the mean time.. destroy this game object too then. | ||
RemoveGameObject(newGameobject); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fix #2 where we destroy the game object again when the tile cannot be found anymore; we can assume the Tile was removed while the Coroutine was running
@@ -185,6 +182,9 @@ private IEnumerator LoadMetaData(GameObject gameObject, string geometryUrl) | |||
|
|||
private void ReadMetaDataFile(byte[] results, GameObject gameobject) | |||
{ | |||
// The gameobject could be destroyed in the mean time | |||
if (!gameobject) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor fix #3, because of the other changes we now need to take into consideration the GameObject may be 'destroying' in the same frame; using the ! operator will also check the lifecycle of a gameobject and return true if it technically still exists but is in the process of destroying
//activeTiles = new List<Vector2Int>(layer.tiles.Keys); | ||
var neededTiles = tileDistances[tilesizeIndex]; | ||
|
||
var neededTileKeys = new HashSet<Vector2Int>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance improvement: hashset lookups are O(1) where List lookups (using Contains) are O(n). This code is also simplified and will no longer use class-wide state for its internals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ziet er goed uit
… are destroyed before the Game Object was spawned