Author Topic: Connecting to scene bug.  (Read 1782 times)

roelbartstra

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Connecting to scene bug.
« on: April 08, 2014, 06:02:43 AM »
Hi everyone,

I'm new to network programming, so that is why I downloaded TNet. I followed both tutorials and got it all up and running.
I have the same setup as in the second tutorial. So I open the start scene, and the auto join script will connect to my game scene. However, I noticed something odd when connecting to the game scene. My script that controls the player instance in the update, can't find the player in the first frame. I debugged the code and it seems that the awake function is called after the update function. Which goes against all Unity logic. It does not happen when I directly launch the game scene, so it has something to do with how TNet connects the player to the server and how it loads in the map.

As a temporary fix I have this at the top of my update function:
if(TutorialPlayer.controlledPlayer == null) return;

But if I have to do that all over my game code everywhere it's gonna end up being a huge mess. I'm just wondering why
this would even happen, and how I can solve this issue.

djray2k

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 4
  • Posts: 74
  • Blockey Hockey!
    • View Profile
    • Walking Talking Grilling Bear Studios
Re: Connecting to scene bug.
« Reply #1 on: April 08, 2014, 11:39:59 AM »
I just added debug messages to check if it did the same. I still get Awake first and then Update.

Could you post any code that you might think is suspect? Are you doing any disabling/enabling with your player? Are you somehow making more than one by some chance?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Connecting to scene bug.
« Reply #2 on: April 09, 2014, 04:27:38 AM »
Awake called after Update()? Are you instantiating something? TNet's messages are processed in Update, and if something gets instantiated its Awake() will be called immediately. But the script's Update() function will never be called before that script's Awake(). What's the full call stack?