Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Lobohotpants on July 23, 2012, 04:14:34 PM

Title: GameObject variables in Prefabs
Post by: Lobohotpants on July 23, 2012, 04:14:34 PM
I'm having some problems using variables containing GameObjects that are being referenced by Prefabs.  If I directly drag and drop the gameobject into the send event action it will send the event but it doesn't seem to work if the gameobject is in a variable.  I should also point out that the variables contain the prefab and directly dragging and dropping is from the hierarchy view.

I'm also having a similar problem with invoke method.

Added:  It will also work if I do a broadcast.  Would this cause any performance hit if I left it?
Any ideas?
Title: Re: GameObject variables in Prefabs
Post by: Alex Chouls on July 23, 2012, 06:50:21 PM
This is a limitation in Unity. Prefabs cannot store references to scene object (objects in the hierarchy view). Even if the UI allows it, the reference will not be saved. Actually if the UI allows it, it's a bug - I'll look into Send Event allowing this...

A common strategy is to find the GameObject at runtime and store it in a variable E.g. using the Find Game Object action.

Hope this helps.
Title: Re: GameObject variables in Prefabs
Post by: Lobohotpants on July 24, 2012, 12:58:38 PM
Thanks.  I'll try a Get Owner action and Set Object during setup and see if that works.
Title: Re: GameObject variables in Prefabs
Post by: Alex Chouls on July 24, 2012, 03:25:42 PM
You shouldn't need to do that for the Owner. Actions that can target Owner should work on prefabs that are instantiated in the scene.

But you will need to find other scene objects by name, tag etc.