GUI Error: Invalid GUILayout state in GameView view. Verify that all layout Begin/End calls Match

My player has the UI attached to it and it functioned fine until I added the network manager script from Netcode For GameObjects. When I press the host button to load the player prefab and network the error persists and no player or camera is loaded.

If I add the player to the scene and then use the GameView to test, and it all works fine. The error only persists when I begin the network, so I assume it is to do with me not including some Netcode script to handle the UI in the network.

I am very new to this so apologies if this is a very simple solution, none of the solutions I have already found have helped so anything will be greatly appreciated thanks.

Edit: For some reason removing a function that wasn’t related to the GUI fixed my issue. I still have no idea why it was broken but everything works now

I forgot to mention that the code was copied from the learn Netcode site:

        void OnGUI()
        {
            GUILayout.BeginArea(new Rect(10, 10, 300, 300));
            
            if (!NetworkManager.Singleton.IsClient && !NetworkManager.Singleton.IsServer)
            {
                StartButtons();
            }
            else
            {
                PlayerControl();
            }

            GUILayout.EndArea();
        }

2 Answers

2

Nope, that’s a bad assumption without much basis. This error happens when you have some Begin method without calling the corresponding End method. This can be caused either by writing wrong code so you actually created code that intentionally or unintentionally may skip an End call or add an additional Begin call which causes this error, or the other common issue is that you have some other error in your code, (maybe in a try catch) and as the result of that error you don’t reach the End call.

This may even happen inside the manager script due to some misconfiguration which causes this error. We can’t really help you here without seeing the code and knowing the exact error message which usually contains a detailed stacktrace and line numbers.

Do we have a solution for that? I really need to run the game but it is not working