Author Topic: How to Sync a Prefab child  (Read 4281 times)

Willie Prinsloo

  • Guest
How to Sync a Prefab child
« on: April 26, 2013, 04:41:12 PM »
Hi All

Busy Building a Tank Game. All my Tanks are syncing but not the tank turret. (Child object of the Tank.)

Getting the following error:

Network ID of 0 is used by "Player(Clone)/Cannon"
Please make sure that a unique non-zero ID is given to all objects.
UnityEngine.Debug:LogError(Object, Object)
TNObject:UniqueCheck() (at Assets/TNet/Client/TNObject.cs:175)
TNObject:Register() (at Assets/TNet/Client/TNObject.cs:219)
TNObject:Start() (at Assets/TNet/Client/TNObject.cs:202)

How can I sync a child object?

Thanks
Willie
 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to Sync a Prefab child
« Reply #1 on: April 26, 2013, 07:03:14 PM »
ID of 0 is invalid after instantiation. It must be non-zero. Zero ID on a prefab means "choose a unique ID after instantiation". Solution? Select the offending object and give it a non-zero ID.

Willie Prinsloo

  • Guest
Re: How to Sync a Prefab child
« Reply #2 on: April 26, 2013, 11:38:58 PM »
Thanks for the quick Response!

I understand that. The parent object of the prefab get's an unique ID after initialisation using TNAUTIO Create but no ID get assigned to the child Cannon object of the prefab. Must I assign it manually? If so how?

Thanks
Willie


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to Sync a Prefab child
« Reply #3 on: April 27, 2013, 03:14:40 PM »
Parent object of the prefab? Wait, what are you instantiating? Do you have more than one TNObject in the prefab hierarchy?

Willie Prinsloo

  • Guest
Re: How to Sync a Prefab child
« Reply #4 on: April 28, 2013, 12:36:45 PM »
Correct. One for the Tank and the other in hierarchy for the Turret. (Child of Tank.)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to Sync a Prefab child
« Reply #5 on: April 28, 2013, 04:15:57 PM »
How are you instantiating your tank?

Yarashiel

  • Guest
Re: How to Sync a Prefab child
« Reply #6 on: May 21, 2013, 09:02:04 AM »
Hi everyone !

I'm sorry for upping this post, but I have the exact same problem and no solutions have been shared in this topic.

To sum up I have my player object created containing a TNObject component ( he syncs his position...).
This object also have child objects, having each a TNObject because they communicate other properties (such as material , strings...).

The problem is the same as the orginal poster : IDs of TNObjects childs are already on the room (by, of course, the first player connected to the room...).

I'm pretty sure that I'm doint it wrong, so I would like to have advices from you guys.
Please ask me for more details concerning my issue.

Yarashiel

  • Guest
Re: How to Sync a Prefab child
« Reply #7 on: May 21, 2013, 09:35:00 AM »
Ok I "solved" my issue...

I've read an older topic concerning this problem. So I have solved it by doing what Arren recommended earlier : sending everything through network concerning the player (and even childs) by the parent...

However I still want some advices in order to make my script more efficient.
What I do basically is that I declare public gameobjects for each of my child I want to send properties and assign them on the inspector. I guess this is not a a good practice and I know that I could loop though childs and find the one I need by name or even by a variable I assign to identify them.

What's better ? what I am doing right now ( which I assume is dirty) or the looping ?

Thanks in advance

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to Sync a Prefab child
« Reply #8 on: May 21, 2013, 01:25:48 PM »
Best thing to do is have the manager script directly reference scripts and/or game objects by having a public variable for each. For example if I needed to have my "Tank" object to move a child (cannon), then I'd do this in the manager script:
  1. public Transform cannon;
I would then simply drag & drop this value in inspector. With the tank saved as a prefab, the value will always point to the right object on instantiated prefabs.

Yarashiel

  • Guest
Re: How to Sync a Prefab child
« Reply #9 on: May 22, 2013, 03:59:20 AM »
Ok perfect that's what I'm currently doing.

Thanks for the answer Aren, and congratz for Starlink ! The game really is interesting/addictive and looks good !

Jackazilion

  • Guest
Re: How to Sync a Prefab child
« Reply #10 on: May 23, 2013, 06:48:30 PM »
I also have a similar issue, ive got my player/Camera/Weapon which contains a gun script with RFC calls. Ive attached a TNO Object to both the player and the weapon objects as its required for the RFC to work. Is there another way i can call RFC without having the TNObject component?

  1.  
  2. tno.Send("Shoot", Target.Others, false, hit.point, rotation);
  3.        
  4. [RFC]
  5. void Shoot(bool shotOwner, Vector3 hitPoint, Quaternion rotation){
  6. if(hitParticles)
  7. Instantiate(hitParticles, hitPoint, rotation);
  8. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to Sync a Prefab child
« Reply #11 on: May 23, 2013, 08:49:03 PM »
As I suggested earlier in the thread, if you have a class called "Tank", then you likely should have a reference to the cannon, so when you shoot, you should send an RFC on the tank, not on the cannon.