USTRUCT Causes issues with following class

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;
.
.
.
.

First, in 4.11+, GENERATED_BODY() should be used instead of GENERATED_USTRUCT_BODY():

At least as of version 4.11, using
GENERATED_USTRUCT_BODY() will result
in a UHT error stating
GENERATED_BODY() is expected.

https://wiki.unrealengine.com/Structs,_USTRUCTS(),_They’re_Awesome

Another problem is that you mark methods FPlayerLocation(), FPlayerRotator() with UPROPERTY:

UPROPERTY(BlueprintReadOnly)
FVector FPlayerLocation();

So, please change it to a property (from method, as above) and keep it marked with UPROPERTY:

UPROPERTY(BlueprintReadOnly)
FVector PlayerLocation;

Alternatively, if you want a method, you can expose it with UFUNCTION:

UFUNCTION(BlueprintCallable)
FVector GetPlayerLocation() const {
    return this->PlayerLocation;
}

private:
    FVector PlayerLocation;

Finally, if you want to access your USTRUCT from blueprints, add:

USTRUCT(BlueprintType)

So, after those changes, your code should be like this:

USTRUCT(BlueprintType)
struct FLocationStruct 
{
	GENERATED_BODY()

	FLoctationStruct();

	UPROPERTY(BlueprintReadOnly)
	FVector PlayerLocation;

	UPROPERTY(BlueprintReadOnly)
	FRotator PlayerRotator;
};

It is also worth noting, that if you want a struct that contains location and rotation (and scale), FTransform does exactly that.

I changed the code as you suggested. GENERATED_BODY() is still showing the error “identifier “StationEscape_Souce_StationEscape_Grabber_h_14_GENERATED_BODY” is undefined” This still keeps the class declaration from being recognized. I get the error on UCLASS “this declaration has no storage class or type specifier” and on class just below “expected a ;”. To make things stranger If I block comment the USTRUCT out I get the same errors, even waiting a good hour for intellisence to catch up but regardless it will not compile. If I completely remove the USTRUCT then the code will be fine with intellisence and it will compile.

#pragma once

#include "Components/ActorComponent.h"
#include "Engine/DataTable.h"
#include "ObjectBase.h"
#include "Grabber.generated.h"


USTRUCT(BlueprintType)
struct FLocationStruct 
{
	GENERATED_BODY()

		FLoctationStruct();

		UPROPERTY(BlueprintReadOnly)
		FVector FPlayerLocation();
		UPROPERTY(BlueprintReadOnly)
		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);
.
.
.

Hmm, anyone?

Here you still have methods marked with UPROPERTY.
I added a fixed version of your code in the answer.

Oh, Crap… DUH. Now I realize what you were saying. Anyway, I fixed that and just made them variables for now but that didn’t change anything. So I just tried a blank struct to see if that did anything and it does not. Even with my code now looking like this I still have the same errors.
#pragma once

#include "Components/ActorComponent.h"
#include "Grabber.generated.h"


USTRUCT(BlueprintType)
struct FLocationStruct
{
	GENERATED_BODY()

		FLoctationStruct();

	

};


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;
.
.
.

Well the above code and the fixed code actually compiled, but I had to build it several times before one took. There was another question in here where someone had the same behavior his struck would compile in one project with no issue but in a different project he had to compile several times before the errors went away. I’ll go ahead an mark this answered and chalk it up to reflexive voodoo.

Try closing the editor, compiling the whole project with VS (or clang), and starting the editor again. Some things do not hot-reload well.

Maybe you’ve fixed it by now, but you have a typo in the spelling of your constructor:

FLoctationStruct()

I have accepted by now that IntelliSense won’t work properly at all times, but in my experience after creating a new UCLASS or USTRUCT it will run fine after compiling once, since the auto-generated headers are available then.

I have never seen this trick you’re using:

 #ifndef __INTELLISENSE__
 GENERATED_USTRUCT_BODY()
 #endif

Maybe it is doing more harm than good?

yes, that was fixed. I can’t tell you how many times I rewrote that code trying to get VS to stop dropping errors. Even now I can restart VS and the code will be good, I’ll make changes somewhere else and it will break so I have to do a restart to see it clean. I’m not sure it is something that can be fixed by Unreal as it is VS that is having the difficulty dealing with the macros.

I found that in one of the answers on here. I’ve since removed it. It was a trick used before UE changed over to just GENERATED_BODY() from what I could gather. It was supposed to force intellisense to recognize the macro name which it apparently use to puke on a lot. Figured it couldn’t hurt to try.