Hi Michael
I have the following situation after I updated to TNet 2.1.0b.
I replaced
TNManager.Destroy(gameobject)
with
This implied of course derivating my class from TNBehaviour rather then MonoBehaviour.
I had to do it in three classes. It all went well but in one class it gives me NullReferenceException and the tno.DestroySelf() issue doesnt come up in the stuck of the error. I had to find it by trial and error that it was this one the problem.
Here is the class where it happesn and in which i replaced with tno.DestroySelf()
using UnityEngine;
using System.Collections;
public class NDestroyEffect : TNBehaviour /*MonoBehaviour*/ {
// MyGlobalPersistent mGP = null;
/// <summary>
/// Start this instance.
/// </summary>
void Start () {
// mGP = GameObject.Find("MyGlobalPersistent").GetComponent<MyGlobalPersistent>();
if(this.gameObject.name != "ExplosionNeon")
StartCoroutine (KillMe());
}
/// <summary>
/// Update this instance.
/// </summary>
void Update () {
if(this.gameObject.name != "ExplosionNeon"){
if(NDPlayer.instance!=null){
this.transform.position = new Vector3
(NDPlayer
.instance.hips.transform.position.x,
NDPlayer.instance.hips.transform.position.y + .3f,
NDPlayer.instance.hips.transform.position.z);
}
}else{
if(NDShadow.instance!=null){
this.transform.position = new Vector3
(NDShadow
.instance.transform.position.x,
NDShadow.instance.transform.position.y + .3f,
NDShadow.instance.transform.position.z);
}
}
}
/// <summary>
/// Kills me.
/// </summary>
/// <returns>The me.</returns>
IEnumerator KillMe(){
yield return new WaitForSeconds
(0
.5f
);
//TNManager.Destroy(gameObject);
tno.DestroySelf();
}
}
You can see the two places in which i replaced the destruction.
and this is the Error Stack:
NullReferenceException: Object reference not set to an instance of an object
TNBehaviour.OnEnable () (at Assets/TNet/Client/TNBehaviour.cs:31)
UnityEngine.Object:Instantiate(Object, Vector3, Quaternion)
TNManager:OnCreate1(GameObject, Vector3, Quaternion) (at Assets/TNet/Client/TNManager.cs:1028)
System.Reflection.MethodBase:Invoke(Object, Object[])
TNet.UnityTools:ExecuteFirst(List`1, Byte, Object&, Object[]) (at Assets/TNet/Client/TNUnityTools.cs:103)
TNManager:CreateEx(Int32, Boolean, String, Object[]) (at Assets/TNet/Client/TNManager.cs:884)
TNManager:Create(String, Vector3, Quaternion, Boolean) (at Assets/TNet/Client/TNManager.cs:766)
NCharacterSpawner:SpawnEffectFromResourcesInPos(String, Vector3) (at Assets/_MyScripts/NCharacterSpawner.cs:293)
NGUILevelMngmnt:FireEffect(Int32) (at Assets/_MyScripts/NGUILevelMngmnt.cs:692)
NGUILevelMngmnt:PlayerClickedMove(GameObject) (at Assets/_MyScripts/NGUILevelMngmnt.cs:618)
NGUIManager:PerformMove(String, GameObject) (at Assets/_MyScripts/NGUIManager.cs:512)
NGUIManager:ChangeMoveGUI(GameObject) (at Assets/_MyScripts/NGUIManager.cs:424)
NMoveChangeClick:OnClick() (at Assets/_MyScripts/NMoveChangeClick.cs:16)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UICamera:Notify(GameObject, String, Object) (at Assets/NGUI/Scripts/UI/UICamera.cs:823)
UICamera:ProcessTouch(Boolean, Boolean) (at Assets/NGUI/Scripts/UI/UICamera.cs:1483)
UICamera:ProcessMouse() (at Assets/NGUI/Scripts/UI/UICamera.cs:1111)
UICamera:ProcessTouches() (at Assets/NGUI/Scripts/UI/UICamera.cs:1181)
UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:971)
In the stack the error doesnt show that the affected class is NDestroyEffect.cs at the line 46
If I replace with the deprecated TNManager.Destroy(gameobject); works but not if I also derive the class from TNBehaviour.
The class in which the NullRerence happens is TNBehaviour in fact at line 31
//---------------------------------------------
// Tasharen Network
// Copyright © 2012-2015 Tasharen Entertainment
//---------------------------------------------
using UnityEngine;
using TNet;
/// <summary>
/// If your MonoBehaviour will need to use a TNObject, deriving from this class will make it easier.
/// </summary>
[RequireComponent
(typeof(TNObject
))] public abstract class TNBehaviour : MonoBehaviour
{
[System.NonSerialized] TNObject mTNO;
public TNObject tno
{
get
{
if (mTNO == null) mTNO = GetComponent<TNObject>();
return mTNO;
}
}
protected virtual void OnEnable ()
{
if (Application.isPlaying)
{
tno.rebuildMethodList = true;
}
}
/// <summary>
/// Destroy this game object.
/// </summary>
public virtual void DestroySelf () { tno.DestroySelf(); }
}
precisely on the line
tno.rebuildMethodList = true;
If I comment the line
yield return new WaitForSeconds
(0
.5f
);
(of course putting a yield return null at the ned) in the method KillMe() the error stack returns another NullReferenceException also in the NDestroyEffect Class
At the moment my version is stable keeping the old method but I would really like to fix it.
Many thanks
Egi