Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

How to network C++ variables in Unreal; UPROPERTY Replication (Normal& Push) - UE C++ Tutorial

How to network C++ variables in Unreal; UPROPERTY Replication (Normal& Push) - UE C++ Tutorial

enigma_dev
enigma_dev
Informal Unreal C++ Video Tutorial Series · · 1 min read
3,787 0

How to set up replicated variables in C++ (ie UPROPERTY replication). Both the old and easy way. And the new fast push replication model.

Part of the UPROPERTY Basics mini series within my larger unreal engine tutorial series.

While the legacy method of replication still seems to be a valid way of replicating (based on lyra project),
the new "push" replication is used in much of the base engine, like scene nodes components (USceneComponent).
Here I go over how to do both types of replication.

First setting up proper UPROEPRTY keywords.
Then listing it as being replicated in GetLifetimeReplicatedProps
After that we use OnRep variables to get callbacks for when a variable replicates to the client.
Lastly, we debug the entire set up with breakpoints to see it all working together.



0:00 GetLifetimeReplicatedProps virtual override
0:37 Replicated UPROPERTY keyword (old way)
0:57 DOREPLIFETIME (old way)
1:35 ReplicatedUsing UPROPERTY with OnRep UFUNCTION
2:49 Setting variables on server will replicate them to client
3:14 New Replication (Push Model)
3:52 FDoReplifetimeParams & DOREPLIFETIME_WITH_PARAMS_FAST
4:50 Marking Dirty; MARK_PROPERTY_DIRTY_FROM_NAME
5:45 Resovling Compile Errors
6:07 Linker error: UEPushModelPrivate::MarkPropertyDirty
6:13 Including the NetCore module to resolve linker error
7:02 Fast push replication summary
7:49 Testing push replication - code changes
7:52 Set actor to replicate in the constructor
8:06 BeginPlay - Set timer to update variable on server
9:04 Setting the variables on the server
9:40 INCOMPLETE Making a new OnRep (hooked up later 10-50)
9:48 OnRep logic - screen print the vars
10:05 Fixing compile errors
10:30 Dropping breakpoints
10:48 Fixing blueprint replication bool set to false
10:50 Fixing OnRep not hooked up
11:15 Debugging Begin Player Timer Start
11:20 GPlayInEditorContextString showing server
11:51 Timer over, set replicated variables
12:25 Hit breakpoint for old method OnRep
12:40 Hit breakpoint for new method OnRep
12:55 Outro Remarks

Discussion

Loading comments...