Actors not spawning correctly

Hello Everyone,

I’m having a strange issue getting my pawns to spawn correctly for my players in a side-scroller co-op game. My code works in to the point that its spawning my characters. However, its spawning them with an incorrect location, they fall through the world, and their initial rotation seems off, but then it reverts back as soon as I give input. (But the characters still fall through the world).

Heres my GameMode code:


// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.

#include "SideOp.h"
#include "SideOpGameMode.h"
#include "SideOpCharacter.h"

ASideOpGameMode::ASideOpGameMode(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	static ConstructorHelpers::FClassFinder<APawn> PlayerPawnObject(TEXT("Pawn'/Game/Blueprints/BP_Character.BP_Character_C'"));

	// set default pawn class to our character
	if (PlayerPawnObject.Class != NULL /*&& HUDObject.Class != NULL*/)
	{
		DefaultPawnClass = PlayerPawnObject.Class;

	}

}

void ASideOpGameMode::BeginPlay()
{
	Super::BeginPlay();


}

void ASideOpGameMode::PostLogin(APlayerController* NewPlayer)
{
	Super::PostLogin(NewPlayer);
	TArray<ATargetPoint*> SpawnPoints;
	UBlueprint* PlayerToSpawn = BluePlayer;

	/* switch (NumPlayers)
	{
	case 0:
		PlayerToSpawn = BluePlayer;
		break;
	case 1:
		PlayerToSpawn = BeigePlayer;
		break;
	case 2:
		PlayerToSpawn = GreenPlayer;
		break;
	case 3:
		PlayerToSpawn = YellowPlayer;
		break;
	default:
		PlayerToSpawn = PinkPlayer;
		break;
	} */

	for (TActorIterator<ATargetPoint> ActrItr(GetWorld()); ActrItr; ++ActrItr)
	{
		SpawnPoints.Add(*ActrItr); // Fill our spawn points
	}

	if (PlayerToSpawn) // Make sure we have a player to spawn
	{
		if (SpawnPoints[NumPlayers]) // Make sure we have a spawn point
		{
			FActorSpawnParameters SpawnParams;
			SpawnParams.Instigator = nullptr;
			ASideOpCharacter* NewCharacter = GetWorld()->SpawnActor<ASideOpCharacter>(PlayerToSpawn->GetClass(), SpawnPoints[NumPlayers]->GetActorLocation(), SpawnPoints[NumPlayers]->GetActorRotation());
			NewPlayer->Possess(NewCharacter);
		}
	}

}

Ignore the code about which player to spawn. Thats just for color purposes. (I have my customised character class I wrote in C++ then I extended it with Blueprints for my designer to change the flipbooks and other small vars, and the GameMode .h has pointers to these blueprints exposed through UPROPERTY():wink:

I’ve tried manually setting the spawn location, and that fails, and I’ve tried manually setting the rotation as well. Both characters do spawn though, as I can see the small sliver of the rotated sprite for both. I also use the NumPlayers var as I assume the GameMode would automatically iterate as players joined. But changing the index of SpawnPoints to a numerical value (1 or 0) still fails. (I setup two target points in the level for testing the spawn code btw.) The characters still dont spawn in the correct spots or anything else correctly.

Any help is greatly appreciated.