Variables on the GameInstance are not replicated

Hei,

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

  • Next I add a variable with the exact same configuration, named LevelVariable, to the level blueprint
  • Finally I configure the level Event Graph as follows:

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.

From the video Unreal Engine 4 Twitch Broadcast - Networking Framework, Tips & Tricks - Live from Epic HQ and the replication-logo in the blueprint I understood it should be possible to replicate also variables on the GameInstance.

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.

Hi amcofi,

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.

Hope that helps!

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 :slight_smile:

Sorry, yes, I was wrong about that; the GameInstance lives on both Server and Client, but it isn’t replicated.

I’m looking into ways you might be able to transfer PlayerState information between levels, and I’ll let you know what I find.

Thank you very much!

Hi amcofi,

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.

Hope that helps!

Thanks Ben, this helps a lot!

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

Network games are complicated. Learning UE4’s implementation takes effort. I think I got a basic handle on it using C++ and some blueprints after many hours.

IMHO, using C++ for a networked, dedicated server is a requirement to have all the tools you need to address what you want to do.

GameMode object live ONLY on the server, never a client.

I have used these resources:

His PDF is a MUST read. http://cedric-neukirchen.net/

edit:
Found this:

Also, you could do a custom event off the GameInstance, make is server only (RPC) pass it the information you want. This is what I am going to work on here in a few minutes.