Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: ergin on July 14, 2016, 10:20:10 PM

Title: Why can't prefabs reference scene objects?
Post by: ergin on July 14, 2016, 10:20:10 PM
When I try to manipulate a scene object with a prefab It warns me that prefabs can't reference scene objects and references will be lost on save and load.

To overcome this problem, I'm attaching scripts to prefabs and broadcast messages to fsm's from the script. Is there an easier way of doing this?

Thanks.
Title: Re: Why can't prefabs reference scene objects?
Post by: cwmanley on July 16, 2016, 06:36:35 PM
This is normal.  :-[

A few methods I use.

Global Events.

Setting a Variable on the prefab right after I create or spawn it.

Naming the prefab according to the event or message it sends.

Title: Re: Why can't prefabs reference scene objects?
Post by: ergin on July 16, 2016, 09:11:30 PM
Thanks!

I agree, as Unity doesn't allow prefabs to reference scene objects.

how do you send global events?
Title: Re: Why can't prefabs reference scene objects?
Post by: djaydino on July 17, 2016, 07:21:55 AM
Hi,
What i do sometimes is set a gameobject into a global variable (for example my gamemanager fsm object) at the start of the game,
and on the prefab i use "Send Event By Name" and direct it to the global variable.

it still gives that warning but it should work fine. i did not have any problems yet with it on my projects :)
Title: Re: Why can't prefabs reference scene objects?
Post by: cwmanley on July 17, 2016, 10:37:38 AM
That's a great method  :)

Sorry, I meant Broadcasting a Global Event.

Thanks
Title: Re: Why can't prefabs reference scene objects?
Post by: ergin on July 17, 2016, 11:09:10 AM
Thanks...