playMaker

Author Topic: [SOLVED] FSMs on Prefabs can't reference objects in the scene  (Read 10440 times)

Disastercake

  • Full Member
  • ***
  • Posts: 101
  • www.disastercake.com
    • Disastercake
When trying to reference a gameobject in the scene when editing a FSM on a prefab, the Playmaker GUI won't accept any gameobjects from the hierarchy, only in the project panel.  Is this by design?
« Last Edit: May 29, 2012, 01:05:23 PM by Alex Chouls »
Soul Saga - Anime themed adventure RPG by Disastercake

http://www.disastercake.com

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: FSMs on Prefabs can't reference objects in the scene
« Reply #1 on: May 27, 2012, 09:41:48 PM »
Yes. This is a Unity limitation. If you're spawning a prefab in the scene that needs to know about scene objects, you have to find them at runtime. You'd need to do the same thing with scripts...

EDIT: But of course if you make a prefab instance at edit time, you can hook up scene object references on that instance. For this, and other reasons, some people use a "prototype scene object" approach instead of prefabs. There are pros and cons to both approaches...
« Last Edit: May 27, 2012, 09:47:16 PM by Alex Chouls »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: FSMs on Prefabs can't reference objects in the scene
« Reply #2 on: May 28, 2012, 01:43:43 AM »
Hi,

 What I do to overcome this limitation is to plug things are run time like Alex mentionned, this works very well, but you need to be very organized ( cause you would reference the Fsm by typing its name instead of selecting it from a list, since you won't get all the playmaker actions ui helpers during author time ( since you can't reference it, playmaker can't give you any drop down list of Fsm).

 Bye,

 Jean

Phillament

  • Playmaker Newbie
  • *
  • Posts: 44
Re: [SOLVED] FSMs on Prefabs can't reference objects in the scene
« Reply #3 on: December 13, 2013, 01:39:26 AM »
I'm having this exact issue, and while I've read the two responses, I still have nooooo idea what they are saying. I don't understand how to go about plugging things at run time. How does that work?

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: [SOLVED] FSMs on Prefabs can't reference objects in the scene
« Reply #4 on: December 13, 2013, 04:29:35 AM »
I'm having this exact issue, and while I've read the two responses, I still have nooooo idea what they are saying. I don't understand how to go about plugging things at run time. How does that work?

What they mean is that u need to create/place a instance of the prefab into a scene and than assign the missing references. This means in general terms u create a "final" prototype scene and there is no way u could construct this scene by xml files/templates alone. This is the way most game engines are setup and designed.

Thats what we also use, but u can extent this logic, by working with names/layers/tags ..... to "find/get" what u are looking for.

As example our security camera prefab needs a "base" and a "tracker" object, to work/rotate with. We don't even use direct object references to those child's, but try to find them by its name and assign/check them in a "Init" state. This has the advantage that while u can forget to properly name the object, even your artist/leveldesigner beginner programmer can now create and fiddle with the prefab itself, without the need to understand where and how he needs to wire up the missing/broken FSM references.

So we try to always use "soft" referencing, which means by name or tag/layer/component searches.

As example: If u would want to setup a self setup light-switch prefab, u have the problem that u either have to make the light a child of the prefab, so it will be saved or u need to manually assign the light to a object reference variable in the FSM and for this u need a scene instance.
The other way to get around this is to let the prefab look in range for a object that has a light component and also do a line of sight check maybe.

While the last version may not be work 100% of the time, u now just need to manually fix the cases where it breaks.

bye Andy

Boom7Games

  • Playmaker Newbie
  • *
  • Posts: 9
Re: [SOLVED] FSMs on Prefabs can't reference objects in the scene
« Reply #5 on: September 25, 2014, 05:22:30 AM »
Are there any tutorials on this ? cause all the explanations are pretty vague. Thanks

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: [SOLVED] FSMs on Prefabs can't reference objects in the scene
« Reply #6 on: September 25, 2014, 07:52:27 AM »
I don't think there is a specific tutorial for this, it's not as complicated as you might think.

What you cannot do:
Directly link a prefab to a scene object. For instance say "Prefab, blow this scene object up in 3 seconds."

What you can do:
Create a copy of that prefab object into your scene, then tell it "Prefab that is now an instanced copy and existing in the scene, wait 3 seconds, find the gameObject based on this information, and blow it up."

Does not work
Directly tell a Prefab (like an enemy unit) to Smooth Follow the Player. Like "Prefab, Smooth Follow this specific game object in my level."

Does work
Create a copy into the scene, find the player, then store it as a variable to follow. Like "Prefab that I just created into the scene, find the nearest object to you that has the tag 'player' and store it as a variable. Now use that variable in the Smooth Follow action."


So..

Scene objects are awake, prefabs are asleep in a sense.. You can create copies of prefabs into the scene when you instantiate them, which is just the process of instantiation, fancy way of saying that you're creating "instances" of something. It's just copies.

Nothing is alive or working or awake until it exists in the scene. Scenes are levels and as far as the runtime game is concerned if it isn't in the level then it doesn't exist. It's like shopping on the internet for a hammer. You need a hammer to kill that spider crawling up your leg but its not doing any good on the internet so you buy it with instant delivery and then you can put your hands on it and smite the spider. Until then, its just a hammer in some warehouse you look at through the internet. Nothing can happen until you order it.



Remember, there are two hierarchies: Scene and Project... Scene is like stuff you can immediately use, like the mouse and keyboard on your desk while Project hierarchy is the stuff in your closet.

Hope that makes sense.
« Last Edit: September 25, 2014, 07:54:47 AM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D