Having Problem, My tank is spawning above the ground level

Problem:- After setting the BP_GameModeBaseClass my tank is spawning in the sky rather than spawning on the ground.
NOTE:- Everything was fine before setting the game mode class.

BP_GameModeBaseClass:-


BP_PawnTank:-


I don’t think that the c++ code of the tank will help solve this problem.
But Still here is the code in case the problem is related to the code.

BasePawn Header:-

`// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include “CoreMinimal.h”

#include “GameFramework/Pawn.h”

#include “BasePawn.generated.h”

UCLASS()

class TOONTANKS_API ABasePawn : public APawn

{

GENERATED_BODY()

public:

// Sets default values for this pawn's properties

ABasePawn();

protected:

void RotateTurret(FVector LookAtTarget);

void FireProjectile();

private:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))

class UCapsuleComponent* CapsuleComp = nullptr;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))

UStaticMeshComponent* BaseMesh = nullptr;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))

UStaticMeshComponent* Turret = nullptr;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))

USceneComponent* ProjectileSpawnPoint = nullptr;

UPROPERTY(EditDefaultsOnly, Category = "Combat")

TSubclassOf<class AProjectile> ProjectileClass;

};`

BasePawn CPP-

`// Fill out your copyright notice in the Description page of Project Settings.

#include “BasePawn.h”

#include “Components/CapsuleComponent.h”

#include “Projectile.h”

// Sets default values

ABasePawn::ABasePawn()

{

// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.

PrimaryActorTick.bCanEverTick = true;

CapsuleComp = CreateDefaultSubobject<UCapsuleComponent>(TEXT("Capsule Collider")); //Storing Adddress of UCapsuleComponent Subobject in CapsuleComp

RootComponent = CapsuleComp;  //*Assigning CapsuleComp as the RootComponent of the BasePawn

BaseMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Base Mesh"));

BaseMesh->SetupAttachment(CapsuleComp);  //*Setting Up the parent component for following transformation

Turret = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Turret"));

Turret->SetupAttachment(BaseMesh);

ProjectileSpawnPoint = CreateDefaultSubobject<USceneComponent>(TEXT("Projectile Spawn Point"));

ProjectileSpawnPoint->SetupAttachment(Turret);

}

void ABasePawn::RotateTurret(FVector LookAtTarget)

{

FVector ToTarget = LookAtTarget - Turret->GetComponentLocation();

FRotator TurretRotation = FRotator(0.f, ToTarget.Rotation().Yaw, 0.f);

Turret->SetWorldRotation(TurretRotation);

}

void ABasePawn::FireProjectile()

{

FVector ProjectileLocation = ProjectileSpawnPoint->GetComponentLocation();

FRotator ProjectileRotation = ProjectileSpawnPoint->GetComponentRotation();

auto Projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileClass, ProjectileLocation, ProjectileRotation);

Projectile->SetOwner(this);

}`

**Tank.h - **

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "BasePawn.h"
#include "Tank.generated.h"

/**
 * 
 */
UCLASS()
class TOONTANKS_API ATank : public ABasePawn
{
	GENERATED_BODY()
	
public:
	// Sets default values for this pawn's properties
	ATank();

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

	// Called every frame
	virtual void Tick(float DeltaTime) override;

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

private:

	UPROPERTY(VisibleAnywhere, Category = "Components")
	class USpringArmComponent* SpringArmComp = nullptr;

	UPROPERTY(VisibleAnywhere, Category = "Components")
	class UCameraComponent* CameraComp = nullptr;

	UPROPERTY(EditAnywhere, Category = "Movement")
	float Speed = 200.0f;

	void Move(float Value);
	void Turn(float Value);

	APlayerController* PlayerControllerRef = nullptr;
};

Tank.CPP:-

// Fill out your copyright notice in the Description page of Project Settings.


#include "Tank.h"
#include "Camera/CameraComponent.h"
#include "DrawDebugHelpers.h"
#include "GameFramework/SpringArmComponent.h"
#include "Kismet/GameplayStatics.h"

#define OUT

ATank::ATank()
{
    SpringArmComp = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
    SpringArmComp->SetupAttachment(RootComponent);

    CameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
    CameraComp->SetupAttachment(SpringArmComp);
}

// Called to bind functionality to input
void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

    PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &ATank::Move);
    PlayerInputComponent->BindAxis(TEXT("Turn"), this, &ATank::Turn);
    PlayerInputComponent->BindAction(TEXT("Fire"), IE_Pressed, this, &ATank::FireProjectile);
}

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

    PlayerControllerRef = Cast<APlayerController>(GetController());
}

void ATank::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    if (PlayerControllerRef)
    {
        FHitResult HitResult;
        PlayerControllerRef->GetHitResultUnderCursor(ECollisionChannel::ECC_Visibility, false, OUT HitResult);

        DrawDebugSphere(GetWorld(), HitResult.ImpactPoint, 10.f, 8, FColor::Red);
        
        RotateTurret(HitResult.ImpactPoint);
    }

}

void ATank::Move(float Value)
{
    FVector MoveOffset = FVector::ZeroVector;
    MoveOffset.X = Value * Speed * UGameplayStatics::GetWorldDeltaSeconds(this);
    AddActorLocalOffset(MoveOffset, true);
}

void ATank::Turn(float Value)
{
    FRotator TurnOffset = FRotator::ZeroRotator;
    TurnOffset.Yaw = Value * (Speed/3.5f) * UGameplayStatics::GetWorldDeltaSeconds(this);
    AddActorLocalRotation(TurnOffset, true);
}

Where are those Player Starts?

  • I also changed the location of the Player Starts many times, but still, have the same problem.

Your other screenshot showed two, where’s the other one?

Yes, I also noticed it. That is why now I have only one Player Starts in my project.

Does your issue persists if you change the game mode to Game Mode Base?

If I change my Game Mode to GameModeBase, then the default Pawn is spawning at the correct location.

And could you show your game mode code?

ToonTanksGameMode.h -

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "ToonTanksGameMode.generated.h"

/**
 * 
 */
UCLASS()
class TOONTANKS_API AToonTanksGameMode : public AGameModeBase
{
	GENERATED_BODY()
	
};

ToonTanksGameMode.cpp -

// Fill out your copyright notice in the Description page of Project Settings.


#include "ToonTanksGameMode.h"

I noticed something right now that, if in Default BP_PawnTank settings I set the Auto Possess Player to Player 0 it is working fine. Is it the correct way?

That shouldn’t be needed and is set to disabled in Stephen’s project.

Ok, And I replied you with the Game Mode Code. Did you see that?

Sorry I forgot to say I didn’t see anything wrong with that.

If you want you could send your project if you want? Though if everything is working with auto possess you could just continue and see how it goes?

Please send me the Google form link where I could send you my project. I really want to know what is causing this issue.

https://gdev.tv/projectupload

And please use File > Zip Project within Unreal so unneeded files are excluded.

I submitted my project.

I also tried to progress in the course by just possessing my tank, but in the Handling Pawn Death lecture, We need to use the ToonTanksGameMode.

For some reason the tank is offset. Re-creating the blueprint fixed it.

Re-Creating the game mode blueprint or the tank blueprint?

The tank