playMaker

Author Topic: Add Array List + Global Variable madness  (Read 542 times)

vonpopov

  • Junior Playmaker
  • **
  • Posts: 98
Add Array List + Global Variable madness
« on: November 21, 2022, 04:29:44 PM »
Hi,

I have a problem that is quite hard to explain. I tryed to be logical, but failed, so I am here for Help.

Basically, I have an Object, which declare itself as "RTS MANAGER" and has an Arraylist as Component.

The object FSM that declare itself as RTS Manager, as Gameobject global variable



Then I have multiple objects that has to add themselves into an array list that is a component of RTS MANAGER as soon as engine start. But only one will add itself into the array list ....

The array list, that is working for ONLY one, items. (the only and first one, no copy, no prefab, no clone will work what evertechnique to duplicate)


For whatsoever reason, it refuses to be added to the array list by using the global variable content (RTS MANAGER gameobject)

Even if it recognize it (when engine runing, I can see everything is well)
You can check it there :

This FSM is basically trying to add items to the arraylist from start.


The only way I found to make it works, is not clean at all. For each item that need to be added into the array list, I have to replaced the Variable content (the one that point to the Gameobject global variable RTS MANAGER) by drag n droping the RTS MANAGER object itself. And tadaaa, this way it works.



So ? why ? What did I missed ? how can I make each object adding themselves to the arraylist, just using the Global Gameobject Variable (the one that point to the owner of the Arraylist component).



Regards
Help  :o ???



« Last Edit: November 21, 2022, 04:31:39 PM by vonpopov »

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Re: Add Array List + Global Variable madness
« Reply #1 on: November 21, 2022, 04:40:26 PM »
Are you allowing enough time for the RTS Manager to store itself in the global variable before trying to access it from other objects in the scene?

Try this.

Place a "Next Frame Event" action in the first state on your objects, and then in the next state use "Array List Add".

vonpopov

  • Junior Playmaker
  • **
  • Posts: 98
Re: Add Array List + Global Variable madness
« Reply #2 on: November 21, 2022, 04:54:20 PM »
Are you allowing enough time for the RTS Manager to store itself in the global variable before trying to access it from other objects in the scene?

Try this.

Place a "Next Frame Event" action in the first state on your objects, and then in the next state use "Array List Add".

Man ... you are my Hero.
This solved it instantly !!! how many hours lost going crazy on that ....  :D :D :D :D :-[

Thanks you SO MUCH !

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Re: Add Array List + Global Variable madness
« Reply #3 on: November 21, 2022, 06:16:49 PM »
No problem.

Execution or initialization order can be a tricky thing, there are plenty of different ways to deal with this specific problem. The official Hutong Games YouTube channel has a video on different initialization methods that's definitely worth checking out.

https://www.youtube.com/watch?v=IfPZ3RvThxI&ab_channel=HutongGames