Other classes don't recognize my UStruct

I created a UStruct and when I try to use it as a variable/UProperty in other classes, it gives me the following errors:

1>d:\documents\unreal projects\megarisk\source\megarisk\Army/Army.h(41): error C3646: 'team': unknown override specifier
1>d:\documents\unreal projects\megarisk\source\megarisk\Army/Army.h(41): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

I’ve tried things like uppercase-ing the variable name and removing the UProperty macro, and I also tried making a property of a different struct. That last one worked, so I know it’s a problem with this specific struct. The other struct also had a default constructor and a LOCTEXT_NAMESPACE thing at the top.

TeamStruct.h

#define LOCTEXT_NAMESPACE "team"

#pragma once

#include "Object.h"
#include "includes.h"
#include "TeamStruct.generated.h"

/**
 * 
 */
USTRUCT(BlueprintType)
struct MEGARISK_API FTeamStruct
{
	GENERATED_BODY()

		//Default constructor is default
	FTeamStruct()
	{
		teamNum = -1;
		ownerController = nullptr;
		teamColor = FLinearColor(0.0, 0.0, 0.0, 1.0);
	}

/**	FTeamStruct(AController inController)
	{
		teamNum = -1;
		ownerController = &inController;
		teamColor = FLinearColor(0.0, 0.0, 0.0, 1.0);
	}

	FTeamStruct(int32 inNum, AController inController, FLinearColor inColor)
	{
		teamNum = inNum;
		ownerController = &inController;
		teamColor = inColor;
	}*/

	UPROPERTY(BlueprintReadWrite, category = "team")
		FName name;

	UPROPERTY(BlueprintReadWrite, category = "team")
		int32 teamNum;

	UPROPERTY(BlueprintReadWrite, category = "team")
		AController* ownerController;

	UPROPERTY(BlueprintReadWrite, category = "team")
		FLinearColor teamColor;

	UPROPERTY(BlueprintReadWrite, category = "team")
		TArray<class ATerritory*> territoryArray;
	UPROPERTY(BlueprintReadWrite, category = "team")
		TArray<class AArmy*> armyArray;
};

#undef LOCTEXT_NAMESPACE

and here’s part of a .h where I’m declaring a TeamStruct variable. I do have a proper #include at the top, before the #include .generated.h thing:

UPROPERTY(BlueprintReadWrite, Category = "team")
	FTeamStruct team;

bumpidy bump

Hi MrShmid,

I haven’t used plain USTRUCTs much, so I’m not sure how much help I can provide.

That said, two things jump out at me:

  1. Your struct uses the GENERATED_BODY() macro where the ones I’ve used have the GENERATED_USTRUCT_BODY() macro. I think they resolve to the same thing, but you could try using the USTRUCT version just in case.
  2. Your first error is about an override specifier. Your property declaration doesn’t include one of those, and I don’t think the UPROPERTY() macro will generate one either. This makes me wonder if there’s an error in one of the surrounding lines. Perhaps a missing semi-colon on the previous line, for example. Have you made sure the nearby lines are right, or tried declaring a new property (e.g. with a different struct) right before this one?

Anyway, I hope this helps and best of luck either way!

I tried using GENERATED_USTRUCT_BODY(), I tried using declaring a different struct right above the broken one, and I also tried making a different class and copy-pasting the code. None of it worked.

I have another struct that I’ve been copying elements from (local_namespace, default constructor, etc) and it works perfectly. I have no idea what could be causing this.

Hi MrShmid,

That sounds very odd.

Are you able to post a few of the other lines surrounding the property declaration (apparently from Army.h)? That might be helpful.

Also, out of curiosity, have you tried moving the LOCTEXT_NAMESPACE bit below the #pragma once line? If that doesn’t help, you could try doing that in the other struct(s) too. I’d expect to see a different error if that was causing problems, but if I’m correctly inferring its purpose, it probably belongs below the #pragma once in any case.

None of my working structs have that. I tried it anyway and nothing changed.

Worth checking!

Unfortunately, we’ve reached the limit of my knowledge. I’m out of guesses too. If something else occurs to me, I’ll be sure to post it.

For now, hopefully someone else sees what I’m missing.

Best of luck!

If I had to hazard a guess, then I would associate it with your use of a namespace. #define LOCTEXT_NAMESPACE "team"

