Programmaticly add an instance of a object/mesh

I just needs a quick example of how to add an mesh to the scene. Preferably this would be a mesh that I imported into the Editor and then I just create multiple instances (500+) of them at specified locations. Once placed I may be changing their location dynamically as the game runs, but only the position needs to change.

Dear Noctys,

Here are my personal functions that I use to simplify spawning in code!

#Spawn

//***************
//			SPAWN
template <typename VictoryObjType>
static FORCEINLINE VictoryObjType* Spawn(
	UWorld* TheWorld, 
	const FVector& Loc,
	const FRotator& Rot,
	const bool bNoCollisionFail = true,
	AActor* Owner = NULL,
	APawn* Instigator = NULL
){
	if(!TheWorld) return NULL;
	//~~~~~~~~~~~
		
	FActorSpawnParameters SpawnInfo;
	SpawnInfo.bNoCollisionFail 		= bNoCollisionFail;
	SpawnInfo.Owner 				= Owner;
	SpawnInfo.Instigator				= Instigator;
	SpawnInfo.bDeferConstruction 	= false;
		
	return TheWorld->SpawnActor<VictoryObjType>(VictoryObjType::StaticClass(), Loc ,Rot, SpawnInfo );
}

#EX:

//In an Actor Class
AStaticMeshActor* NewSMA = Spawn<AStaticMeshActor>(GetWorld(), Loc,Rot);

#Spawn From a BP

//***************
//			SPAWN
template 
static FORCEINLINE VictoryObjType* SpawnBP(
	UWorld* TheWorld, 
	UClass* TheBP,
	const FVector& Loc,
	const FRotator& Rot,
	const bool bNoCollisionFail = true,
	AActor* Owner = NULL,
	APawn* Instigator = NULL
){
	if(!TheWorld) return NULL;
	if(!TheBP) return NULL;
	//~~~~~~~~~~~
		
	FActorSpawnParameters SpawnInfo;
	SpawnInfo.bNoCollisionFail 		= bNoCollisionFail;
	SpawnInfo.Owner 				= Owner;
	SpawnInfo.Instigator				= Instigator;
	SpawnInfo.bDeferConstruction 	= false;
		
	return TheWorld->SpawnActor<VictoryObjType>(TheBP, Loc ,Rot, SpawnInfo );
}

#Ex:

 //In an Actor Class
AStaticMeshActor* NewSMA = Spawn<AStaticMeshActor>(GetWorld(), MyBP,  Loc,Rot);

#Setting a BP in .H and Then Editor

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category=BPClasses)
UClass* MyBP;

Enjoy!

#:heart:

Rama

Thanks for this snippet, Rama. Glad to see you here.

Hee hee!

#:heart:

Rama

Awsome. thanks! I may comment back if I have questions.