My TArray of one structure works when declared inside a function, but not when declared on header file

Did a test project and it works ok

.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "ProgressEvent.h"
#include "APj_013_VerticalCppGameModeBase.generated.h"


USTRUCT(BlueprintType)
struct FStr_ProgressEvent {
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	AProgressEvent* EventRef;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	float XLoc;
};


//class AProgressEvent;
/**
 * 
 */
UCLASS()
class DROID_API AAPj_013_VerticalCppGameModeBase : public AGameModeBase
{
	GENERATED_BODY()

	public:
		UFUNCTION(BlueprintCallable)
		void AddProgressEvent(AProgressEvent* ProgressEvent, float EventLocation);

		UPROPERTY(BlueprintReadWrite, EditAnywhere)
		TArray<FStr_ProgressEvent> ProgressEventList;
};

.cpp

#include "APj_013_VerticalCppGameModeBase.h"

void AAPj_013_VerticalCppGameModeBase::AddProgressEvent(AProgressEvent* ProgressEvent, float EventLocation)
{
	FStr_ProgressEvent NewStr;
	NewStr.EventRef = ProgressEvent;
	NewStr.XLoc = EventLocation;
	ProgressEventList.Add(NewStr);
}

Could you be resetting the TArray somewhere in your code or making it nullptr?

1 Like