I am trying to spawn an actor from within my C++ code but can’t seem to get it right without crashing Unreal when loading my project. I setup an actor class called Ball (ABall in C++) and have created a call to the SpawnActor function (from here) and it just doesn’t seem to work.
Thanks NTG, this has allowed my editor to open with the spawn actor function compiled, however I am still not seeing any type of object appear in the game/hierarchy. I’ll take a look through the FPS tutorial and see if that can give me any pointers when it spawns the projectile object.
Maybe it will help:
Spawning:
So you need a game Mode as C++ class and then in the Editor under Edit->Project Settings->Maps & Modes: Default Modes you need to set your created GameMode as default game mode. So that this game mode is launched when you start your game.
Or :
open class Viewer from editor and drag your object inside the scene. But i think you want to spawn it.
GameMode cpp:
void AKawummGameMode::BeginPlay()
{
Super::BeginPlay();
UWorld* const World = GetWorld();
if (World)
{
World->SpawnActor<ASolidBlock>(ASolidBlock::StaticClass());
}
}