playMaker

Author Topic: [FIXED] GameObject variables are getting mixed up during play  (Read 1550 times)

nickfourtimes

  • Playmaker Newbie
  • *
  • Posts: 27
I've got an FSM in a prefab. On spawn, there's an init state that spawns some other stuff with the prefab. The state uses Create Object, and stores the object in a variable called spawnedObj. Then it uses Set Parent to set the parent of spawnedObj to itself (nesting the new object with the spawned prefab).

However, at runtime, when the prefab is spawned, I can inspect the instantiated prefab and see that the selection of GameObject variables has changed. In this case, say the FSM has many GameObject variables: spawnedObj, other1Obj, other2Obj, ...

Instead of Set Parent setting the parent of spawnedObj, as it is in the prefab, the action is now setting the parent of other1Obj (that is, in the Set Parent -> GameObject drop-down list, it's showing other1Obj).

Why would this happen?
« Last Edit: April 01, 2019, 12:00:42 PM by nickfourtimes »

nickfourtimes

  • Playmaker Newbie
  • *
  • Posts: 27
Re: [FIXED] GameObject variables are getting mixed up during play
« Reply #1 on: April 01, 2019, 12:04:57 PM »
Well, I don't quite understand how this got fixed, but it did.

One thing I noticed is that in the PM editor, the State tab would show "Prefab Instance (modified)" no matter how many times I hit "Apply" (both in the PM window and in the Unity inspector). If my FSM changes weren't being applied, that would explain why the spawned prefabs were spawning with the wrong variables used.

The only things I recognise having done were:
- I had a "Description" in one of my states, which I removed.
- I had a "Finish FSM" action in the last of my init states, which had a few other actions in it. I moved the Finish FSM action to a separate state all on its own.

I made these latter changes, then when I hit Apply the PM window simply showed "Prefab Instance" instead of "Prefab Instance (modified)," and the prefab was spawned properly in the game.

Azzak

  • Playmaker Newbie
  • *
  • Posts: 2
Re: [FIXED] GameObject variables are getting mixed up during play
« Reply #2 on: April 17, 2019, 11:52:34 AM »
It just happened to me, but I can not seem to fix it.

I have one instance that has "Prefab Instance (modified)".
If I click overrides, apply all, it does not do anything.
It does the same if I go to overrides, select the FSM, click apply.

I tried adding or removing a description, but it gets removed when I click apply.

Other than unpacking the instance, deleting the old prefab and make the object a prefab again, I do not see how to fix it ?

nickfourtimes

  • Playmaker Newbie
  • *
  • Posts: 27
Re: [FIXED] GameObject variables are getting mixed up during play
« Reply #3 on: April 17, 2019, 03:23:11 PM »
I'll answer my own post here (again).

I finally found this guide a few days ago. Basically, if you're working on an instance of a prefab in a scene, you can change the variables (or drag-and-drop object references) and then hit apply, and the changes should be reflected in the prefab on disk.

However, if you're changing the structure of the FSM – adding or removing actions or events, reordering states or actions, that sort of thing – then you really should be working on the prefab itself, on disk. Easiest way to do that is to hit "Select" either in the PM editor inspector, or in the Unity inspector itself... at that point you'll be working directly on the prefab. Of course, in this case, you can't now refer to objects in the scene, but that's a general Unity constraint anyway.

Once I read this article and started using "Select" to work directly in the prefabs, we no longer had this issue where our changes to the prefab instance weren't being applied.