Description

In some situations, it can be useful to have a replicated editor-only C++ property (For example, the user that reported this issue was attempting to replicate settings to the client for game designers in ImGui). Since such a property is wrapped in C++ with "#if WITH_EDITORONLY_DATA", it should work with replication on the Editor, while having no effect on the packaged game.

If such a property is present in the code while packaging a dedicated server, its definition and usage will be correctly stripped from the compilation, but some replication code will still be generated for it. This causes the dedicated server to crash when it attempts to replicate the actor that ultimately contains the property.

The problem was tracked down to the auto-generated C++ function ValidateGeneratedRepEnums(). It is generated by the UHT function AppendNativeGeneratedInitCode() in file [Engine\Source\Programs\Shared\EpicGames.UHT\Exporters\CodeGen\UhtHeaderCodeGeneratorCppFile.cs], in the code that precedes the error message "UHT Generated Rep Indices do not match runtime populated Rep Indices for properties in ". The generator adds "#if WITH_EDITORONLY_DATA" to several places where this kind of property is mentioned, but has no special treatment at this point.

Steps to Reproduce

Note: This repro needs a source build of UE to allow packaging a dedicated server.

1. Compile the repro project
1.1. The project contains a C++ "AMyActor" class containing some replicated and non-replicated uproperties
1.2. Property "MyReplicatedIntB" is tagged "Replicated" and also wrapped in "#if WITH_EDITORONLY_DATA"
1.3. All usages of "MyReplicatedIntB" are wrapped in "#if WITH_EDITOR"

2. Open the repro project
2.1. The startup map contains a replicated actor "BP_MyActor"
2.2. This actor increments some integer variables at 1-second intervals and prints them to the log and screen

3. Set Net Mode "Play as Client" and PIE with 2-3 players
3.1. Variable "MyInt" is not replicated and can be seen being incremented only on the server
3.2. Variables "MyReplicatedInt

{A|B|C}

" are replicated and can be seen being incremented on the server and clients

4. Package the project:
4.1. "Windows" platform, "Development" configuration, "TestReplicationServer" target
4.2. "Windows" platform, "Development" configuration, "TestReplicationClient" target

5. Test the packaged project:
5.1. Run the server executable with "-log" on the commandline
5.2. Run the client executable with "127.0.0.1:7777 -log" on the commandline
5.3. Once the client connects, the server will crash in [MyActor.gen.cpp]
5.4. Crash message: "UHT Generated Rep Indices do not match runtime populated Rep Indices for properties in AMyActor"

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-231448 in the post.

0
Login to Vote

Unresolved
ComponentUE - Foundation - Cpp Tools - UnrealHeaderTool
Affects Versions5.45.35.65.5
Target Fix5.6
CreatedNov 26, 2024
UpdatedDec 3, 2024
View Jira Issue