playMaker

Author Topic: Referencing a child object in prefabs  (Read 2565 times)

lukew

  • Playmaker Newbie
  • *
  • Posts: 32
    • View Profile
Referencing a child object in prefabs
« on: November 02, 2015, 05:41:45 AM »
Hello,

I know that it's impossible to reference a scene object in prefabs or templates. Anyway, Playmaker editor allows me to make a reference to the child object of a prefab (after choosing edit instance instead of edit prefab) and this prefab still works fine in other scenes after instantiating it (reference to its child object is not lost).

The question is - should I do that? Is it fine to make references to child objects in prefabs? Is there a chance that they would be lost in some specific circumstances? Or maybe this is appropriate technique?

Please let me know what do you think.
« Last Edit: November 02, 2015, 06:43:26 AM by lukew »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4436
    • View Profile
    • jinxtergames
Re: Referencing a child object in prefabs
« Reply #1 on: November 02, 2015, 01:24:36 PM »
Hi,
I think thats fine.
when your "prefab" is inside the scene from the start it will work just the same as if it was not a prefab.
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

lukew

  • Playmaker Newbie
  • *
  • Posts: 32
    • View Profile
Re: Referencing a child object in prefabs
« Reply #2 on: November 03, 2015, 12:07:58 AM »
Hi,

The thing is that it works fine when it's not in the scene but it's instantiated in different scene. References works and are not lost as long as they are pointing to GameObjects that are child objects of this prefab.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4436
    • View Profile
    • jinxtergames
Re: Referencing a child object in prefabs
« Reply #3 on: November 03, 2015, 12:50:54 AM »
Hi,
Hmm.. but if you edit the instance and not the prefab it only changes the object in that scene and not the prefab.
If you drop your prefab in another scene the changes should not be there.
unless you click on prefab "apply" in the inspector.

but yes,
if your prefab is referencing to one of his children that will work
and i tried with a "send event" to a child while editing prefab (not instance) and that works also.

and i think that will work fine.
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

lukew

  • Playmaker Newbie
  • *
  • Posts: 32
    • View Profile
Re: Referencing a child object in prefabs
« Reply #4 on: November 03, 2015, 02:38:06 AM »
Quote
Hmm.. but if you edit the instance and not the prefab it only changes the object in that scene and not the prefab.
If you drop your prefab in another scene the changes should not be there.
unless you click on prefab "apply" in the inspector.

Yes, I'm always applying changes to prefab and then the references to child objects in FSMs of this prefab are working on other scenes.

When editing instance (and applying changes to prefab), it's possible to keep GameObjects references to all GameObjects that are in the hierarchy under the parent (children of children too).
When editing prefab, it's still possible to keep GameObject references, but only to objects that are under the parent in the first branch (can't set objects that are children of children).

Anyway, I've noticed that editing larger FSM (~100 states) on instance is much slower than editing it on prefab so I will probably use get/find child for objects that are in lower branches and can't be set manually while editing prefab.

Thanks for the replies!
« Last Edit: November 03, 2015, 03:43:17 AM by lukew »

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • View Profile
    • Homepage
Re: Referencing a child object in prefabs
« Reply #5 on: November 04, 2015, 02:28:10 PM »
Hi!

I always use global game object variables if I have many levels (Scenes)!
Then I can make changes on the scene object in one level and this object will make the changes in all the levels, just need to apply. Or I can make the changes in the prefabs. So I always reference to a global game object. :)
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

thatnzguy

  • Playmaker Newbie
  • *
  • Posts: 43
    • View Profile
Re: Referencing a child object in prefabs
« Reply #6 on: November 05, 2015, 03:17:36 PM »
In a scene you can make your object with children, set your FSM up to reference them (I set 'inspector' on reference variables). Then make your object a prefab, you'll see the references are lost, however if you overwrite the prefab with the object you just used to make it, then the references stick.