Download

Spawn StaticMeshActors from Object Libraries

I have found snippets of answers everywhere on google but nothing really comes up concise.

I have the following problem I want to solve and use.

I have created a Object Library that will contains x amount of objects (Static Meshes I import like baskets, or props, or anything that has a static mesh that you can spawn). By default, this array will have nothing. I want to load this Object Library by utilizing the


LoadAssetsFromPath();

and grab all static meshes and place it into the library. (I think this is already done in my code?) (Example:


myObjectLibrary->LoadAssetsFromPath("StaticMesh' /Game/Models/'");

.

The goal is to have all these static mesh actors pre loaded in the game so I can call when to spawn in a blueprint (or code) in specific areas of the game may it be 1 or 10 in a certain area.

This is where I start to scratch my head on how to spawn these objects and if the above method is even correct.

I the BeginPlay() function, I have:


TArray<UStaticMesh*>SMS_Objects;
myObjectLibrary->GetObjects(SMS_Objects);

// Testing if it got the item
UStaticMesh* tempSM = SMS_Objects[0];

// Error here saying Error    C2664    'T *UWorld::SpawnActor<UStaticMesh>(UClass *,const FTransform &,const FActorSpawnParameters &)': cannot convert argument 1 from 'UStaticMesh *' to 'const FVector &' 

GetWorld()->SPawnActor<UStaticMesh>(tempSM, FVector(0, 0, 600), FRotator(0, 0, 0));

In the myObjectLibrary.h class, I have property of


UStaticMeshComponent* myMesh;

and


UObjectLibrary* myObjectLibrary;

In the .cpp in the constructor, i have the Construction helper and the CreateDefaultSubobject for the root scene component and the mesh where


myMesh->SetupAttachment(RootScene);

Please help me on how to load all these objects into the library and using blueprints to call a matching static mesh actor(s) to spawn in specific locations in the world.

Thanks!