Why are all the Menu Widgets handled in GameInstance?

I have recently finished your multiplayer course (loved it, has given me a good grounding), and am now working on my own project. One question I have is why are you handling all Menu Widget creation and operation in the GameInstance? It works fine, and works for all players connected. But it seems like it should be attached to the PlayerController or something only client side.

Just before I attempt my own refactor to try this out for myself, do you have any gems of wisdom, about whether I should or should not do this? Is GameInstance truly the right place for UI?

Thanks!

I think it’s about the callback from the OSS. They are easier to handle in GameInstance. So I think you might be able to move some but not all logic out.

The GameInstance can also help you persist things between worlds which can be helpful.

Great to hear you enjoyed the course and are taking it further.

Thank you! I actually did end up moving it; all the menu related stuff is now on the PlayerController but the session related stuff has stayed on GameInstance. It does mean a bit more code overall because both classes now share some similar function names and PlayerController keeps calling GameInstance, but each class is now a bit more concise. So I don’t know if it’s now better or worse, but hey, learning through refactoring!

You’re right, I did have to make a callback delegate for when the session search results is updated. I’m not sure if that’s a bit sloppy, but at least I avoided a circular dependency…

1 Like

No, sounds good. I think I didn’t want the extra complexity in the lectures but sounds like a good approach.

Privacy & Terms