x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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

GameInstanceVariable

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

level 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.

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.

Product Version: Not Selected
Tags:
variable.png (23.7 kB)
level_blueprint.png (200.7 kB)
more ▼

asked Apr 06 '15 at 01:35 PM in Blueprint Scripting

avatar image

amcofi
525 9 83 49

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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!

more ▼

answered Apr 07 '15 at 04:17 PM

avatar image amcofi Apr 07 '15 at 05:43 PM

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

avatar image Ben Halliday STAFF Apr 09 '15 at 04:41 PM

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.

avatar image amcofi Apr 10 '15 at 06:02 AM

Thank you very much!

avatar image Ben Halliday STAFF Apr 17 '15 at 05:23 PM

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!

avatar image amcofi Apr 18 '15 at 03:52 PM

Thanks Ben, this helps a lot!

avatar image Davision Sep 26 '15 at 12:53 PM

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.

avatar image DanzigLucifuge Apr 25 '17 at 04:23 AM

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

avatar image acxsasx Jun 06 '17 at 10:14 PM

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: https://forums.unrealengine.com/showthread.php?53208-MMO-Starter-Kit https://wiki.unrealengine.com/Survival_sample_game His PDF is a MUST read. http://cedric-neukirchen.net/

edit: Found this: https://answers.unrealengine.com/questions/286918/how-can-a-client-send-a-variable-from-his-game-ins.html

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question