A simple example of spawning a new object instance from a blueprint (or any other type of) Uclass:
UObject* AMySpawner::NewObjectInstance(UObject* Context, UClass* Class) {
if ( !Context || !Context->IsValidLowLevelFast() || Context->IsPendingKill() ) { return nullptr; }
if ( Class == nullptr ) { return nullptr; }
auto World = GEngine->GetWorldFromContextObject ( Context, EGetWorldErrorMode::LogAndReturnNull );
if ( World != nullptr ) { return NewObject<UObject>( Context , Class ); }
return nullptr;
}
Or just getting the CDO (class default object) which is always spawned by the engine when game exe is launched:
UObject* AMySpawner::GetClassDefaultObject(UClass* Class) {
return Class->GetDefaultObject(true);
}