arnaud-jamin / Cog

Cog is a set of debug tools for Unreal Engine built on top of Dear ImGui
MIT License
357 stars 44 forks source link

Multiplayer not supported #27

Open Vaei opened 10 months ago

Vaei commented 10 months ago

I added Cog to the gamestate as per the example project and setup readme.

This means that BeginPlay, Tick, EndPlay are called for the server and every client. Of course, if I move it to GameMode, then it will only run on server and clients won't get any UI, so that won't help.

There seems to be a lack of consideration for the static properties that ImGui uses.

Soon as there is a server and a client (vs. standalone), it will crash on EndPlay because calling CogWindowManager->Shutdown(); shuts down the Context, causing ImGuiIO& IO = ImGui::GetIO(); to return nullptr, but it is not null checked (rather, it has an assert, which it fails, and then promptly crashes).

Furthermore, BeginPlay spams warnings because it is repeating logic:

Warning      LogConsoleManager         Console object named 'Cog.ToggleSelectionMode' already exists but is being registered again, but we weren't expected it to be! (FConsoleManager::AddConsoleObject)
Warning      LogConsoleManager         Console object named 'Cog.ToggleInput' already exists but is being registered again, but we weren't expected it to be! (FConsoleManager::AddConsoleObject)
Warning      LogConsoleManager         Console object named 'Cog.ResetLayout' already exists but is being registered again, but we weren't expected it to be! (FConsoleManager::AddConsoleObject)
Warning      LogConsoleManager         Console object named 'Cog.LoadLayout' already exists but is being registered again, but we weren't expected it to be! (FConsoleManager::AddConsoleObject)
Warning      LogConsoleManager         Console object named 'Cog.SaveLayout' already exists but is being registered again, but we weren't expected it to be! (FConsoleManager::AddConsoleObject)

Even if I test if ImGui has already initialized, to ensure it only runs once, then it'll run on the server and not the clients so they don't get windows.

For cog to support multiplayer (literally at all) it needs to respect that ImGui uses statics and separate out of the behaviour between Cog and ImGui so that you can initialize or clean up without making repeated calls to statics (especially when they are getting nulled).

This isn't sufficient on it's own, because we need to know when all clients have finished cleaning up, and then shutdown ImGui.

arnaud-jamin commented 10 months ago

Hello,

I will have a look. The reason I don't get this error on my side is because I do not use the unreal option "Run Under One Process".

If you uncheck this, Unreal spawn a process for the server and the client. This is more reliable since it is closer to what the players will experience.

Vaei commented 10 months ago

I'm aware of the option but for rapid iteration and testing, it takes a lot longer to spin up so not a good option all of the time.

arnaud-jamin commented 10 months ago

Sure, that's why I'll have a look to fix it.

Moniz commented 1 week ago

I've got a fork that supports this now, if that's of interest https://github.com/Moniz/Cog Gamepad support is off for the moment though as I refactored how input is handled quite a bit