hi, I have a player class, that has the current tile he is on currently, named current_tile from type tile.
my issue: current_tile becomes null and I get NullRefernceException.
here is my code in start func:
void Start()
{
tile firstTile = tile_manager.instance.GetTileWithId(0);
if (firstTile == null)
{
Debug.Log(“fist tile is null”);
}
setCurrentTile(firstTile);
if(current_tile == null )
{
Debug.Log("badI");
}
}
set func:
private void setCurrentTile(tile tile_new) {
if (current_tile == null) {
Debug.Log(“bad given tile”);
}
else
{
current_tile = tile_new;
}
}
if I don’t use the set tile function and immediately assign the tile to the current tile everything works, but in the current example with debug log the outcome to the console is :
bad given tile
badI
this doesn’t make sense to me because:
1)there is no other code running in parallel that can change the current tile or any corutin, so how current tile change to null out of nowhere?
even if I assign the value instantly and solve this issue, a similar issue happens once again later on when it just becomes null out of nowhere even tho I track every change of the field, is this a known issue, can I get some guidance or help?