How to use FindObject()?

I am trying to “translate” this UE3 code to UE4 C++ (code taken from JSon Save States UDK gem, ObjectName is an object’s GetPathName()):

          Actor = Actor(FindObject(ObjectName, class'Actor'));

But how does FindObject() works in UE4? It expects an UObject* Outer as input, I don’t understand what to put.

Here’s the FindObject() signature (UObjectGlobals.h line 997):

template< class T > 
inline T* FindObject( UObject* Outer, const TCHAR* Name, bool ExactClass=0 )

I usually just put this (whatever class you are in) as outer, or NULL.

It probably doesnt matter at all unless what you are looking for is an actor component sub object ptr

Rama

PS: so an example from my code:

#UObjectGlobals.h

COREUOBJECT_API UObject* StaticLoadObject( UClass* Class, UObject* InOuter, const TCHAR* Name,

becomes

Cast( StaticLoadObject(
			UMaterial::StaticClass(), NULL,
			*TheMaterialFNamePath.ToString() //to get the platform specific *TChar
	));

You should really try to avoid using NULL if possible and instead use nullptr. It’s a lot safer if only because you’re not checking against a number (zero) - and it’s part of the C++ language as of C++11 (which is required by Rocket in any case!).

1 Like

I’ve never used that function but I’m guessing that you want to pass the world (which you can get by calling GetWorld() from inside any actor) as the “Outer” parameter.