Workaround for "FindObject" in Object Class

Hey guys, I want to get the name of an enum inside of a normal object class, but I get an error using FindObject in there. So my Question is: Is there any other way of getting the const UEnum* or another workaround for it?

well, thanks for your comment, but it does not really help me :confused: findobject will work (A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums) .I´m setting the variables correct, you could have been because they are named similarly.

Ok, few notes:

  1. enum is not an object, so findobject wont work.
  2. if i understand correctly, in your constructor you want to set your variable "type"and “amount”. Not assign your constructor variables to whichever the default values are for type and amount.
  3. when setting “type” correctly in your constructor, you can just use this same “type” variable as your class’ enum.

oh, i didnt know enums could be found like that.I stand corrected. your variables however should be set the other way around. item::type = type; and item::amount = amount;

that being said, what is the error it shows you?

Hi MrZelektronz,

First thing to note here is that in the code you posted, in the 2nd line of your function getName(), the variable type is undefined (unless you have defined it somewhere else which is not posted in your original question). That aside, in order to get the name of an enum as a FString you should do the followings:

  • Make sure that your enums are defined in a way that Unreal Engine can understand them. Here’s two different way of defining Enums in an Unreal Engine friendly manner:

Note that they should be marked by the macro UENUM(/*Optional Specifiers*/). You can use any of these two versions and they will both work fine.

  • Having defined your enums properly, you can get the name of your enums as a FString and print them to Ouput log screen as such:

See that static_cast difference between the two version of Enums for this case? You do not need to include anything for this code to work as long as you have CoreMinimal.h included in your header file. However if the intellisense still fails to catch up and keeps giving you false warnings, you can #include "UObject/Package.h" in your .cpp file which should take care of these intellisense errors for you.

Hope this answered your question.