Author Topic: TNManager.LoadLevel Causes all Start() to run twice while networked  (Read 2936 times)

Eyeshock

  • Guest
I don't even know where to begin on this one; I thought I had the gameplay side worked out, but this it's suddenly become a disaster.

The major problem obviously is the Start() is running twice on all elements in the loaded scene when there is more than one player in the channel. Even when my game is running Single Player, it is still 'networking', as in the game plays as a multiplayer game even with only one player to allow players to join freely.

This problem only began today. I instantiated a prefab in a previous scene to manage my custom lobby. The prefab had a network ID of 0 to allow instantiation, as do all the other prefabs. When loading the next scene, the first prefab instantiated always seems to favor 16777214, and the same was true in the previous scene. So then I got a 'use unique identifiers' error; it still instantied the new prefab (with a 26...), but complained about it anyway.

So I tried taking away the DontDestroyOnLoad(), and obviously it fixed it. So basically, it's trying to spawn every first prefab with the number 16777214 whether one exists already or not. It just seems to be that number too. Perhaps it's always 16777214 the first prefab in a scene?

The real nightmare began when I tried to network locally; up until this point, it was working fine. Suddenly, I have 2 copies of all objects because the Start() functions for EVERY object in the scene that is present on loadup is running twice. These are not networked objects, they are just basic stuff like Audio Listeners/Jukebox scripts for background music and a script that spawns the player.

I'm not entirely sure where to even begin sorting out this problem. I would simply reverse everything I have done, but that's a lot of work (that I suspect I'll need to do anyway to debug the problem).

I'm hoping perhaps this problem has come up before?

Eyeshock

  • Guest
Re: TNManager.LoadLevel Causes all Start() to run twice while networked
« Reply #1 on: July 24, 2013, 04:45:45 AM »
I was able to track down the Start() function problem, it turns out you can run TNManager.LoadLevel twice simultaneously via a network call, and that causes all of the Start/Awake/OnEnable functions in the loaded scene to run twice; which is scary because it seems like it would just load the scene, then reload the scene! Either way, it wasn't desirable so making sure LoadLevel exists outside of RFCs fixed it.

I still can't figure out why TNObject loves 16777214 so much, nor why it will try to spawn the first prefab in a scene with that number whether that ID is in use already or not, even if the prefabs are all in the TNManager's object list.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNManager.LoadLevel Causes all Start() to run twice while networked
« Reply #2 on: July 24, 2013, 02:05:09 PM »
All objects that get created dynamically inside your scene get destroyed as soon as you load another scene. If you want an object to stay, you can't create it dynamically. It must have a static ID instead.