[C++] How Do I Initialize Movement/Falling State on Spawned Character?

Dear Friends at Epic,

Hi there!

So I’ve made progress from a previous question about how to spawn creatures.

Now, after following James Goulding’s advice, I can get duplicates of my main Character class to spawn with mesh and added components and even the animation blueprint playing properly.

You cant see in the picture, but the spawned creatures are actually playing the correct idle animation, given their current speed.

Speaking of speed,

How do I initialize the spawned creature’s movementcomponent properly, or whatever else I need to do so that the creature falls the ground from the spawn point

and can begin receiving movement commands?

Here is my new spawn code thanks to James:

minor question
(how do I use the generated blueprint class as the type, instead of assuming/knowing it is the main character class?
I know my code below is not perfect for spawning because I am assuming the generated class type)

constructor
static ConstructorHelpers::FObjectFinder PlayerPawnOb(TEXT("Blueprint'/Game/Blueprints/MyCharacter.MyCharacter'"));
	if (PlayerPawnOb.Object != NULL)
	{
		CreatureClass = (UClass*)PlayerPawnOb.Object->GeneratedClass;
	}

in a test function
{
AVictoryGameCharacter* NewCreature = 
		GetWorld()->SpawnActor(CreatureClass, TestLocation, GetControlRotation(),SpawnInfo );
}	

Here is where I am trying to initialize movement, in the main character class’s constructor

AVictoryGameCharacter::AVictoryGameCharacter(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
//Set Movement Settings
	
	//defaults
	CharacterMovement->DefaultLandMovementMode = EMovementMode::MOVE_Walking;
	CharacterMovement->DefaultWaterMovementMode = EMovementMode::MOVE_Falling;
	
	//air control
	CharacterMovement->AirControl = 0.7;
	
	//Set movement to falling on spawn
	CharacterMovement->SetMovementMode(EMovementMode::MOVE_Falling);

Thanks for the help!

:slight_smile:

supplemental picture, illustrating the issue, they spawn just fine, accept they seem uninterested in gravity :slight_smile:

I figured it out, I had to spawn a controller for the character to get it to start physics!

Setting:

CharacterMovement->bRunPhysicsWithNoController = true;

did not help

Had to actually make a controller :slight_smile:

//pawn.h
SpawnDefaultController();