#Player from Main Menu not being deleted in NetworkManager.Players when switching to game scene

8 messages · Page 1 of 1 (latest)

lament sluice
#

When I start a lobby from my main menu, the main menu player's object or reference is not getting properly deleted/removed from NetworkManager.Players.

So when I try to iterate through NetworkManager.Players, I get an error of "MissingReferenceException: The object of type 'MyNetworkPlayer' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object."

Any ideas what might be the problem and how to fix this?

peak kernel
#

can you send the script you are getting this error on through?

lament sluice
#

Sure. I think it has something to do with the null Player not being removed from Players when I switch scenes so I could make a hacky fix, but would rather get to the core issue.

peak kernel
lament sluice
#

When the scene changes, I can just run this every time and it should work fine
for each player in Players
if player == null
Players.remove Player
But I'm not sure why it isn't getting removed in the first place.

peak kernel
#

can you please send the stacktrace

lament sluice
#

Sorry I didn't get notified when you replied, but I found out it was me needing to remember to remove the previous character from the list when I overrided a NetworkManager method.