At wit's end with this strange error

After promoting “AimDirection”, I have run into this build error that I can’t seem to get around. The code will not compile, giving the error “declaration of ‘AimDirection’ hides class member”. I have been reviewing the video, the error, and the code over and over again and everything seems to be in order. Tried rebuilding everything (it doesn’t, because of the same error) and I even went so far as to delete my own code and paste Ben’s in its place and I’m still getting this error. What am I missing here?

Can you share your full code?

It’s saying that because you have AimDirection as the name of the parameter coming into the function, as the name of the private field/member in the class, it’s having trouble distinguishing between them (one of them hides the other).

Strictly speaking it’s a warning not an error, since it can still “work” but just may not have the intended result in the case of a typo.

If it’s giving you an error and stopping your compilation, you may have adjusted the warning severity for this problem too high.

However, just change one of the two FVector AimDirection declarations to have a different name, fix up the other references to it throughout the code so within the function it reads from the correct one, and you should be good to go.

To note, in later versions of Unreal, warnings are treated as errors.

1 Like

Ok that’s good to know. You can still downgrade it from a warning or override it case by case though, no?

I’m not advocating in this case that you do, but by golly, linters produce a lot of false positives in VS.

Unreal uses a custom build system. Having a look at it it doesn’t seem it’s globally (/Wx). Just shadowing

https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Programs/UnrealBuildTool/Platform/Windows/VCToolChain.cs#L494

I’m a little surprised Unreal doesn’t turn on the warnings for format specifiers.

1 Like

Oh, not sure that’s what I meant. I mean if you use VS’s or a 3rd party code analysis tool, they will pick out these warnings but you can enter in-code suppression of them with a pragma / comment.

Once these are done, the code analysis prior to the compilation should complete without warning, and then Unreal wouldn’t even know the warning had occurred (I have to presume it only reads the output of the build that can be compiled by various IDEs).

Even if a warning is on globally, local suppression usually takes precedence to it.

(For the OP’s benefit though, just fix the naming :smiley: this extended talk doesn’t apply in this specific case)

Thanks for the input. Just going to go ahead and make another similarly-named variable with same value as AimDirection. Could not get VS to yield at all to just using the one.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms