I don’t have much context for some of the variables you’re using so I can’t go too in-depth while looking into this issue, but I can at least provide you with and idea of what the problem is. I believe the issue with your implementation of FindObject may be due to the parameters it is expecting.
This page shows what the expected parameters are for the FindObject function, they are quite different from the ones for FObjectFinder. (FObjectFinder | Unreal Engine Documentation)
If this isn’t enough to help you overcome this issue, please supply me with the .cpp and .h that these functions are being used in to hopefully give me more context.
All the variables I’m using (except widgetClassesCache) are defined in the example code. As for widgetClassesCache — it’s just a static TArray.
I have already seen the docs for these methods, as well as some related questions and even skimmed through some uses in the engine sources, so I believe I’m passing the right parameters.
Here is the .h and .cpp files:
I will really appreciate if you’ll look at them, as I’m out of the ideas of what could be wrong.
After digging into the use of FindObject itself, I believe I’ve found the problem. It seems that LoadObject must be used before using FindObject as it cannot locate a class that has not yet been loaded. FObjectFinder must automatically load classes or something of the sort so that it can bypass this for ease of access.
Below is a link for the LoadObject function itself.
If using that function doesn’t work out for you, please let me know, I’d be happy to look into the issue further with you.
Note the first and thrid lines are identical. But the first line will return NULL, and the third will return the right value, so FindObject really works only if the object is already loaded.
In addition to that I checked the LoadObject code and it’s anyway doing a Find first to ensure its not loading twice.