Download

Character Subclass Half-spawns in ShooterGame

I’ve been trying to fix this for days and getting nowhere - I’m trying to spawn a blueprinted sublass of ShooterCharacter in the ShooterGameDemo. It just needs to be the Character, it’s not another game ‘player’. The subclassed character is sort of like a bot, but they are created by a player and have a custommovementcomponent that dictates how they move about the level.

When I place a few instances of the Blueprinted class into the level in the editor, everything works as expected. But when I try to Spawn the character mid-game, the Character’s mesh appears, but nothing happens. I can see that the character is being possessed by a controller, and PostInitializeComponents() is being called, but BeginPlay() is not being called.

This is related to the answerhub link below. I’ve run out of things to try, hoping someone here can give me a new route to head down…
https://answers.unrealengine.com/questions/161315/spawned-character-not-registering.html

ShooterCharacter Constructor:


...
static ConstructorHelpers::FObjectFinder<UBlueprint> BP(TEXT("Blueprint'/Game/GroundGame/Blueprints/BP_EnergyGround.BP_EnergyGround'"));
	if (BP.Object) {
		ClassToSpawn = (UClass*)tBP.Object->GeneratedClass;
	}
...


Spawning code:



...
Spawned = World->SpawnActor<APawn>(ClassToSpawn , GetActorLocation(), GetActorRotation(), SpawnParams);
World->GetAuthGameMode<AShooterGameMode>()->RestartPlayer(Spawned->GetController());
Cast<ACharacter>(SpawnedPickup)->GetCharacterMovement()->SetMovementMode(MOVE_Falling);
...


I still haven’t been able to figure this one out. Stepping through code, I do see that the spawned character’s Location value is being changed, but the character remains in place visually. Any ideas of other troubleshooting avenues to pursue?

First off, you are using the FObjectFinder instead of the FClassFinder, I don’t think it is making a difference, but FClassFinder is just cleaner.


static ConstructorHelpers::FClassFinder<APawn> PlayerPawnClassFinder(TEXT("/Game/Blueprints/MyCharacter"));
ClassToSpawn = PlayerPawnClassFinder.Class;

should do the trick.

If you are trying to replace the DefaultShooterPawn, just go to ShooterGameMode.cpp and change these lines


static ConstructorHelpers::FClassFinder<APawn> PlayerPawnOb(TEXT("/Game/Blueprints/Pawns/PlayerPawn"));
DefaultPawnClass = PlayerPawnOb.Class;

*Edit: I just read that Spawning works, so I guess you are trying to Spawn AI? otherwise there would be no real reason to bypass the GameMode Player/Pawn initializations.

Also, you Spawn the Pawn and call


Spawned->GetController()

but GetController() should always be NULL at this point, because, well you only Spawn the Pawn.