How to store local variables?

I’m making a turn based battle system and now I try to implement a creature queue, which should determine the order of activation of the creatures. I created a simple raw C++ struct which looks something like this:

struct FQueueRecord
{
     ACreature* Creature;
     int32 PointsToNextTurn;
};

The question is how should I store the records inside a member TArray variable? Should the struct be a USTRUCT and ACreature* a UPROPERTY?

A FQueueRecord instance is created loaclly inside a method. After adding a new record, the queue is sorted based on the PointsToNextTurn variable. Would the use of a smart pointer be a good option? If so, which type should be used: std::unique_ptr, TUniquePtr or even TUniqueObj? Or is there any better solution?

(I considered a TMap for this, but it should be possible to add the creature more than once.)

Yes if you using UObjects you need USTRUCT and UPROPERTY in it and TArray need to be UPROPERTY too, so engine see those varbales and can automatically null invalid pointers of destroyed actors (ofcorse oyu will need to do struct cleaning in your case). Other then that it’s needed to other thing, it’s not dangerous with actors but if you got pure UObject you need to have them referenced in the way engine see them or else they be trashed.

I don’t know what you mean by local varbales as the way you describe sound not like local variables (mean varbales in scope of function). If you indeed use local variable the all those doesn’t matter as in scope of function engine won’t able to delete those objects, even if you do that with destroy function they be just marked as pending kill and deleted after current frame, so in this case this is all optional.

All you need to know is that without all those U macros engine don’t see those variables, and most impotently GC don’t see it.

By local variables I mean something like this:

Header:

USTRUCT()
struct FQueueRecord
{
    GENERATED_USTRUCT_BODY()
    
    UPROPERTY()
    ACreature* Creature;
    
    int32 PointsToNextTurn;
};

UCLASS()
class UCreatureQueueComponent : public UActorComponent
{
    GENERATED_BODY()

public:
    void AddCreature(ACreature* Creature);
 
private:
    UPROPERTY()
    TArray<FQueueEntry> Queue;
};

Source:

void UCreatureQueueComponent::AddCreature(ACreature* Creature)
{
	FQueueRecord Record;
	Record.Creature = Creature;
	Record.PointsToNextTurn = Creature->GetDefaultPointsToNextTurn();

    // Should Record be here converted to some sort of a smart pointer
    // or is it ok to store it by value?
    // What if the Record variable was bigger?

	Queue.Add(Record);

    // ...
}

What exactly do you mean by “struct cleaning”?

By the way, should every UObject* (including AActor*) be marked as a UPROPERTY even inside a UCLASS?

I’ll just answer your last question: Yes, all properties that are instances of UObject-derived classes must be decorated with UPROPERTY() otherwise they will be automatically garbage-collected by the engine and your game will crash when you try to reference them.