Author Topic: if(TNManager.isThisMyObject) error message  (Read 3369 times)

gevarre

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
if(TNManager.isThisMyObject) error message
« 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:

  1. using UnityEngine;
  2. using TNet;
  3.  
  4. public class GamePlayer : TNBehaviour
  5. {
  6.                
  7.         static public GamePlayer instance;
  8.                
  9.         void Awake()
  10.         {
  11.                 if(TNManager.isThisMyObject)
  12.                 {
  13.                         instance = this;
  14.                 }
  15.         }
  16. }
  17.  

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?

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: if(TNManager.isThisMyObject) error message
« Reply #1 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.

gevarre

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: if(TNManager.isThisMyObject) error message
« Reply #2 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: if(TNManager.isThisMyObject) error message
« Reply #3 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.

jasperjon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: if(TNManager.isThisMyObject) error message
« Reply #4 on: October 31, 2016, 10:51:22 AM »
So, is this correct?

  1. using TNet;
  2.  
  3. public class GamePlayer : TNBehaviour
  4. {
  5.     static public GamePlayer instance;
  6.     void Start()
  7.     {
  8.         if (tno.isMine)
  9.             instance = this;
  10.     }
  11.    
  12. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: if(TNManager.isThisMyObject) error message
« Reply #5 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.