Warning: ActorItem is not initialized properly even though its struct probably has a custom default constructor

When compiling, I get a warning about the constructor.

ObjectProperty FItemInShelf::ActorItem is not initialized properly even though its struct probably has a custom default constructor.

The constructor initializes all members of the class. I absolutely do not understand the reason for the warning.
FItemInShelf::ActorItem is an AActor* it is assigned nullptr or another AActor* depending on the constructor.

Structure:

USTRUCT(BlueprintType)
struct FItemInShelf
{
	GENERATED_BODY()

public:

	FItemInShelf()
	{
		SocketsName = FName("None");
		PointLocation = FVector::ZeroVector;
		PointRotation = FRotator::ZeroRotator;
		PointTransform = FTransform::Identity;
		PointWorldTransform = FTransform::Identity;
		ActorItem = nullptr;
		Take = false;
	}

  FItemInShelf(FName InName, FVector InLoc, FRotator InRot, FTransform InTrans, FTransform InWorldTrans, AActor* InActor, bool InTake) : SocketsName(InName), PointLocation(InLoc), PointRotation(InRot), PointTransform(InTrans), PointWorldTransform(InWorldTrans), ActorItem(InActor), Take(InTake) {};
	
	FItemInShelf(FName InName, FTransform InTrans, FTransform InWorldTrans, AActor* InActor, bool InTake) : SocketsName(InName), PointTransform(InTrans), PointWorldTransform(InWorldTrans), ActorItem(InActor), Take(InTake) {};


	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shelf")
	FName SocketsName;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shelf")
	FVector PointLocation;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shelf")
	FRotator PointRotation;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shelf")
	FTransform PointTransform;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shelf")
	FTransform PointWorldTransform;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shelf")
	//TWeakObjectPtr<AActor> ActorItem;
	AActor* ActorItem;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shelf")
	bool Take;

	FString ToString() const;

};

Any Idea ? It may not be possible to initialize AActor* = nullptr if UPROPERTY is used?

1 Like

In third constructor you forget initialize PointLocation and PointRotation.
In that situations using delegating constructor is useful:

// "base" constructor, initializes everything
FItemInShelf(FName InName, FVector InLoc, FRotator InRot, FTransform InTrans, FTransform InWorldTrans, AActor* InActor, bool InTake)
	: SocketsName( InName ),
	  PointLocation( InLoc ),
	  PointRotation( InRot ),
	  PointTransform( InTrans ),
	  PointWorldTransform( InWorldTrans ),
	  ActorItem( InActor ),
	  Take( InTake )
{};

// half-init (rest initialized by defaults)
FItemInShelf(FName InName, FTransform InTrans, FTransform InWorldTrans, AActor* InActor, bool InTake) :
	FItemInShelf( InName, FVector::ZeroVector, FRotator::ZeroRotator, InTrans, InWorldTrans, InActor, InTake )
{}

// default constructor
FItemInShelf() :
	FItemInShelf(FName("None"), FVector::ZeroVector, FRotator::ZeroRotator, FTransform::Identity, FTransform::Identity, nullptr, false)
{}
2 Likes

Thanks, I’ll try it, but I also got a bug. After deleting the structure, the compiler continued to output a warning.