I’ll start by saying that I am very new to C++ and Unreal, so I apologize ahead of time if my lingo is not exact and please correct me when I use a term wrong.
I am attempting to refactor my code and I have several member functions that need to get player location and rotator objects. Figuring this would be a good opportunity to learn how to use structs in Unreal I decided to make a struct that simply grabs the FVector and FRotator for my pawn and later abstract it to give the values for any body.
Below you can see where I declared the USTRUCT and based on all of my research I have declared it correctly. I added the #ifndef based on several answers to other questions about why intellisense craps on the GENERATED_STRUCT_BODY(). However this did not solve the problem, but at least allowed intelli to recognize my struct method names. The problem now is that my class definition below the struct is not being recognized at all by the compiler or intelli. A hover over UCLASS gives the error “this declaration has no stroage class or type specifier”.
My code works fine without the USTRUCT, so it has to be causing the issue some how but I can’t figure out how. I’ve even tried including Engine/DataTable.h and ObjectBase.h, Engine/DataTable.h because I saw someone say you had to do it and ObjectBase.h because that is where I found the declaration of GENERATED_USTRUCT_BODY() but either of the include had any effect so I removed them as they should be included as part of the generated.h as I understand.
Edit: Wanted to add that without the constructor it will not even recognize the first method FPlayerLocation, it will give the error "expected ; " on the method.
#ifndef __INTELLISENSE__
GENERATED_USTRUCT_BODY()
#endif
#include "Components/ActorComponent.h"
#include "Grabber.generated.h"
USTRUCT()
struct FLocationStruct
{
GENERATED_USTRUCT_BODY()
FLoctationStruct();
UPROPERTY(BlueprintReadOnly)
FVector FPlayerLocation();
UPROPERTY(BlueprintReadOny)
FRotator FPlayerRotator();
};
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class STATIONESCAPE_API UGrabber : public UActorComponent
{
GENERATED_BODY()
public:
UGrabber();
virtual void BeginPlay() override;
virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;
///These set arm length reach for player
float GetReachDistance();
void SetReachDistance(float);
private:
//Allows us to set reach distance in Unreal UI
UPROPERTY(EditAnywhere)
float ReachDistance;
.
.
.
.