Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Issues with ANY_PACKAGE used in FindObject

In trying to get a FString representation of one of my Enums, I am getting a compile error:

error C2664: 'T FindObject(UObject ,const TCHAR ,bool)': cannot convert argument 1 from 'UPackage ' to 'UObject *'

I have not been able to figure out what I am missing to make this work.


 template<typename TEnum>
 static FORCEINLINE FString GetEnumToString(const FString& Name, TEnum Value)
     const UEnum* enumPtr = FindObject<UEnum>(ANY_PACKAGE, *Name, true);
     if (!enumPtr)
         return FString("Invalid");
     return enumPtr->GetNameByValue((int64)Value).ToString();

Product Version: UE 4.16
more ▼

asked Aug 15 '17 at 06:33 AM in C++ Programming

avatar image

66 3 9 30

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Of course, I immediately fixed it after posting the question.

I simply changed

 #include "CoreMinimal.h"


 #include "EngineMinimal.h"

more ▼

answered Aug 15 '17 at 06:45 AM

avatar image

66 3 9 30

avatar image Rumbleball Nov 14 '18 at 03:07 PM

Can anybody tell whats the difference? I searched the whole VS Solution for ANY_PACKAGE and the only thing that comes up is: #define ANY_PACKAGE ((UPackage*)-1) in ObjectMacros.h

Changing the include should not make any difference, as that is the only definition there is.

My code (plugin code) compiles fine for development, but the error comes up when trying build the plugin for shipping in 4.20. Also strange: the problem seems to occour in 4.16 already but in 4.19 I had no issue with it.

avatar image TharagonX Nov 21 '18 at 04:41 PM

@Rumbleball : The unity build feature of Unreal (which merges a lot of .cpp files into a single file during compilation for shorter compile time) can hide missing includes. Probably some other .cpp file got into the same unity compile chunk, which had the include that was actually missing in the first file the whole time.

avatar image Rumbleball Nov 22 '18 at 10:49 AM

The include should be fine as it finds the definition. The problem is that the compiler can`t resolve UPackage to UObject.

avatar image NL Feb 26 '19 at 09:24 AM

The culprit seems to be specifically StructOnScope.h, which is indirectly included by EngineMinimal.h, but not CoreMinimal.h. That file does mention the UPackage class. I have not looked further though.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question