Struct compile error

Hi everyone,

I tried following the unreal documentation on this topic from what I understood it should be very simple, so I tried creating a struct in my playercontroller’s header

USTRUCT()
	struct FShipMovementStruct
	{
		GENERATED_USTRUCT_BODY()

		UPROPERTY()
			AShipBase* ShipPointer;
		UPROPERTY()
			FVector ShipDirection;
		FShipMovementStruct()
		{
			ShipPointer = nullptr;
			ShipDirection = FVector::ZeroVector;
		}
	};

But I guess there is more to it. The compiler throws the following errors saying that they are the [ProjectName].cpp file. I haven’t touched anything there. Here is the output:

TheColony.generated.cpp(77): error C2653: ‘FShipMovementStruct’ : is not a class or namespace name

TheColony.generated.cpp(85): error C2065: ‘FShipMovementStruct’ : undeclared identifier

TheColony.generated.cpp(85): error C2070: ‘unknown-type’: illegal sizeof operand

TheColony.generated.cpp(89): error C2653: ‘FShipMovementStruct’ : is not a class or namespace name

TheColony.generated.cpp(94): error C2065: ‘FShipMovementStruct’ : undeclared identifier

TheColony.generated.cpp(94): error C2923: ‘UScriptStruct::TCppStructOps’ : ‘FShipMovementStruct’ is not a valid template type argument for parameter ‘CPPSTRUCT’

TheColony.generated.cpp(94): error C2512: ‘UScriptStruct::TCppStructOps’ : no appropriate default constructor available

TheColony.generated.cpp(94): error C2660: ‘UScriptStruct::DeferCppStructOps’ : function does not take 1 arguments

TheColony.generated.cpp(787): error C2065: ‘FShipMovementStruct’ : undeclared identifier

TheColony.generated.cpp(787): error C2923: ‘UScriptStruct::TCppStructOps’ : ‘FShipMovementStruct’ is not a valid template type argument for parameter ‘CPPSTRUCT’

TheColony.generated.cpp(787): error C2512: ‘UScriptStruct::TCppStructOps’ : no appropriate default constructor availableTC_PlayerController.cpp

TheColony.generated.cpp(787): error C2664: ‘UScriptStruct::UScriptStruct(const UScriptStruct &)’ : cannot convert argument 1 from ‘FObjectInitializer’ to ‘EStaticConstructor’

No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

TheColony.generated.cpp(788): error C2065: ‘FShipMovementStruct’ : undeclared identifier

TheColony.generated.cpp(788): error C2059: syntax error : ‘)’

TheColony.generated.cpp(788): error C2143: syntax error : missing ‘(’ before ‘)’

TheColony.generated.cpp(789): error C2065: ‘FShipMovementStruct’ : undeclared identifier

TheColony.generated.cpp(789): error C2059: syntax error : ‘)’

TheColony.generated.cpp(789): error C2143: syntax error : missing ‘(’ before ‘)’

And the problematic code in TheColony.cpp file is the following

class UScriptStruct* FShipMovementStruct::StaticStruct()
{
	static class UScriptStruct* Singleton = NULL;
	if (!Singleton)
	{
		extern THECOLONY_API class UScriptStruct* Z_Construct_UScriptStruct_FShipMovementStruct();
		extern THECOLONY_API uint32 Get_Z_Construct_UScriptStruct_FShipMovementStruct_CRC();
		extern THECOLONY_API class UPackage* Z_Construct_UPackage_TheColony();
		Singleton = GetStaticStruct(Z_Construct_UScriptStruct_FShipMovementStruct, Z_Construct_UPackage_TheColony(), TEXT("ShipMovementStruct"), sizeof(FShipMovementStruct), Get_Z_Construct_UScriptStruct_FShipMovementStruct_CRC());
	}
	return Singleton;
}

and the following two lines which I barely understand

ReturnStruct = new(EC_InternalUseOnlyConstructor, Outer, TEXT("ShipMovementStruct"), RF_Public|RF_Transient|RF_Native) UScriptStruct(FObjectInitializer(), NULL, new UScriptStruct::TCppStructOps<FShipMovementStruct>, EStructFlags(0x00000001));
		UProperty* NewProp_ShipDirection = new(EC_InternalUseOnlyConstructor, ReturnStruct, TEXT("ShipDirection"), RF_Public|RF_Transient|RF_Native) UStructProperty(CPP_PROPERTY_BASE(ShipDirection, FShipMovementStruct), 0x0000000000000000, Z_Construct_UScriptStruct_FVector());

Can someone please tell me what is the problem

1 Like

I found what I was doing wrong.

I was basically defining the struct inside the class. the correct way was to define it above or below the class but not inside it.

1 Like