GetLifetimeReplicatedProps in comment causes compile error

If I add

// GetLifetimeReplicatedProps

to header file of any class that implements this function in .cpp file I get compilation error. It looks like override for GetLifetimeReplicatedProps doesn’t get declared in GENERATED_BODY.

Hey -

Using a function in the source file who’s declaration is commented out in the header file will cause compile errors since the compiler doesn’t know where the declaration of the function is. Additionally, after looking at the function declaration inside Actor.h, that function is not declared virtual so it cannot be overridden in the child class. If you are using a source built version of the engine then this can be edited in the source code, otherwise you will only be able to call the function from your class without changing its functionality.

Cheers

I don’t think that I’ve written original question precisely enough so I’ll post some example code.

TestActor.h

#pragma once

#include "GameFramework/Actor.h"
#include "TestActor.generated.h"

UCLASS()
class TESTPROJECT_API ATestActor : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ATestActor();

	// Something Something GetLifetimeReplicatedProps, this is not a commented out function declaration
	// The above comment stops file from compiling, if the "GetLifetimeReplicatedProps" string is removed (or broken with space/underscore etc.)from this and the above comment the file can now compile

	UPROPERTY(Replicated)
	int32 MyReplicatedInt;
};

TestActor.cpp

#include "TestProject.h"
#include "TestActor.h"
#include "UnrealNetwork.h"

// Sets default values
ATestActor::ATestActor()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	SetReplicates(true);
	bAlwaysRelevant = true;
}

// Implementation of replication function, since i want to have more control over what's getting replicated to who
void ATestActor::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
	DOREPLIFETIME(ATestActor, MyReplicatedInt);
}

The issue is not with the commenting out function declaration.

Hey -

Adding //GetLifetimeReplicatedProps to the .h file does not change the outcome of the compile for me. What is the exact error you get when the compile fails?

‘GetLifetimeReplicatedProps’ : member function not declared in ‘ATestActor’

Error does disappear 100% of the time when a space is added somewhere in GetLifetimeReplicatedProps in comment. I’m using VS Express 2013 with binary 4.8.3 engine version.

That specific error is because the compile see the function in your .cpp file but doesn’t know what to do with it since it was not declared in the source file. Adding the function declaration should solve the error

I know, it’s just that without “GetLifetimeReplicatedProps” somewhere in the comment in the .h file the declaration is done automatically, probably in GENERATED_BODY() macro. The problem is that comment changes compile outcome.

I know that this thread is pretty old, but OP is absolutely correct. If you have the function “GetLifetimeReplicatedProps” in your header file as a comment, such as //GetLifetimeReplicatedProps, you will be given the error 'GetLifetimeReplicatedProps' : member function not declared in 'AClass'. Most likely a bug.

1 Like

Feels great being validated after 3 years

1 Like

This bug still exists on Engine 4.21.2… just verified

Bug still here in 4.27.2

1 Like