Download

Strange compile error when adding UPROPERTY

Hi,

I’m running into some weird compile error and I’m currently clueless on what is causing it.

I have a class derived from UDataAsset with the following member:


    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Effects")
        TArray<FSkillSpecialEffectData> SpecialEffects;

Everything compiles fine.

When I try to add this member:


UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Player\|Casting")
            bool RotateCasterToDirectionKey = true;

I get the following compile error:

ScaleWithStat_StatType does indeed exist in FSkillSpecialEffectData. This error doesn’t exist unless I add another UPROPERTY to my UDataAsset class.

If I remove the UPROPERTY tag from RotateCasterToDirectionKey, it again compiles fine.

Does anyone have any idea why this is happening?

Thanks.



"Player**\**|Casting"


bad ctrl+c / ctrl+v :slight_smile:

Thanks for the reply, but not sure what you mean. | is for adding Subcategories to the editor. I use it all over my code without a problem.

Yes, I know what that char is…
But there’s a small chance it could confuse UBT when generating the .generated files.

What if UBT goes and reads it as “Player\|Casting” instead, while you could’ve just written “Player|Casting” ?!

Since you don’t show any code and the error is in generated classes, the only thing I see is that…

Oh sorry, now I know what you mean.

But even changing it to Player|Casting doesn’t compile.

This compiles fine, as long as that UPROPERTY is commented out. When I un-comment it, I get the compile error. I just don’t understand why that specific UPROPERTY. There is nothing different about it.

I made a workaround which works by not even touching this file but still. I wonder what is causing it.

Did you delete *Intermediate *folder rebuilt the game from Visual Studio yet?

Yea, that was the first thing I tried. Deleted everything but Content, Config and Source. Even moved the project folder just in case.

What if you exchange that property placement with another one, just to see if the problem persists or other property gets the error? Just a thought, but I am also running out of ideas, lol

How did you manage to make Unreal’s reflection to accept “INT” macro from Windows Kit, instead of int32 ?
I though UHT couldn’t recognize custom typedef

Alright so I kind of fixed it but still have no idea why it was happening.

I went back and looked at the error about ScaleWithStat_StatType not existing. It’s type is an enum that I forward declared. I removed the forward declare and just imported the enum header and compiled and it worked. So I guess something wrong with forward declaring that specific enum type? No idea.

But to try and find out why forward declaring only worked based on the UPROPERTYs in a while different file I did some tests:

As for switching the order of the properties:

It seems like if there is more than 1 UPROPERTY between Icon and RequiredLevel, I get the compile error. If there is only 1, doesn’t matter what it is, then it will compile fine.

I moved RotateCasterToDirectionKey and RotateCasterToCamera to the bottom of the file, the last UPROPERTYs.

This worked:
Screenshot_2.png

And this worked:
Screenshot_3.png

but having them both:
Screenshot_4.png

caused the error again.

I tried changing INT to int32, no difference.

Totally confused but not using that forward declare fixes it so I’ll settle for that I guess.

Thanks everyone.

How about having a INT uproperty between those two bools? Just for the sake of weirdness…

Now it will only compile with both bool UPROPERTYs commented out lol. So strange.

Screenshot_1.png

Only commenting one of them out won’t compile now…even tho before I could have one of them.

Did you say ugly things to Unreal or Visual Studio recently? If so, they know… try telling them you’re sorry :s

I guess it is not liking the initialization for the bools… what if you just initialize them into the constructor?, since the INTs would be initialized there anyway.

Lol no I wasn’t but I definitely did after I started getting this error.

I thought so too but I have about 5 other bools above these that don’t cause any issue at all.

Did you at least try? Because I usually don’t initialize them in the declaration, so now Im thinking why I never got this error before…

Sorry for the late reply but initializing them in the constructor instead of declaration didn’t change anything.

Really weird… its getting lost on how to deal with the struct showed in that error… forward declaration should still work… well at least you found a workaround! Well keep an eye on this and test some on my own codes.

usually I use int32 instead of INT as someone mentioned.

You can also do bools as

uint32 bSomeBool:1;

This will make C++ use a 32 bit int as a giant bitmask combining all the bools of the class into one int. It may save some space at the expense of a small perf hit since it has to read from a bitmask rather than a bool directly.

It’s more likely that there’s a weird missing comma or something somewhere in the UPROPERTY() defs. UE4 compiler errors can be really confusing when you’re missing something simple like GENERATED_BODY() at the top of your UCLASS definition. After years of knowing how to fix C/C++ compiler errors I now have to learn how to fix UE4 compiler errors too. It becomes easier to know what weird thing you’re missing the more experience you get. Hopefully it’s something stupid like that and you’ll be back on your way.

(Oh wait I missed the other reply where you fixed it by including the enum header, I never actually tried forward declaring an enum but I assume you can’t unless it’s a pointer or a reference)

In my experience forward declarations of enums and structs don’t work. The reason it may have worked before is because under the hood UE4 can merge source files before compiling to reduce compile time. This is called “unity build”. The reason why it broke suddenly is then because after small code changes can cause the unity build to combine the files together in a different way. So by chance the unity build took care of an include you were missing, and by chance it stopped doing that after different files were combined.

To disable unity build, go to your project’s MyProject.Target.cs and add to the constructor:



        bUseUnityBuild = false;


Try compiling once in a while with unity build disabled, it may reveal some more missing includes which would have randomly turned up later.