Download

GameInstance doesn't support Switch has Authority?

I’m trying to switch on authority in a game instance function, but the Switch Has Authority node is not available.
The documentation for GameInstance says that game instances are created once per client, so it’s not server-only: UGameInstance | Unreal Engine Documentation
The “crash course in networking” says that I should turn on replication for a blueprint in the “Replication” defaults panel. However, this gameinstance blueprint does not have such a panel: A Crash Course in Blueprint Replication - Unreal Engine

I’m using a RepNotify variable, and in the OnRep_ function, I want to load a new level if the variable changes, only if I have authority.
How can I do this?

The GameInstance class only exists for clients, therefore you cannot distinguish code paths into Authority or Remote. GameInstance does not replicate.

Try doing your level changing within the GameMode class.

The GameInstance also exists for the Server, but this is his own. The part with the replication is correct.

Plus, the GameMode only exists on the Server! Keep that in mind.

Are you sure GameInstance does not replicate? I am using it to store variables between all players, and it seems to work.

Totally sure. The GameInstance is unique for each player. It is created when you Start the Game and it is not destroyed until you close the Game.
So it is the only class (at normal settings) that survives level changes. If you debug the GameInstanceBlueprint and selected single clients, you will only
see one single GameInstance per client/server.

Yes, that’s what I would expect.
However, why wouldn’t it replicate?
I can mark properties on Gameinstance as replicated.

Trying to do the level switch in GameMode doesn’t work that well because I need to preserve state, and I need to drive it from the server.

Also, I must be not getting something about the GameInstance.
The “event init” that is a default event, doesn’t get called. (I have a print and a breakpoint; never gets set)
When I call a custom event from the level blueprint, and the custom event tries to create a User Widget with a couple of buttons, and add that to the viewport, the viewport doesn’t actually show the buttons.

You need to set your custom GameInstance in the “Maps and Nodes” Project Settings, the same place where you set the GameMode etc.
At the bottom there is dropdown Menu to select the GameInstance class that should be used.

If the INIT is not called, i guess you just forgot to do what i wrote above :stuck_out_tongue:

I believe I have set the class correctly. Also, I don’t think that’s the problem, because in the level blueprint, I can cast the game instance to my game instance subclass, and call an event directly.
My work-around was to do just that.
However, when doing that, the UI that was created was still not attached to the viewport.
I’m wondering if this happens too early in the setup of the game or something.

I’m git cloning the code now so that I can answer these questions with authority.
It’s amazing how little is actually answered in the reference manual. Try looking up “GameInstance” and then see if it’s replicated or not. (Not documented on that page)
Try looking up “GameMode” and see when an instance will be created an destroyed. (Not doumented there)
Try looking up the difference between “Open Level” and “Server Travel” (the latter doens’t even have a Blueprint Node)
The documentation seems to document the ******** that I can already deduce from the names of things, and none of the important bits like “when is this constructed, who owns it, how does it fit into the bigger scheme of things.”

1 Like