playMaker

Author Topic: What's different between drag-assign a GO and creating a GO variable?  (Read 1469 times)

mekoid

  • Playmaker Newbie
  • *
  • Posts: 36
I always wonder about this. Anyone please?
Like if I drag-assign a GO from the child of a GO and create a prefab, will the link work? What's different if I use Find Child and the variables stuff?
Thanks
« Last Edit: February 02, 2015, 12:17:03 AM by mekoid »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: What's different between drag-assign a GO and creating a GO variable?
« Reply #1 on: February 02, 2015, 07:10:24 AM »
If you try to link a prefab to a scene object the link will not work, it may work for one Play but Unity will break it. This is because scenes are typically changing and the Project Hierarchy is not so if you change the scene and that object disappears then you have broken linkage in the Project so Unity doesn't allow it.

Now when creating Prefabs you can actually link anything in that prefab hierarchy together via drag-n-drop and Unity will recognize that all of the links are relative and aren't going to change so the prefab made will retain the links between all of the children and/or main parent object.

This is a much better method of doing prefabs when you need to assign variables within a prefab's local hierarchy than if you would use Find Child or try to use Get Parent multiple times to move up a stack. The result is the same, but its generally easier to drag the variables directly if it fits your circumstances and if it is all within the same local prefab hierarchy then you don't have to worry about it breaking the connection.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

mekoid

  • Playmaker Newbie
  • *
  • Posts: 36
Re: What's different between drag-assign a GO and creating a GO variable?
« Reply #2 on: February 02, 2015, 10:51:12 AM »
That's very helpful!! Thanks so much!!  ;D