[Question] Constructor vs BeginPlay

bUseOutLine is set to false by default in the parrent class

Constructor

AInteractableItem::AInteractableItem()
{
	if (Role == ROLE_Authority)
	{
		bUseOutline = true;
	}
}

BeginPlay

void AInteractableItem::BeginPlay()
{
	Super::BeginPlay();

	UE_LOG(LogTemp, Warning, TEXT("%s : bUseOutLine = %s"),*GetName(), bUseOutLine ? TEXT("true") : TEXT("false"));
}

The output log is telling me that the boolean is set to false, But when I put the if statement inside the BeginPlay function, The output log is telling its set to true.

Why is this hapening, Is this a bug or cant I use a if statement inside a constructor?

I appreciate some advice about this behavior

Role isn’t set to ROLE_Authority until InitializeDefaults, so in the constructor Role equals ROLE_None.

Ah that explains alot, So how could I check inside the constructor if its a server version of the actor, Or should I just let the BeginPlay function handle that?

You’ll have to do it outside the constructor. BeginPlay is a safe place to check that kind of thing.

So that means I cant set a replicated variable inside a constructor?

You could, but if its going to be replicated you’re better off setting the default value across the server and clients in the constructor without checking the role. There’s no reason to replicate the default value, only if it changes after construction.

This is very confusing, In the parrent class constructor I set the boolean to false, Using the ROLE_AUTHORITY check. And in the child class constructor I also set it to false using the ROLE_AUTHORITY check, Then I build and press play. The output log is telling its set to false. But when I restart the editor and press play the output log is telling its set to true

But you are saying it shouldnt work inside a constructor, But it looks like it does only when restarting the editor.

Can’t speak for the results you’re getting from restarting the editor. I wouldn’t rely on that.