[Question]Spawning "Blueprint 'Static Mesh' Tiles" from C++

I can’t seem to figure out how to spawn a blueprint that has a static mesh. What i’m trying to do is spawn a simple blueprint with it’s world location and rotation set to the outputs from our maze generator function.

I’m pretty sure this should be in my gamemode ? Or maybe just a simple actor class ? Any other ideas where i should be placing my maze generator to spawn these “BP tiles”?

I understand SpawnActor is what I’m looking for. Can i see a simple usage ?

#You Are In Luck

I just fnished a tutorial on this :slight_smile:

#Basic Version

PlayerController, HUD, or Character.h

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

PlayerController, HUD, or Character.cpp

FActorSpawnParameters SpawnInfo;
SpawnInfo.bNoCollisionFail 	= true;
SpawnInfo.Owner 			= this;
SpawnInfo.bDeferConstruction 	= false;

AStaticMeshActor* NewTile = 
	GetWorld()->SpawnActor(
		YourTileBP, SpawnLoc ,SpawnRot, SpawnInfo );

#FVector SpawnLoc and FRotator SpawnRot

Whatever values you want :slight_smile:

#To Do: Make a Static Mesh Actor BP

After compile time you need to go into editor,

  • make a blueprint of a static mesh actor
  • assign your mesh
  • filter for “material” and assign any default material that you want (under Rendering)
  • go to the blueprint of whatever class you are using to spawn stuff, such as HUD or PlayerController or Character
  • plug in your new Blueprint for YourBPTile

#Template Version

Wow interesting Timing!

I just finished writing a template Spawn Actor from Blueprint function!

all details here
http://forums.epicgames.com/threads/973803-20-Tutorials-UE4-C-Concepts-Templates-lt-Template-gt-Spawn-Actor-From-BP-For-You!?p=31777885#post31777885

#Code for Templated Version

stick this in your .h for your HUD or PC or Character

That’s the .h, not the .cpp, since this is FORCELINE

template 
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(TheBP, Loc ,Rot, SpawnInfo );
}

#Template Usage

AStaticMeshActor* NewTile = SpawnBP(GetWorld(), YourTileBP, SpawnLoc, SpawnRot);

#Enjoy!

Enjoy!

You can use my Template to spawn any kind of BP you want in a convenient way

Rama

You are sensational! Thank you so much! Once i work out the kinks in my maze gen algorithm I’ll release it to the community and dedicate it to you since you provide such awesome help and helpful tutorials in areas which are lacking! Thanks again Nathan :wink:

Hee hee!

Sounds like fun to me! Good luck with your maze!

Rama

I just wanted to add a picture showing it working, as i didn’t get around to taking one yesterday It’s just a simple loop and offsetting the newly spawned actor as such. :smiley: Thanks so much again Rama! <3

#Woohoo Congrats :heart:

Woohoo!

That’s awesome Robert!

Can’t wait to see it develop further!

:heart:

Rama