playMaker

Author Topic: GameObject variables in Prefabs  (Read 2279 times)

Lobohotpants

  • Playmaker Newbie
  • *
  • Posts: 38
    • View Profile
GameObject variables in Prefabs
« on: July 23, 2012, 01: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?
« Last Edit: July 23, 2012, 01:16:56 PM by Lobohotpants »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3632
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: GameObject variables in Prefabs
« Reply #1 on: July 23, 2012, 03: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.

Lobohotpants

  • Playmaker Newbie
  • *
  • Posts: 38
    • View Profile
Re: GameObject variables in Prefabs
« Reply #2 on: July 24, 2012, 09:58:38 AM »
Thanks.  I'll try a Get Owner action and Set Object during setup and see if that works.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3632
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: GameObject variables in Prefabs
« Reply #3 on: July 24, 2012, 12: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.