Support => TNet 3 Support => Topic started by: gevarre on February 03, 2016, 07:58:30 PM
Title: if(TNManager.isThisMyObject) error message
Post by: gevarre on February 03, 2016, 07:58:30 PM
Hi, I'm using Tnet 3 and following the old "TNet: Making a Game from Scratch" tutorial.
In my GamePlayer script I've got this:
usingUnityEngine;
usingTNet;
publicclass GamePlayer : TNBehaviour
{
staticpublic GamePlayer instance;
void Awake()
{
if(TNManager.isThisMyObject)
{
instance =this;
}
}
}
Unfortunately, I'm getting this error: Assets/_Scripts/GamePlayer.cs(11,30): error CS0117: `TNManager' does not contain a definition for `isThisMyObject'
Any ideas? It's a new, empty project and I'm using Unity 5.3.1f1
Note: at 15.28 of the tutorial video, the GameObject in the start scene suddenly has the TNManager script attached to it. If I just click on the "Add Component" button, this doesn't show up. I had to manually find the script and drag it onto the object. Could this be significant or just the way it works?
Title: Re: if(TNManager.isThisMyObject) error message
Post by: cmifwdll on February 04, 2016, 06:42:40 AM
I don't have TNet 3, but try tno.isMine instead of TNManager.isThisMyObject. Remember to derive from TNBehaviour.
In TNet 2, TNManager component can be added from Add Component > TNet > Network Manager. Not sure if this has changed in TNet 3.
I think TNet 3 is still technically a beta, so I imagine there'll probably be better documentation / updated tutorials upon its official release.
Title: Re: if(TNManager.isThisMyObject) error message
Post by: gevarre on February 04, 2016, 01:43:29 PM
Thanks. Those are good points.
tno.isMine doesn't seem to give any errors. Unfortunately, according to the docs, that's not for use in a Start function (unless TNManager.isThisMyObject is being deprecated and you should now just use tno.isMine everywhere?)
I do admit the tutorial is pretty old, so maybe things have just changed. I did experiment a bit, and version 2.1.1 does work fine with the latest Unity build, so I don't think that's the cause.
Title: Re: if(TNManager.isThisMyObject) error message
Post by: ArenMook on February 04, 2016, 09:31:27 PM
Awake() is not the right place for these kinds of checks. You should be checking tno.isMine in Start() instead.
I will be making a new "make a game from scratch" tutorial to go with TNet 3 soon.
Title: Re: if(TNManager.isThisMyObject) error message
Post by: jasperjon on October 31, 2016, 10:51:22 AM
So, is this correct?
usingTNet;
publicclass GamePlayer : TNBehaviour
{
staticpublic GamePlayer instance;
void Start()
{
if(tno.isMine)
instance =this;
}
}
Title: Re: if(TNManager.isThisMyObject) error message
Post by: ArenMook on November 03, 2016, 08:19:06 AM
Place-wise it's fine, yes. Start() is called after the creation finishes.
However "tno.isMine" tells you that you own this object. If your GamePlayer object gets instantiated as persistent, and you leave, then when you come back, it will still be there. Likewise if there were two players and left, then one comes back, this player will now own both objects.
If the object was created as not persistent, then this won't happen and your code will work fine.