Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: krane on February 06, 2017, 04:32:48 PM

Title: Managing persistent array (e.g. inventory)
Post by: krane on February 06, 2017, 04:32:48 PM
I'm still confused about persistent data.
Let's say I have an arraylist in one scene that will control an inventory. If I want to reference that array list in another scene to add/remove objects, how do I do that? I know I can put this information into a loader and it will persist across all scenes, but how do I set up my FSMs to refer to that in development?
Title: Re: Managing persistent array (e.g. inventory)
Post by: marv on February 06, 2017, 04:54:35 PM
Have you tried setting the object your inventoryarray/table is attached to as a global variable, putting the object as "dontdestroyonload" and then referencing the global variable in your FSMs?
Title: Re: Managing persistent array (e.g. inventory)
Post by: elusiven on February 06, 2017, 05:17:15 PM
For example you have two GameObjects, Object A and B.

Arraylist with a reference "inventory_items" is on Object A.

If both GameObjects are active and Object A will be frequently used, on Object A, in the start state you do a "Get Owner" and store Object A as a global variable. Now on Object B to get that array all you have to do is use any arraylist action, and in the array owner select the Object A global variable, and put reference "inventory_items". Also as marv suggested, to persist a gameobject through scene, you want to make it dontdestroyonload

Now... You don't want to use global variables for every GameObject in the game... So for less important objects u can tag them, and use gameobject.findwithtag, and in playmaker I believe it's Find GameObject, but instead of putting the name in, you put the tag in.

Also an interesting tip: If you want to get a deactivated object, you can use get child instead of find gameobject. In my app I use this quite frequently because it's only one scene, but it has +10,000 levels and if you try to use find game object on a dedicated game object it will simply not find it.
Title: Re: Managing persistent array (e.g. inventory)
Post by: jeanfabre on February 08, 2017, 01:41:12 AM
Hi,

 Maybe using easySave would be easier, then it would persist both in game when swithching scenes and in dev and when app is shutdown and reopen.

 Bye,

 Jean