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