Hi! I've been restructuring my project and have run into a serious issue that I can't seem to understand why it's happening and haven't seen much online about it. I'm hoping someone will give me some sort of insight as to what's happening.
So I have been setting up classes and using inheritance to organize them nicely. They are as follows: -Saveable extends Node2D#For anything saving and loading -Interactable extends Saveable#For anything to be interacted with -BaseItem extends Interactable#General type for items -Snappable extends BaseItem#For anything that should snap to other objects -Farmplot extends Snappable#Handles behavior and data for the farm plot item
It's nothing too complicated. And this works fine when I place farm plot instances in the world and run. My issue arises in my autoload script.
In this script, I have an array that keeps track of the preview image, name, price, and a preloaded packed scene for every unique item in the game. itemArray = [ ItemData.new(preload(-img preview path-), -name-, -price-, preload(-packed scene path-)), ... ] (ItemData is a class that contains the corresponding data. I do this instead of an array of arrays for ease of access)
When I run this with the array filled, the preloaded scene for the farm plot item does not load properly. When instancing the preloaded scene and following it through the debugger with a breakpoint, the stack variables sections does not show the variables related to Interactable and BaseItem(the parent scripts to snappable). Because of this, the program attempts to initialize the variables in those parent scripts but initializes them onto the snappable variables, like there is some indexing issue... this is the part that puzzles me. When the program continues to initialize everything else, the snappable variables are set correctly. But this means that the variables in the parent classes are not initialized, so the game crashes when you attempt to reference them. And to make it even more confusing, this only happens when the snappable that is being preloaded is not the first one. If I move the farm plot item to be first in the array, it initializes fine.. but when an item is preloaded before that, it has this initialization issue.
I can provide pictures if my novel doesn't paint a clear enough picture. Any thoughts will be appreciated.
Thank you!