BeardedManStudios / ForgeNetworkingRemastered

See various forks, also please join the Forge Community fork of Forge Alloy! -> https://github.com/ForgeAlloyCommunity/ForgeAlloy
https://twitter.com/FarrisFaulds
Apache License 2.0
1.49k stars 311 forks source link

Windows Stand Alone Player returns null reference when you instantiate in Scene 0 #370

Open Gwom opened 4 years ago

Gwom commented 4 years ago

Version Number and Operating System(s):

03/10/2018-19.53.38,04 Windows, Unity Editor 2019.2.21f1

Expected behavior:

The Editor and Windows Stand Alone version behave the same, regardless of what i am doing, and it doesn't return null when making a network object

Actual behavior:

The Windows player behaves differently than the editor, when i instantiate the chat object it returns null but the editor works

Steps to reproduce:

(not tried these actual steps but have reproduced similar) Add the multiplayer scene into a build, turn off automatically change scenes, make it spawn the chat window/network object on a key press. Build for Windows (debug), log in as host and press that key to spawn the chat object all in one scene, note you get a null reference as the whole GameObject[] is null which should hold your Chat prefab - i believe the whole thing is null, not just it has no entries but could not attach the debugger to my windows build to confirm. Also note, if you do this in the editor in Unity, it is not null.

If you make a scene 0 that doesn't really do anything but go to scene 1 (where you have the multiplayer scene we used before and the Chat on Keypress), then make a windows build the same thing will actually work. I am not sure if you need the forge manager script in scene 0 and have it not destroy on scene change and this is doing something, or just the fact this is all done (the instantiating) in a scene with index != 0 will work regardless. I do know you don't need to become host in scene 0, before spawning chat in scene 1, you can do both these things in scene 1 and it will still work.

[Optional] Discord Username:

Gwom

phalasz commented 4 years ago

I'm not sure I follow what you are describing here. Would you be able to provide a minimal project where I can see what you are trying to describe above.

Also proven reproduce steps would be much appreciated.

Gwom commented 4 years ago

@phalasz unfortunately if make a project using basic steps it seems to not be reproducible so it must be some kind of conflict with my setup and slicing it out of the project would take quite a while. I quickly tried the following and the issue does not happen on Windows Player:

  1. Make a project with the multiplayer scene
  2. Turn off Automatic Scene on the NetworkManager prefab
  3. Turn on DontChangeSceneOnConnect on the MutiplayerManager component
  4. Add to the MultiplayerManager.cs at ln 168 else if (Input.GetKeyDown(KeyCode.Q)) NetworkManager.Instance.InstantiateChatManager();
  5. Make a Windows build, run, connect as client and press Q

It is very difficult to see what I am doing that is different to this, and due to another issue I cannot attach my debugger to the windows player. As such, it is difficult to know why I am getting a null reference for the Instantiate but only on the Windows version, not on the Editor. If i can get more details or a more concrete example that would be good but for now, I am unsure how to provide more info (sorry). If you can think of anything that may affect Windows only, to do with scenes that would be good to know.

phalasz commented 4 years ago

I personally haven't see an issue like this and without concrete steps that always reproduce the problem I will not be able to help.