Variables on GameInstance are not replicated

Hei,

It seems variables on GameInstance are not replicated. This even if they are set up exactly same as a variable in level blueprint, where it does work. I used following steps to reproduce this:

  • Create a new project based on ThirdPerson template
  • Create a new blueprint derived from GameInstance and configured that in Project Settings
  • Add following variable to GameInstance blueprint

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

When I run this with two players and press, in server game, Z and C both clients display correct value for LevelVariable when I press V. However, when I press X, I only get correct value at server and not at client.

From video Unreal Engine 4 Twitch Broadcast - Networking Framework, Tips & Tricks - Live from Epic HQ and replication-logo in blueprint I understood it should be possible to replicate also variables on 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,

GameInstance is itself not replicated, and exists only on Server, so its variables won’t be replicated either. Your best place for something you’d want replicated from GameInstance would be GameState, which is replicated.

Hope that helps!

I’m sorry, I am a bit confused about " GameInstance is itself not replicated, and exists only on Server". For me 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 GameInstance does not replicate?

Either way, from what I understood, GameInstance is only object that persists between levels. Therefore, if I want e.g. character selection to persist from one level ( menu) to another (gameplay), this must be stored on GameInstance. This means I copy my replicated variables from e.g. PlayerState to GameInstance, before I load next level. Then after loading level, variables are copied from GameInstance back to PlayerState so they can be replicated again. Is this 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; 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 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 server (only server) save data to GameInstance, then have server copy it back out to replicated variables in Player States post-travel.

Hope that helps!

Thanks , this helps a lot!

Is there any update on feature request? Having to first put all variables in GameInstance and then from there copy it to all 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 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 game mode and they just don’t replicate down to clients and I still don’t know why. I keep hearing about 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 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 tools you need to address what you want to do.

GameMode object live ONLY on 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 GameInstance, make is server only (RPC) pass it information you want. This is what I am going to work on here in a few minutes.