Spawn "Object" from string reference in C++?

I want to be able to do something according to the “idea” in this code snipet (that doesn’t work).

TArray<UObject*> UFuzzyFetcherLibrary::getAllMatchingObjects(const FString& json)
	TArray<UObject*> result; 
	static ConstructorHelpers::FClassFinder<UObject> theClass(TEXT("Class'/Script/PluginProject.MyObject'"));
	if (theClass.Class) {
		UObject* classPointer = (UObject*)theClass.Class.GetDefaultObject();
	return result;

Later the string will be provided from an external source. The objects are not necessarly BPs and if possible I would like to be able to keep it that way. Currently the Array contains zero object when i use this function from blueprints, probably due to the “ClassFinder” not finding the class.

Take a look at the FindObject, LoadObject, and LoadClass functions in UObjectGlobals.h. They can be used to load stuff from string paths at runtime.

Keep in mind you might need to explicitly list any assets you intend to load this way to always be packaged with your project, otherwise they might be omitted during the packaging process because there are no other references to them in your project.

In additiona to what cancel has said, StaticLoadObject is also useful if you’re looking to create an instance of an object from a path, e.g. loading a static mesh:

UStaticMesh* meshToUse = Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), NULL, TEXT("pathToYourAssetHere")));
if(meshToUse && mesh)

In the end i found it to allways be easier to just add a UPROPERTY to my class and set the value in the editor holding the class type i want to spawn.