I keep hitting the same problem over and over and I start to think that there is a flaw in the initialization sequence of PlayCanvas. Otherwise please tell me what I’m doing wrong and how to code it differently.
I have several scripts that make use of the initialize function to setup variables, arrays, and so on.
Then I have other classes (Controllers) that instruct the entities on what to do by calling some methods.
Many time it happens that I have to instantiate some entities as children of hidden UI elements (like unselected tabs o hidden views) and, at some unpredictable time (server-side messages, timers, or user input), I have to call some methods of the disabled entities that expect the initialization to be already executed.
But the initialize function is not called, causing me a lot of headaches.
So, in my opinion, the initialize function should be called as soon as an entity is cloned, and the
enabled function should not be called manually from inside the initialize. It’s just wrong. It should be raised when and if the entity gets enabled eventually.