Author Topic: [TNet] Trying to execute a function xy before it has been created.  (Read 3109 times)

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
I have currently a huge problem. I dont know what i did, but my game worked a few days ago, and now when a second player trys to join the game, it's freeze and than i got disconnected.
My first player is my builded .exe and my second player is my Unity Editor.

And during the freeze time i got the "[TNet] Trying to execute a function xy before it has been created." logs and about 250 times per gameobject..

Here is an screenshot of my editor


When i disable the synchronizing function, it works. But i didn't changed them.

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: [TNet] Trying to execute a function xy before it has been created.
« Reply #1 on: October 26, 2016, 08:37:02 PM »
I've had the same exact problem! Even the editor completely froze. I don't remember exactly what I did to fix it, though... I think I wrapped all relevant functions in an if (TNManager.isInChannel) block.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [TNet] Trying to execute a function xy before it has been created.
« Reply #2 on: October 30, 2016, 12:51:06 PM »
The "trying to execute" log message happens when a message arrives, but the target object is not present for any reason. Check your warnings -- you will get notified if TNet failed to create an object. My guess is you renamed a prefab you instantiated before, so now TNet can't find it for instantiation.

For convenience, when TNet can't create an object, it creates a dummy of it with a TNObject present. This lets you right-click it in inspector and choose to delete it, thus removing it from the server.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: [TNet] Trying to execute a function xy before it has been created.
« Reply #3 on: November 04, 2016, 12:08:38 PM »
I dont renamed a prefab or deleted it.

When a channel gets created and the player joins, all objects will be correctly instantiated without any errors. Than an another player joins the game and he got this errors.

I wrapped all my sync functions with if (TNManager.isInChannel) and it doesnt work...

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: [TNet] Trying to execute a function xy before it has been created.
« Reply #4 on: November 05, 2016, 04:18:19 AM »
This is my sync script for vehicles attached on each vehicle


  1. public class NetworkVehicle : NetworkTransform
  2. {
  3.     [Range(0.0f, 30.0f)]
  4.     public int m_updatesPerSecondInput = 10;
  5.  
  6.     private VehicleController m_vehicleController;
  7.  
  8.     public override void Awake()
  9.     {
  10.         base.Awake();
  11.  
  12.         m_vehicleController = GetComponent<VehicleController>();
  13.     }
  14.  
  15.     IEnumerator Start()
  16.     {
  17.         while (TNManager.isJoiningChannel) yield return null;
  18.  
  19.         StartCoroutine(PeriodicSync());
  20.         StartCoroutine(PeriodicSyncInput());
  21.     }
  22.  
  23.     //public override void Start ()
  24.     //{
  25.     //    base.Start();
  26.  
  27.                    
  28.     //}
  29.  
  30.     public override void Update ()
  31.     {
  32.         base.Update();
  33.     }
  34.  
  35.     IEnumerator PeriodicSyncInput()
  36.     {
  37.         for (;;)
  38.         {
  39.             if (TNManager.IsInChannel(tno.channelID) && IsOwnerOfThisObject)
  40.             {
  41.                 tno.SendQuickly("SetAxis", Target.OthersSaved, m_vehicleController.MovementInput, m_vehicleController.HandbrakeInput);
  42.             }
  43.  
  44.             yield return new WaitForSeconds(1f / m_updatesPerSecondInput);
  45.         }
  46.     }
  47.  
  48.     [RFC]
  49.     protected void SetAxis(Vector2 v, bool _handbrake)
  50.     {
  51.         m_vehicleController.MovementInput = v;
  52.         m_vehicleController.HandbrakeInput = _handbrake;
  53.     }
  54. }
  55.  


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [TNet] Trying to execute a function xy before it has been created.
« Reply #5 on: November 05, 2016, 09:33:20 AM »
NetworkTransform is a Unity class, and has nothing to do with TNet.

Check your object instantiation. Where is your TNObject located and what is its ID? Make sure it's instantiated via TNManager.Instantiate, not Object.Instantiate.

On a sidenote, if you want periodic updates, you should be using InvokeRepeating instead of coroutines.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: [TNet] Trying to execute a function xy before it has been created.
« Reply #6 on: November 05, 2016, 10:46:21 AM »
NetworkTransform is my own class. Posted on this thread(http://www.tasharen.com/forum/index.php?topic=14959.0)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [TNet] Trying to execute a function xy before it has been created.
« Reply #7 on: November 09, 2016, 12:44:57 PM »
This part of your NetworkTransform's Awake() function seems very wrong to me:
  1.         if (TNManager.isHosting)
  2.             m_currentOwner = TNManager.playerID;
Awake() is supposed to be used to cache local components and set local values. Accessing other classes in Awake() is a mistake. In your case you check TNManager.isHosting for some reason and cache the owner. Why? The host can change at any time due to players leaving. You should not be caching anything. Also the object's owner is tno.owner already.