How to get class of an object?

Hello, i’m making my own blueprintable class to be used as scripts for future in-game items, however i’m unsure about how to actually instance them. I made a base class in C++ already and bluepritns will inhert from this class.
Here’s what iv’e been trying:

UTestClass* UGameLibrary::InitializeScript(TSubclassOf<class UTestClass> script, AActor* Owner, FName name)
{
	return (UTestClass*)NewObject<class of script>(Owner, name);
}

Now as you can see NewObject needs a type parameter in <>, but inside this function i don’t know what it will be, that’s why i have a parameter TSubClassOf script, however i can’t simply pass it into the NewObject.

Is there a way i could pass the input variable’s type into the NewObject?
If i use templates the function won’t be callable from blueprint.

NewObject indeed allows you to specify type, like this:

UTestClass* testObject = NewObject<UTestClass>(Owner, script, name);

Check out UObjectGlobals.h for the full list of NewObject templates available.