- Home /
List keeps emptying itself
Hello,
I have been running into a problem where (I think) a list keeps emptying itself.
So I have a base class called CustomBehaviour. It derives from the ScriptableObject class and is abstract. From this CustomBehaviour class I create child classes in which I can write behaviour code for NPC's (MineCrystals).
Lastly, I have a Unit script which has a list of CustomBehaviours and in the update it loops through that list and for every CustomBehaviour it find in the list it calls the Execute() function. This is the function in which the behaviour code is.
Base class, CustomBehaviour: https://hastebin.com/uxiwosinap.cs
Behaviour class, MineCrystals: https://hastebin.com/akibicakam.cs
Unit class:https://hastebin.com/qivejobuci.cs
Now the problem lies within the MineCrystal class. It has a list of CrystalMine that i set in the OnEnable function. The two Debug.Logs after that at line 24 and 25 return the mines perfectly.
However, the two Debug.Logs in the Execute() function at line 31 and 32 keep returning null, like the list has emptied itself.
I have already checked it the mines in the scene do not get deleted by accident but they don't.
What could cause this?
Thanks in advance!
When you say the calls in Execute()
return null, are you saying that m_$$anonymous$$inesList
is null or that the element m_$$anonymous$$inesList[0]
is null?
What is the value of m_$$anonymous$$inesList.Count
at the end of OnEnable()
? Inside Execute()
?
Are you sure that Execute()
is being called after OnEnable()
?