[ad_1]
one among my gamers all the time, constantly get a NullReferenceException in a “shall be destroyed” behaviour. No different report have been despatched (they’re computerized). Solely from that system and I could not reproduce it.
My idea is that it is concerning some misterious behaviour of the rubbish gollector and Unity’s Destroy mechanism. (by the way in which I take advantage of IL2CPP)
Here is the setup:
-
All UI_TownLabels (MonoBehaviour desc.) reference a TownHallBehaviour. (MonoBehaviour desc.)
-
All TownHallBehaviour reference Tile (pure C#) object.
-
A Tile object holds references with something concerning that Tile, together with MonoBehaviour descendants, like TileBehaviour.
Here is the case:
-
When the person clicks on a button to finish the sport, a tween impact is began.
-
When it is completed, I destroy all TileBehaviours‘ gameObject, and all UI_TownLabels‘ gameObject.
-
Earlier than being destroyed, UI_TownLabel’s LateUpdate remains to be known as accurately, as a result of Destroy is efficient after the tip of the present body.
-
Nonetheless right here when it tries to get its TownHallBehaviour’s Tile’s TileBehaviour’s Rework’s Place, there’s a NullReferenceException.
Surprisingly evidently the TownHallBehaviour, the Tile, and the TileBehaviour are all NOT null. Solely the rework of the TileBehaviour. At the very least that is what suspect as a result of the exception comes from Tile.get_Position()
Here is what’s within the Label’s LateUpdate: var targetPosition = TownHallBehaviour.Tile.Place;
Here is a snippet from Tile:
public class Tile : TileBase
{
personal readonly TileBehaviour tileBehaviour;
public Tile(TileBehaviour tileBehaviour)
{
this.tileBehaviour = tileBehaviour;
}
public Vector3 Place
{
get { return Rework.place; }
}
public Rework Rework
{
get { return tileBehaviour.rework; }
}
}
(I assumed for a time that possibly this LateUpdate is within the subsequent body… and there’s a Label within the scene which is not within the Label assortment thus would not get destroyed…
… however the code for that’s easy, it seems to be good. And even when it might be the case, there should could be different gamers affected, or at the least it should not happen all the time for this person. Proper?)
Thanks upfront for all the assistance!
[ad_2]