Ok, I am trying to use a USTRUCT in UE4 but after following the documentation and looking at example after example of structs all over the Internet I am still left with the same compile error.
In Header file
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyInvIconActor.generated.h"
UCLASS()
class SURVIVAL_PROTO1_API AMyInvIconActor : public AActor
{
GENERATED_BODY()
FIconDataStruct myIconData;
public:
// Sets default values for this actor's properties
AMyInvIconActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
int ID;
int Amount;
};
USTRUCT()
struct FIconDataStruct {
GENERATED_BODY()
public:
UPROPERTY()
int ID;
FIconDataStruct() {
ID = 0;
}
};
In cpp file
#include "MyInvIconActor.h"
// Sets default values
AMyInvIconActor::AMyInvIconActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AMyInvIconActor::BeginPlay()
{
Super::BeginPlay();
myIconData.ID = 5;
}
// Called every frame
void AMyInvIconActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
Error-
C:\Users\james\Documents\Unreal Projects\Survival_Proto1\Source\Survival_Proto1/MyInvIconActor.h(15) : error C2079: ‘AMyInvIconActor::myIconData’ uses undefined struct ‘FIconDataStruct’
I don’t understand what is wrong with my code. If the struct is undefined then I don’t see how it would let me do FIconDataStruct myIconData under generated body, the intellesense shows the struct which doesn’t usually happen if something is undefined because if it is undefined then in VS’s eyes it does not exist, So how is the intellesense suggesting it to me if it is undefined??? and it also lets me access the struct in the cpp file. How is this undefined???