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();
		result.Push(classPointer);
	}
	
	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.

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)
{
     mesh->SetStaticMesh(meshToUse);
}

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.