#"The variable doesn't exist anymore" on variables still asigned in the inspector

1 messages · Page 1 of 1 (latest)

tame rain
#

Okay, I got something smelly going on.

In my script PlacableFurniture.cs I have a variable: SpriteRenderer[] _graphicVariants;. The variable is filled in prefab through editor (image).
Despite that I get this error message each time I'm trying to access a value within _graphicsVariants:
MissingReferenceException: The variable _graphicVariants of PlacableFurniture doesn't exist anymore.
The inspector values are still present at runtime in on-scene instances.

drowsy jungle
#

How are you attempting to access them?

tame rain
#

What the hell

Debug.Log(_graphicVariants != null);
Debug.Log(_graphicVariants.Length);
tame rain
# drowsy jungle How are you attempting to access them?

two ways:
swapping between them
_graphicVariants[i].gameObject.SetActive(i == _currentSpriteIndex);
coloring them dependant on collision
_graphicVariants[_currentSpriteIndex].color =(_collisions.Count > 0) ? new Color(1,0,0,1) : new Color(0,1,0,1);

#

current sprite index is a class scope variable

#

immediately forgot why I felt compelled to mention that 😆

tame rain
#

seems to be an engine bug, I switched variable type from SpriteRenderer[] to GameObject[] and it works like a charm

#

probably something sus going on with pointers to SpriteRenderer