Author Topic: Trying to execute a funtion on TNObject before it has been created  (Read 2815 times)

Malgo

  • Guest
Im gettin a weird error since I started using meta files to place my current project on SVN.

Everytime I load a scene it seems that every TNObject somehow gets reset and loses whatever connection it had to the manager. I get the following error when launching the scene:

Trying to execute a function 'NetChangeState' on TNObject #10103 before it has been created.

When I replace every TNObject in the scene the problem is solved but reapears every time I quit or reload the scene. It wouldnt be so much of a bother since Ive scripted the changing of TNObjects but building the game generates the same error.

Any hints as to where I should look for an error?

Cheers

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Trying to execute a funtion on TNObject before it has been created
« Reply #1 on: May 21, 2013, 01:23:06 PM »
That's a rather strange object ID. Do you really have over 10,000 TNObject scripts present in your scene? As a rule of thumb, if you have more than a few of them per scene, you're likely doing something very wrong. How are they created? Do you have something creating them at edit time?

Make sure to delete server.dat file if you have it. If you created a channel with a persistent flag set, all your previous RFC calls are still going to be present, which is a problem if you changed TNObject IDs.

Malgo

  • Guest
Re: Trying to execute a funtion on TNObject before it has been created
« Reply #2 on: May 22, 2013, 04:25:33 AM »
Thanks for the answer.

I actually only have about 10 TNObjects in the scene and since the game is turn-based I dont create any during runtime. The high ID is due to the fact that I have to remove and readd all TNObject components when I load the scene. The IDs just keep counting up...

I don't have any server.dat and I havent created any channel yet. I ususally deal with the game logic before creating any kind of menu or management so the only part of your framework I'm using is TNObject. It's weird because everything worked before I started using the meta files.

Malgo

  • Guest
Re: Trying to execute a funtion on TNObject before it has been created
« Reply #3 on: May 22, 2013, 04:51:09 AM »
OK I found the problem. The thing is that Im making my first call to the network in the Start function of my main logic script. Since TNOs register themselves to the dictionary used to find them during the start function this cause a concurrency problem.

In order to fix the problem quickly I moved the Register() function call in the TNObject to the awake function. Is there a reason why you didn't do that in the first place? In that case I would adapt the logic script accordingly.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Trying to execute a funtion on TNObject before it has been created
« Reply #4 on: May 22, 2013, 09:01:18 AM »
Because when TNObjects are instantiated, Awake would be called before the UID is set, which would result in it being mis-categorized. It must be in Start.

I suggest you simply modify your logic. It shouldn't be in Start. It should be in OnNetworkJoinChannel().

Malgo

  • Guest
Re: Trying to execute a funtion on TNObject before it has been created
« Reply #5 on: May 22, 2013, 09:29:54 AM »
Allright then. Thanks for the help!