playMaker

Author Topic: Why can't prefabs reference scene objects?  (Read 3374 times)

ergin

  • Junior Playmaker
  • **
  • Posts: 86
Why can't prefabs reference scene objects?
« 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.
« Last Edit: July 15, 2016, 01:42:17 AM by ergin »

cwmanley

  • Full Member
  • ***
  • Posts: 107
Re: Why can't prefabs reference scene objects?
« Reply #1 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.


ergin

  • Junior Playmaker
  • **
  • Posts: 86
Re: Why can't prefabs reference scene objects?
« Reply #2 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?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Why can't prefabs reference scene objects?
« Reply #3 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 :)

cwmanley

  • Full Member
  • ***
  • Posts: 107
Re: Why can't prefabs reference scene objects?
« Reply #4 on: July 17, 2016, 10:37:38 AM »
That's a great method  :)

Sorry, I meant Broadcasting a Global Event.

Thanks

ergin

  • Junior Playmaker
  • **
  • Posts: 86
Re: Why can't prefabs reference scene objects?
« Reply #5 on: July 17, 2016, 11:09:10 AM »
Thanks...