playMaker

Author Topic: Parent a prefab to another prefab  (Read 3227 times)

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Parent a prefab to another prefab
« on: October 13, 2014, 07:18:05 AM »
Hi!

I need to parent a prefab to another prefab. But I get an error.

"Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption."

I tried to store the Prefabs in a Game Object variable, but it doesn't work.

How can I do this?
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Parent a prefab to another prefab
« Reply #1 on: October 13, 2014, 07:34:59 AM »
Nested prefabs are not supported in Unity 4.x but Unity 5.0 is supposed to have support.

Currently if you add prefabs to the scene, parent them, etc, then make that a prefab then it will simply create the prefab and the sub-prefabs are turned into unique objects.

I haven't seen that error though, how are you getting it?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Parent a prefab to another prefab
« Reply #2 on: October 14, 2014, 10:32:17 AM »
Hi!

I was thinking the same. :-)

I get the error if I use "Set Parent" and use Prefab A as game object and Prefab B as parent.
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Parent a prefab to another prefab
« Reply #3 on: October 14, 2014, 10:40:08 AM »
Ah, well, if you're targeting the prefab in the project hierarchy that wouldn't work anyway, Unity doesn't allow that. You need to target a scene object.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Parent a prefab to another prefab
« Reply #4 on: October 14, 2014, 05:26:37 PM »
My plan was to create a two prefabs in the scene where one of the prefab will parent the other. But I find another way. Thanks! :)
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

mweyna

  • Full Member
  • ***
  • Posts: 242
Re: Parent a prefab to another prefab
« Reply #5 on: October 14, 2014, 06:24:03 PM »
You could do something where you set a global variable upon creation, Set Game Object Parent and then on the next prefab, have an action where it sets that global variable object as it's parent. Just have to make sure your timing is right with the actions.