Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | DoubleCakes |
I have an NPC node that is a tool and one of its script variables has a setter function attached that takes a string and uses it to find a sprite image (saved a .PNG) in the game folder to choose its sprite. I type in something like “CITPED2” and it looks inside the folder to find PED2.PNG in the CIT folder.
However, the line of script that sets the texture always returns an error:
Node not found: Sprite
res://Maps/Actors/{Scripts/NPC.gd:28 - Attempt to call function 'set_texture' in base 'null instance' on a null instance.
From what I read of this error, the function is not recognizing the Sprite and returning it as a ‘null instance’. It’s weird because despite getting an error, the script does was its supposed to do. In the editor, when I change the sprite_sheet variable (and the string is a valid location), the Sprite’s Texture changes without any other problems! But running this game is impossible because that error comes up on runtime just as it does in the editor.
I’m not sure what causes it, but if I remove that line changing the texture then I don’t get the error.
The error doesn’t pop up whenever I change the sprite_sheet variable, but whenever I save or load in the node. Maybe there’s something about what happens to a tool during save time that could enlighten us, but I’m still learning how tools work.
So I’m guessing this has to do with either setter functions or how tool nodes function in the editor. I’ve been trying at this for awhile and I’m really out of ideas. I couldn’t find the help I needed.