How to apply a default value

Hi everyone, I need help with a simple question about UE5. I have a property in a C++ script that indicates which enemy my player will focus on when the game starts (I have this flow just for study). My question is: how can I guarantee that when my player starts the game, this property has the default value EnemyCpp_BP? I have tried many ways to set this default value, but so far I have not been able to do so.

In my C++ class, this property is defined like this:

UPROPERTY(BlueprintReadWrite, EditAnywhere)
AEnemy* FocusedEnemy;|

You need to get the first Enemy in the current level (GetAllActorsOfClass > Get(0)) and set the value explicit… maybe in BeginPlay.

1 Like

Thanks @BDC_Patrick, I used it exactly as you suggested and it worked perfectly :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.