Author Topic: RFC got fired only at the third try  (Read 2325 times)

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
RFC got fired only at the third try
« on: November 04, 2016, 09:54:34 AM »
This happens on my vehicle.
When i try to enter it, i need to press it a few times and than i can get into it. (Im asking the hoster, if i can access this vehicle)

Error Message:
  1. NullReferenceException: Object reference not set to an instance of an object
  2. TNet.TNObject.RebuildMethodList () (at Assets/ThirdParty/TNet/Client/TNObject.cs:637)
  3. TNet.TNObject.Execute (System.String funcName, System.Object[] parameters) (at Assets/ThirdParty/TNet/Client/TNObject.cs:541)
  4. TNet.TNObject.SendRFC (Byte rfcID, System.String rfcName, Target target, Boolean reliable, System.Object[] objs) (at Assets/ThirdParty/TNet/Client/TNObject.cs:882)
  5. TNet.TNObject.Send (System.String rfcName, Target target, System.Object[] objs) (at Assets/ThirdParty/TNet/Client/TNObject.cs:685)
  6. NetworkTransform.SetLocalWantControl (Boolean _set) (at Assets/GameAssets/Scripts/Network/NetworkTransform.cs:216)
  7. VehicleSeats.EnterVehicleLocal (Boolean _enter, UnityEngine.GameObject _player) (at Assets/GameAssets/Scripts/Vehicle/VehicleSeats.cs:74)
  8. VehicleController.OnTriggerStay (UnityEngine.Collider other) (at Assets/GameAssets/Scripts/Vehicle/VehicleController.cs:107)

VehicleController.cs:107
  1. m_vehicleSeats.EnterVehicleLocal(true, m_player);

VehicleSeats.cs:74 (m_networkVehicle is a Child Class from NetworkTransform)
  1. m_networkVehicle.SetLocalWantControl(true);

NetworkTransform.cs:216
  1. public void SetLocalWantControl(bool _set)
  2.     {
  3.         tno.Send("OnPlayerWantControls", Target.Host, TNManager.playerID, _set);
  4.     }
  5.  
  6.     [RFC]
  7.     void OnPlayerWantControls(int _playerID, bool _set)
  8.     {
  9.         if (_set) //PLAYER WANT CONTROL
  10.         {
  11.             if (IsOwnerOfThisObject) //HOSTER CONTROLS THIS OBJ
  12.             {
  13.                 OwnerOfThisObject = _playerID;
  14.             }
  15.         }
  16.         else //PLAYER DONT WANT CONTROL - LET HOSTER CONTROL
  17.         {
  18.             OwnerOfThisObject = TNManager.playerID;
  19.         }
  20.  
  21.         tno.Send("OnPlayerGetControls", Target.Others, m_currentOwner);
  22.     }
  23.  
  24.     [RFC]
  25.     void OnPlayerGetControls(int _newOwner)
  26.     {
  27.         OwnerOfThisObject = _newOwner;
  28.     }
  29.  
  30.     public bool IsOwnerOfThisObject
  31.     {
  32.         get
  33.         {
  34.             return OwnerOfThisObject == TNManager.playerID;
  35.         }
  36.     }
  37.  
  38.     public bool HostOwnsThisObject
  39.     {
  40.         get
  41.         {
  42.             return IsOwnerOfThisObject && TNManager.isHosting;
  43.         }
  44.     }
  45.  
  46.     public int OwnerOfThisObject
  47.     {
  48.         get
  49.         {
  50.             return m_currentOwner;
  51.         }
  52.         set
  53.         {
  54.             m_currentOwner = value;
  55.         }
  56.     }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: RFC got fired only at the third try
« Reply #1 on: November 05, 2016, 09:39:01 AM »
Once again, NetworkTransform is a Unity class and has nothing to do with TNet.

You need a TNObject for communication, and to instantiate via TNManager.Instantiate, otherwise nothing will work properly.

