Author Topic: assign unique id for parent gameobject and the children gameobject  (Read 3856 times)

juanqinyang

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 1
    • View Profile
Hi, guys~ Now I am doing an peoject than need to synchronize the localposiiton of several child gameobject. To do so, now I attach the TNObject.cs to the parent gameObject and also every children gameobjects. And attach the TNAutoSync.cs to every child gameobjects to synchronize the locaoposition of them. I seems to work. But to synchronize a gameobject, it should have a unique id, but the TNAutoCreate.cs assign the same id to the parent and every child gameobject. How can I assign unique id to the parent and every child gameobject?



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: assign unique id for parent gameobject and the children gameobject
« Reply #1 on: July 21, 2015, 12:05:31 PM »
When you instantiate an object, TNet will give it a unique ID -- but only one. If you have nested TNObjects, they won't receive unique IDs because the order in which they can appear via GetComponentsInChildren is not guaranteed to be the same, so you may end up with RFCs going to the wrong objects.

The only way to do what you are trying to do properly, is to use only one TNObject/TNAutoSync script, and just referencing child's fields along with the object's.