My objective:
- I’ve created a custom AGameState subclass. I want some of the variables to be replicated between the clients so I use the following macro on every variable I want to be replicated:
UPROPERTY(Replicated)
- Doing so requires to have a well known function to assist with the replication:
GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const;
- And Inside that function I call the parent function and use following macro:
DOREPLIFETIME(ACustomGameState, MyReplicatedVariable);
I don’t think I’m missing anything, if I am please let me know.
The problem:
Every time I run the game with a replicated variable (with the UPROPERTY(Replicated) macro and the DOREPLIFETIME(ACustomGameState, MyReplicatedVariable) macro) the game crashes.
What catched my eye in the log was this message (full log is below):
Assertion failed: bIsValid [File:PATH_TO_FILE\CustomGameState.gen.cpp] [Line: 333] UHT Generated Rep Indices do not match runtime populated Rep Indices for properties in ACustomGameState.
I’ve searched across the internet for the meaning of this message with no success in finding anything closely related to this.
I would apreciate any help.
The log:
Assertion failed: bIsValid [File:D:\Github\Warper\Intermediate\Build\Win64\UnrealEditor\Inc\Warper\WarperGameState.gen.cpp] [Line: 333] UHT Generated Rep Indices do not match runtime populated Rep Indices for properties in AWarperGameState
UnrealEditor_Warper_patch_0!AWarperGameState::ValidateGeneratedRepEnums() [D:\Github\Warper\Intermediate\Build\Win64\UnrealEditor\Inc\Warper\WarperGameState.gen.cpp:333]
UnrealEditor_CoreUObject!UClass::SetUpRuntimeReplicationData() [D:\build++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\Class.cpp:4371]
UnrealEditor_Engine!FRepLayout::InitFromClass() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\RepLayout.cpp:5941]
UnrealEditor_Engine!FRepLayout::CreateFromClass() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\RepLayout.cpp:5916]
UnrealEditor_Engine!UNetDriver::GetObjectClassRepLayout() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\NetDriver.cpp:5980]
UnrealEditor_Engine!UNetDriver::FindOrCreateRepChangedPropertyTracker() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\NetDriver.cpp:5965]
UnrealEditor_Engine!AActor::CallPreReplication() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\Actor.cpp:1454]
UnrealEditor_Engine!UNetDriver::ServerReplicateActors_BuildConsiderList() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\NetDriver.cpp:4371]
UnrealEditor_Engine!UNetDriver::ServerReplicateActors() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\NetDriver.cpp:5079]
UnrealEditor_Engine!UNetDriver::TickFlush() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\NetDriver.cpp:705]
UnrealEditor_Engine!TBaseUObjectMethodDelegateInstance<0,UNetDriver,void __cdecl(float),FDefaultDelegateUserPolicy>::ExecuteIfSafe() [D:\build++UE5\Sync\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:611]
UnrealEditor_Engine!TMulticastDelegate<void __cdecl(float),FDefaultDelegateUserPolicy>::Broadcast() [D:\build++UE5\Sync\Engine\Source\Runtime\Core\Public\Delegates\DelegateSignatureImpl.inl:967]
UnrealEditor_Engine!UWorld::Tick() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:1695]
UnrealEditor_UnrealEd!UEditorEngine::Tick() [D:\build++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:1777]
UnrealEditor_UnrealEd!UUnrealEdEngine::Tick() [D:\build++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:474]
UnrealEditor!FEngineLoop::Tick() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5215]
UnrealEditor!GuardedMain() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:183]
UnrealEditor!GuardedMainWrapper() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:147]
UnrealEditor!LaunchWindowsStartup() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:283]
UnrealEditor!WinMain() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:330]
UnrealEditor!__scrt_common_main_seh() [d:\a01_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
kernel32
ntdll
The GetLifetimeReplicatedProps Function
void AWarperGameState::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(AWarperGameState, RoundState);
DOREPLIFETIME(AWarperGameState, GameTimer);
DOREPLIFETIME(AWarperGameState, AgentsScore);
DOREPLIFETIME(AWarperGameState, WarpersScore);
DOREPLIFETIME(AWarperGameState, Agents);
DOREPLIFETIME(AWarperGameState, Warpers);
DOREPLIFETIME(AWarperGameState, Spectators);
}
Some replicated variables
UPROPERTY(Replicated)
TEnumAsByte<ERoundState> RoundState;
UPROPERTY(Replicated)
FTimerHandle GameTimer;
UPROPERTY(Replicated)
int AgentsScore;
UPROPERTY(Replicated)
int WarpersScore;
UPROPERTY(Replicated)
TArray<AWarperPlayerState*> Agents;
Constructor
AWarperGameState::AWarperGameState(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
// Comented this to see if it made a diference. It didn't...
// bReplicates = true;
// NetUpdateFrequency = 16;
// MinNetUpdateFrequency = 2;AgentsScore = 0;
WarpersScore = 0;
RoundState = MatchNotStarted;
}