playMaker

Author Topic: Global Variable GameObjects being confused with prefabs  (Read 2205 times)

allornothing

  • Playmaker Newbie
  • *
  • Posts: 20
Global Variable GameObjects being confused with prefabs
« on: March 01, 2015, 06:35:29 PM »
Hey

I've tried a few different attempts here to solve the problem and may have found a quirky but infuriating bug:

On Scene 1, I have a menu that allows the user to choose 5 objects and confirm their selection. On confirm, I look at the 5 objects and save their original prefabs from the library as gameobjects to 5 global variables. On loading the next scene, I look at the 5 globals and create the objects. However, these global vars are reset to None on scene switch.

Another method was to store the 5 global variables to a manager FSM which had its own 5 variables. I would DontDestoryOnLoad, and then grab its local variables and push them back out to the globals to repopulate. Still no dice, gameobject gloabals reset to none.

After trying some other prefabs, which worked, I pinpointed the issue:

If an instanced FSM tries to set the prefab it was instanced from to a global variable gameobject, it saves the instance reference instead.

I can repro this 100%.

Steps to repro:

- Instance a prefab in the scene which contains an FSM.
- In the FSM, save a reference to the original prefab to a global variable gameobject
- Before switching scene, observe the global variable has been populated correctly
- Switch scene, and notice the prefab reference is cleared out
- Change the Set Game Object to reference to any other prefab in the library (even if it exists as an instance in the same scene) and it will work.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Global Variable GameObjects being confused with prefabs
« Reply #1 on: March 03, 2015, 12:48:47 AM »
Hi,

I can't repro this at all.

 basically, the first issue I see here if the global variable loosing its reference, this is not happening here on my tests, I load a level and the globals remains untouched.

-- are you sure you have no fsm editing the global?
-- are you sure you are not pointing to the instance of the prefab instead? because that will get lost between scenes, globals can not be scene's object during editing.

Bye,

 Jean

allornothing

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Global Variable GameObjects being confused with prefabs
« Reply #2 on: March 03, 2015, 11:27:17 AM »
Defintely not referencing instance. I can repro this 100% - if the fsm on the prefab references itself (its own prefab), it references the instance of itself in live gameplay rather than the library prefab.

So if prefab X has an FSM that assigns prefab X to a gameobject variable, at runtime it will reference the instance, not the prefab. Not using get owner or anything, in the FSM I'm dragging the prefab from the library into the gameobject field, so I guess this is being stored as a reference to itself, rather the explicit link to the prefab. At runtime "itself" becomes the instance.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Global Variable GameObjects being confused with prefabs
« Reply #3 on: March 09, 2015, 02:55:21 AM »
Hi,

 What version of PlayMaker are you using?
 
Bye,

 Jean