How to destroy a TrueSyncBehavior GameObject? doc code doesn't work.

Hi Everyone,

the documentation seems to have a simple way to destroy a TrueSyncBehavior behavior using

public void OnSyncedCollisionEnter(GameObject other) { Destroy(other); }

but that doesn't work, it creates this error:

MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
TrueSync.LayerCollisionMatrix.CollisionEnabled (UnityEngine.GameObject goA, UnityEngine.GameObject goB) (at Assets/TrueSync/Unity/LayerCollisionMatrix.cs:32)
TrueSync.PhysicsWorldManager.IsCollisionEnabled (IBody rigidBody1, IBody rigidBody2) (at Assets/TrueSync/Unity/PhysicsWorldManager.cs:277)
TrueSync.World.CanBodiesCollide (TrueSync.RigidBody body1, TrueSync.RigidBody body2)
TrueSync.CollisionSystem.CheckBothStaticNonKinematic (IBroadphaseEntity entity1, IBroadphaseEntity entity2)
TrueSync.CollisionSystemPersistentSAP.Detect (Boolean multiThreaded)
TrueSync.World.Step (FP timestep, Boolean multithread)
TrueSync.PhysicsWorldManager.UpdateStep () (at Assets/TrueSync/Unity/PhysicsWorldManager.cs:76)
TrueSync.AbstractLockstep.ExecutePhysicsStep (System.Collections.Generic.List`1 data, Int32 syncedDataTick)
TrueSync.AbstractLockstep.Update ()
TrueSync.TrueSyncManager.FixedUpdate () (at Assets/TrueSync/Unity/TrueSyncManager.cs:703)

the only way seems to be using TrueSyncManager.SyncedDestroy(this.gameObject);

BUT, is it not an overhead? as I am already within a synched callback?




  • That is the correct way to use it!
  • Hi,

    Cool, thanks for the confirmation :)
  • I instantiated a gameobject using TrueSyncManager.SyncedInstantiate and when I went to remove the gameobject from existence I tried using TrueSyncManager.SyncedDestroy, which did not remove the gameobject; in fact, there wasn't even an error message. When I used GameObject.Destroy the object was removed. The gameobject has a script attached that derives from TrueSyncBehavior. What is the intended usage of TrueSyncManager.SyncedDestroy?
  • Hi @ScriptGeek, the idea of TSManager.SyncedDestroy is to destroy correctly objects managed by TrueSync, and by "correctly" I mean in the same frame/tick in every player connected as well taking care of rollback situation. It may not perform 100% right as you reported this issue. Thanks.