Please follow the TNet's tutorials on this. Nowhere is NetworkTransform mentioned or used.
  1. tno.Send("RequestTakeControl", tno.owner, TNManager.playerID);
  1. [RFC] protected void RequestTakeControl (int playerID)
  2. {
  3.     tno.Send("SetControl", Target.AllSaved, playerID);
  4. }
  5.  
  6. [RFC] protected void SetControl (int playerID)
  7. {
  8.     var player = TNManager.FindPlayer(playerID);
  9.     // Take control here
  10. }

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: RFC got fired only at the third try
« Reply #2 on: November 05, 2016, 10:26:34 AM »
NetworkTransform is my own script. I dont use Unity Networking.

Thats my NetworkTransform:
  1. using UnityEngine;
  2. using System.Collections;
  3. using TNet;
  4.  
  5. public abstract class NetworkTransform : TNBehaviour
  6. {
  7.     private int m_currentOwner = 0;
  8.  
  9.     [Range(0.0f, 30.0f)]
  10.     public int m_updatesPerSecond = 20;
  11.  
  12.     [Range(0.0f, 10.0f)]
  13.     public double m_InterpolationBackTime = 0.1;
  14.  
  15.     [Range(0.0f, 20.0f)]
  16.     public double m_ExtrapolationLimit = 0.5;
  17.  
  18.     [HideInInspector]
  19.     public CharacterController m_characterController;
  20.     [HideInInspector]
  21.     public PlayerController m_playerController;
  22.  
  23.     private Rigidbody m_rigidBody;
  24.  
  25.     internal struct State
  26.     {
  27.         internal double timestamp;
  28.         internal Vector3 pos;
  29.         internal Vector3 velocity;
  30.         internal Vector3 angularVelocity;
  31.         internal Quaternion rot;
  32.         internal Vector3 moveInput;
  33.         internal Quaternion mouseInput;
  34.     }
  35.  
  36.     // We store twenty states with "playback" information
  37.     State[] m_BufferedState = new State[20];
  38.     // Keep track of what slots are used
  39.     int m_TimestampCount;
  40.  
  41.     public virtual void Awake()
  42.     {
  43.         if (GetComponent<Rigidbody>() != null)
  44.         {
  45.             m_rigidBody = GetComponent<Rigidbody>();
  46.         }
  47.  
  48.         if (TNManager.isHosting)
  49.             m_currentOwner = TNManager.playerID;
  50.     }
  51.  
  52.     public virtual void Start()
  53.     {
  54.     }
  55.  
  56.     public virtual void Update ()
  57.     {
  58.         if (!tno.isMine)
  59.             InterpolateTransform();
  60.     }
  61.  
  62.     public IEnumerator PeriodicSync()
  63.     {
  64.         for (;;)
  65.         {
  66.             if (TNManager.IsInChannel(tno.channelID))
  67.             {
  68.                 if (IsOwnerOfThisObject)
  69.                 {
  70.                     Sync();
  71.                 }
  72.                 else if (HostOwnsThisObject)
  73.                 {
  74.                     Sync();
  75.                 }
  76.             }
  77.             yield return new WaitForSeconds(1f / m_updatesPerSecond);
  78.         }
  79.     }
  80.  
  81.     void Sync()
  82.     {
  83.         if (m_rigidBody != null)
  84.         {
  85.             tno.SendQuickly("SetTransform", Target.OthersSaved, m_rigidBody.position, m_rigidBody.rotation, m_rigidBody.velocity, m_rigidBody.angularVelocity, Vector3.zero, Quaternion.identity);
  86.         }
  87.         else
  88.         {
  89.             tno.SendQuickly("SetTransform", Target.OthersSaved, transform.position, transform.rotation, Vector3.zero, Vector3.zero, Vector3.zero, Quaternion.identity);
  90.         }
  91.     }
  92.  
  93.     void InterpolateTransform()
  94.     {
  95.         // We have a window of interpolationBackTime where we basically play
  96.         // By having interpolationBackTime the average ping, you will usually use interpolation.
  97.         // And only if no more data arrives we will use extra polation
  98.  
  99.         // This is the target playback time of the rigid body
  100.         double interpolationTime = Time.time - m_InterpolationBackTime;
  101.  
  102.         // Use interpolation if the target playback time is present in the buffer
  103.         if (m_BufferedState[0].timestamp > interpolationTime)
  104.         {
  105.             // Go through buffer and find correct state to play back
  106.             for (int i = 0; i < m_TimestampCount; i++)
  107.             {
  108.                 if (m_BufferedState[i].timestamp <= interpolationTime || i == m_TimestampCount - 1)
  109.                 {
  110.                     // The state one slot newer (<100ms) than the best playback state
  111.                     State rhs = m_BufferedState[Mathf.Max(i - 1, 0)];
  112.                     // The best playback state (closest to 100 ms old (default time))
  113.                     State lhs = m_BufferedState[i];
  114.  
  115.                     // Use the time between the two slots to determine if interpolation is necessary
  116.                     double length = rhs.timestamp - lhs.timestamp;
  117.                     float t = 0.0F;
  118.                     // As the time difference gets closer to 100 ms t gets closer to 1 in
  119.                     // which case rhs is only used
  120.                     // Example:
  121.                     // Time is 10.000, so sampleTime is 9.900
  122.                     // lhs.time is 9.910 rhs.time is 9.980 length is 0.070
  123.                     // t is 9.900 - 9.910 / 0.070 = 0.14. So it uses 14% of rhs, 86% of lhs
  124.                     if (length > 0.0001)
  125.                         t = (float)((interpolationTime - lhs.timestamp) / length);
  126.  
  127.                     // if t=0 => lhs is used directly
  128.                     transform.localPosition = Vector3.Lerp(lhs.pos, rhs.pos, t);
  129.                     transform.localRotation = Quaternion.Slerp(lhs.rot, rhs.rot, t);
  130.  
  131.                     if(m_playerController != null)
  132.                     {
  133.                         m_playerController.MoveInput = Vector3.Lerp(lhs.moveInput, rhs.moveInput, t);
  134.                         m_playerController.MouseInput = Quaternion.Slerp(lhs.mouseInput, rhs.mouseInput, t);
  135.                     }
  136.                     return;
  137.                 }
  138.             }
  139.         }
  140.         // Use extrapolation
  141.         else
  142.         {
  143.             State latest = m_BufferedState[0];
  144.  
  145.             float extrapolationLength = (float)(interpolationTime - latest.timestamp);
  146.             // Don't extrapolation for more than 500 ms, you would need to do that carefully
  147.             if (extrapolationLength < m_ExtrapolationLimit)
  148.             {
  149.                 float axisLength = extrapolationLength * latest.angularVelocity.magnitude * Mathf.Rad2Deg;
  150.                 Quaternion angularRotation = Quaternion.AngleAxis(axisLength, latest.velocity);
  151.  
  152.                 if (m_rigidBody != null)
  153.                 {
  154.                     m_rigidBody.position = latest.pos + latest.angularVelocity * extrapolationLength;
  155.                     m_rigidBody.rotation = angularRotation * latest.rot;
  156.                     m_rigidBody.velocity = latest.velocity;
  157.                     m_rigidBody.angularVelocity = latest.angularVelocity;
  158.                 }
  159.                 else
  160.                 {
  161.                     transform.position = latest.pos + latest.angularVelocity * extrapolationLength;
  162.                     transform.rotation = angularRotation * latest.rot;
  163.  
  164.                     if (m_playerController != null)
  165.                     {
  166.                         m_playerController.MoveInput = latest.moveInput;
  167.                         m_playerController.MouseInput = latest.mouseInput;
  168.                     }
  169.  
  170.                     if (m_characterController != null)
  171.                     {
  172.                         m_characterController.SimpleMove(latest.velocity);
  173.                     }
  174.                 }
  175.             }
  176.         }
  177.     }
  178.  
  179.     [RFC]
  180.     protected void SetTransform(Vector3 pos, Quaternion rot, Vector3 vel, Vector3 angularVelocity, Vector3 moveInput, Quaternion mouseInput)
  181.     {
  182.         // Shift the buffer sideways, deleting state 20
  183.         for (int i = m_BufferedState.Length - 1; i >= 1; i--)
  184.         {
  185.             m_BufferedState[i] = m_BufferedState[i - 1];
  186.         }
  187.  
  188.         // Record current state in slot 0
  189.         State state;
  190.         state.timestamp = Time.time;
  191.         state.pos = pos;
  192.         state.velocity = vel;
  193.         state.rot = rot;
  194.         state.angularVelocity = angularVelocity;
  195.         state.moveInput = moveInput;
  196.         state.mouseInput = mouseInput;
  197.         //state.input = input;
  198.         m_BufferedState[0] = state;
  199.  
  200.         // Update used slot count, however never exceed the buffer size
  201.         // Slots aren't actually freed so this just makes sure the buffer is
  202.         // filled up and that uninitalized slots aren't used.
  203.         m_TimestampCount = Mathf.Min(m_TimestampCount + 1, m_BufferedState.Length);
  204.  
  205.         // Check if states are in order, if it is inconsistent you could reshuffel or
  206.         // drop the out-of-order state. Nothing is done here
  207.         for (int i = 0; i < m_TimestampCount - 1; i++)
  208.         {
  209.             if (m_BufferedState[i].timestamp < m_BufferedState[i + 1].timestamp)
  210.                 Log.Info("State inconsistent");
  211.         }
  212.     }
  213.  
  214.     public void SetLocalWantControl(bool _set)
  215.     {
  216.         tno.Send("OnPlayerWantControls", Target.Host, TNManager.playerID, _set);
  217.     }
  218.  
  219.     [RFC]
  220.     void OnPlayerWantControls(int _playerID, bool _set)
  221.     {
  222.         if (_set) //PLAYER WANT CONTROL
  223.         {
  224.             if (IsOwnerOfThisObject) //HOSTER CONTROLS THIS OBJ
  225.             {
  226.                 OwnerOfThisObject = _playerID;
  227.             }
  228.         }
  229.         else //PLAYER DONT WANT CONTROL - LET HOSTER CONTROL
  230.         {
  231.             OwnerOfThisObject = TNManager.playerID;
  232.         }
  233.  
  234.         tno.Send("OnPlayerGetControls", Target.Others, m_currentOwner);
  235.     }
  236.  
  237.     [RFC]
  238.     void OnPlayerGetControls(int _newOwner)
  239.     {
  240.         OwnerOfThisObject = _newOwner;
  241.     }
  242.  
  243.     public bool IsOwnerOfThisObject
  244.     {
  245.         get
  246.         {
  247.             return OwnerOfThisObject == TNManager.playerID;
  248.         }
  249.     }
  250.  
  251.     public bool HostOwnsThisObject
  252.     {
  253.         get
  254.         {
  255.             return IsOwnerOfThisObject && TNManager.isHosting;
  256.         }
  257.     }
  258.  
  259.     public int OwnerOfThisObject
  260.     {
  261.         get
  262.         {
  263.             return m_currentOwner;
  264.         }
  265.         set
  266.         {
  267.             m_currentOwner = value;
  268.         }
  269.     }
  270. }
  271.  

Whats really suspicious, i have about 10 cars. And only one car make this error. All other 9 cars work, without any error.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: RFC got fired only at the third try
« Reply #3 on: November 09, 2016, 12:41:47 PM »
Hmm... So what's line 637 of TNObject for you where the error happens? What's actually null?