since ANY_PACKAGE got deprecated in UE 5.1 I am searching for alternatives to search for a c++ class by name. The suggested solution withing the deprecation msg isnt working, either when I pass an outer (for example the UWorld object) or by specifiying the package path (/Game/)
Note that this will only find enums that are defined within your project (Engine enums will return nullptr).
Also, for anyone who happens to be dealing with UEnums, I found another more general solution here:
Bonus tip: If you don’t know a class’s context, one way you can find it out is by using FindObject on the class’s name with the deprecated ANY_PACKAGE macro, then printing *GetNameSafe(class->GetOuter()) to the log to find out what it is.
UE5.1 Documentation mentions:
Outer object to look inside. If this is ANY_PACKAGE it will search all in memory packages, if this is null then InName should start with a package name.
So I replaced ANY PACKAGE with nullptr.
Then I found the class I was looking for in UE Content Drawer and copied reference.
You can use FindFirstObjectSafe() instead of FindObject()
for example, is my case this: UClass* Result = FindObject<UClass>(ANY_PACKAGE, *Name)
changed to: UClass* Result = FindFirstObjectSafe<UClass>(*Name);