Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: Filip on December 10, 2013, 05:24:19 PM

Title: Strange behaviour in bundled AutoSync-example
Post by: Filip on December 10, 2013, 05:24:19 PM
I noticed I had to restart the dedicated server in order to get persistent gameobjects to sync. I thought it was something wrong with my code but I now tested the bundled AutoSync-example and it shares the same problem.

This is what you should do to replicate the problem:

1. Create new project with TNET imported.
2. Add "Example AutoJoin" and "Example AutoSync" in Build Settings. Make sure "Example AutoJoin" is top.
3. Check "Run in background" in "Player settings"
4. Run TNServer.exe
5. Build and run the project.
6. Open AutoJoin-scene and play in unity.
7. Everything is working as it should.
8. Stop unity and close the other game window.
9. Build and run.
10. Play in unity.
11. Not syncing anylonger.
Title: Re: Strange behaviour in bundled AutoSync-example
Post by: ArenMook on December 10, 2013, 10:40:16 PM
This happens because the object's owner is no longer there. I'm going to change it so that the object automatically gets a new owner, but in the meantime you can also fix it like so:
  1. public class MoveSpinObject : TNBehaviour
  2. {
  3.         void OnDrag (Vector2 delta)
  4.         {
  5.                 // Take control of the object if it has no owner present
  6.                 if (!tno.isMine && TNManager.GetPlayer(tno.ownerID) == null)
  7.                         tno.ownerID = TNManager.playerID;
  8.  
  9.                 if (tno.isMine)
  10.                 {
  11.                         Vector3 euler = transform.eulerAngles;
  12.                         euler.y -= delta.x * 0.5f;
  13.                         transform.eulerAngles = euler;
  14.  
  15.                         Vector3 pos = transform.position;
  16.                         pos.y += delta.y * 0.01f;
  17.                         transform.position = pos;
  18.                 }
  19.         }
  20. }
Title: Re: Strange behaviour in bundled AutoSync-example
Post by: ArenMook on December 10, 2013, 11:21:30 PM
Although the proper fix would be to change TNObject.Awake function to the following:
  1.         void Awake ()
  2.         {
  3.                 mOwner = TNManager.objectOwnerID;
  4.                 if (TNManager.GetPlayer(mOwner) == null)
  5.                         mOwner = TNManager.hostID;
  6.         }
I've checked it in like this into the Professional repository, so you will see it in the next update.
Title: Re: Strange behaviour in bundled AutoSync-example
Post by: Filip on December 11, 2013, 08:28:59 AM
Thanks a lot.
Title: Re: Strange behaviour in bundled AutoSync-example
Post by: ArenMook on December 12, 2013, 06:35:11 AM
As a note, I pushed that update last night.