It seems variables on the GameInstance are not replicated. This even if they are set up exactly the same as a variable in the level blueprint, where it does work. I used the following steps to reproduce this:
Create a new project based on the ThirdPerson template
Create a new blueprint derived from GameInstance and configured that in Project Settings
Add the following variable to the GameInstance blueprint
When I run this with two players and press, in the server game, Z and C both clients display the correct value for LevelVariable when I press V. However, when I press X, I only get the correct value at the server and not at the client.
Also, when I make a C++ project with a replicated variable, it requires me to implement GetLifetimeReplicatedProps. However, it seems this method is never invoked. I am using 4.7.4-2497108+++depot+UE4-Releases+4.7 on Windows.
The GameInstance is itself not replicated, and exists only on the Server, so its variables won’t be replicated either. Your best place for something you’d want replicated from the GameInstance would be the GameState, which is replicated.
I’m sorry, I am a bit confused about “The GameInstance is itself not replicated, and exists only on the Server”. For me the clients do also have a GameInstance, however, they do not have a GameMode. Maybe I misunderstood your intention or maybe you actually only meant to say the GameInstance does not replicate?
Either way, from what I understood, the GameInstance is the only object that persists between levels. Therefore, if I want e.g. character selection to persist from one level (the menu) to another (gameplay), this must be stored on the GameInstance. This means I copy my replicated variables from e.g. PlayerState to the GameInstance, before I load the next level. Then after loading the level, the variables are copied from the GameInstance back to the PlayerState so they can be replicated again. Is this the correct way to have replicated variables persist between levels?
I am completely new to Unreal Engine, so maybe I am making things more complex than they need to be
I’ve looked into it and spoken with the networking developers, and it sounds like there isn’t a clean way to do this in a content-only (no code) project. This is a feature that will require more engine work to support, and I’ll be entering a feature request to expose more functionality to Blueprints.
For a code project, you can copy Player State to Player State through CopyProperties during seamless travel.
A hacky way to do it in a content-only project that might work is to have the server (only the server) save data to the GameInstance, then have the server copy it back out to replicated variables in the Player States post-travel.
Is there any update on the feature request? Having to first put all variables in GameInstance and then from there copy it to all the player states with a event at post is quite annoying, especially when you have lots of variables. Would be great if there would be something that travels with a level change and is also replicated. Furthermore you can’t do that event inside the gameinstance.
Here here. I’m finding it impossible to set up a network game using only blueprints. I know it’s partly my own incompetence but I’m frustrated I set variables to replicate from the game mode and they just don’t replicate down to clients and I still don’t know why. I keep hearing about the difference between game state and game mode and I just don’t understand any of this. All I want is to share some variables and change them and for them to be the same everywhere I don’t get why its so hard