It does not know what an FTeamStruct is. Default-int comes from C, where if a return type isn’t specified it will return an int, and as it says C++ doesn’t support this, which essentially translates to not having a return type that it’s aware of.

If that isn’t the issue then you’ll need to pastebin the army.h.

In response to : GENERATED_USTRUCT_BODY() is obsolete, only not marked as such. GENERATED_BODY() is correct.

Tried those fixes, still got the same errors. Here’s army.h (‘Team’ is the new struct I made to replace TeamStruct)

#pragma once

#include "GameFramework/Actor.h"
#include "Data/Team.h"
#include "Data/SettingsVar.h"
#include "includes.h"
#include "Army.generated.h"

UCLASS()
class MEGARISK_API AArmy : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AArmy();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	UPROPERTY(BlueprintReadWrite, Category = "team")
		int32 teamNum;

	UPROPERTY(BlueprintReadWrite, Category = "troops")
		int32 troops;

	UPROPERTY(BlueprintReadWrite, Category = "invasion")
		bool isGeneral;

	UPROPERTY(BlueprintReadWrite, Category = "invasion")
		bool isMarshal;

	UPROPERTY(BlueprintReadWrite, Category = "territory")
		ATerritory* homeTerr;

	UPROPERTY(BlueprintReadWrite, Category = "team")
	FSettingsVar testStruct;
	
	UPROPERTY(BlueprintReadWrite, Category = "team")
	FTeam teamStruct;


	TArray<UStaticMesh*> Meshes;

	//References
	UGameInstance* gameInstance;
	AGameState* gameState;
	AGameMode* gameMode;
	AController* controller;


	//Components
	UPROPERTY(BlueprintReadWrite, Category = "mesh")
		UStaticMeshComponent* armyMesh;

	UPROPERTY(BlueprintReadWrite, Category = "troops")
		UTextRenderComponent* troopText;

};

Ah well, thank for all your help!

Just to confirm, you removed it from the namespace provided by #define LOCTEXT_NAMESPACE "team" completely and the errors persisted?

The code looks fine other than that, so all that you can really do following that is to comment out lines of code until it works to isolate where the issue is actually happening.

Before that though, try putting your FTeam in your Army.h just to isolate the other file as being the cause.

Unfortunately the one line that seems to be causing all the problems is #include "includes.h". includes.h is basically an stdafx file where I store all of my frequently used headers.

The way I have the code set up, I almost have circular dependency. An army (and a number of other things) has a team variable, and each team, in turn, has a variable/array of all objects belonging to that team. This makes it a lot easier to get an object’s team or all of the armies owned by a team.

Also, it seems that structs don’t like being used via includes.h. I tried putting the working SettingsVar struct into includes.h and I got errors similar to the ones I’ve been having with the Team struct.

I’ve got to go to bed now so I’ll try some stuff out tomorrow. Thanks for all the help.

For anyone wondering if I solved this, I created a new UObject class that had a TeamStruct variable. I could use this wherever I wanted without any problems.

What I learned:

  • USTRUCTs don’t like being put in stdafx.h-style files
  • You can always make a wrapper object to hold something if it doesn’t like being #include’d in other things.

Hope that helps,

For anyone wondering if I solved this, I created a new UObject class that had a TeamStruct variable. I could use this wherever I wanted without any problems.

What I learned:

  • USTRUCTs don’t like being put in stdafx.h-style files
  • You can always make a wrapper object to hold something if it doesn’t like being #include’d in other things.

Hope that helps,

I had exactly the same problem, I have a messages.h class which includes a bunch of USTRUCT and UPROPERTY declarations, and this file was not compiling giving me the error of :

Error (active) member “FpsCharacterDetailsMessage::FName” is not a type name PSUnreal\net\messages.h 53

I solved it by adding at the top this line:

  #include "messages.generated.h"

which seems to be needed whenever you have a U* declaration in a class which is not default UE class.

It looks like this:

#pragma once

#include "PSUnreal.h"

#include "messages.generated.h"

// used in FpsCharacterDetailsMessage
USTRUCT(BlueprintType)
struct FNetworkDetailSkill
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FBonus Struct")
		FName category;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FBonus Struct")
		FName text;
};