TT Spawn particles crash when I try to delete 2nd Health inPawnturret&tankfiles

Sure

#include "TankGameModeBase.h"
#include "ToonTanks/Pawns/PawnsTank.h"
#include "ToonTanks/Pawns/PawnTurret.h"
#include "Kismet/GameplayStatics.h"
#include "ToonTanks/PlayerControllers/PlayerControllerBase.h"

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

    HandleGameStart();
}

void ATankGameModeBase::ActorDied(AActor* DeadActor)
{
    if (DeadActor == PlayerTank)
    {
        PlayerTank->HandleDestruction();
        HandleGameOver(false);

        if(PlayerControllerRef)
        {
            PlayerControllerRef->SetPlayerEnabledState(false);
        }
    }
    else if(APawnTurret* DestroyedTurret = Cast<APawnTurret>(DeadActor))
    {
        DestroyedTurret->HandleDestruction();

        if(--TargetTurrets == 0)
        {
            HandleGameOver(true);
        }
    }
}

void ATankGameModeBase::HandleGameStart()
{
    TargetTurrets = GetTargetTurretCount();
    PlayerTank = Cast<APawnsTank>(UGameplayStatics::GetPlayerPawn(this, 0));
    PlayerControllerRef = Cast<APlayerControllerBase>(UGameplayStatics::GetPlayerController(this, 0));
    
    GameStart();
    if(PlayerControllerRef)
    {
        PlayerControllerRef->SetPlayerEnabledState(false);

        FTimerHandle PlayerEnableHandle;
        FTimerDelegate PlayerEnableDelegate = FTimerDelegate::CreateUObject(PlayerControllerRef, 
            &APlayerControllerBase::SetPlayerEnabledState, true);
        GetWorld()->GetTimerManager().SetTimer(PlayerEnableHandle, PlayerEnableDelegate, StartDelay, false);
    }
}

void ATankGameModeBase::HandleGameOver(bool PlayerWon)
{
    GameOver(PlayerWon);
}

int32 ATankGameModeBase::GetTargetTurretCount()
{
    TArray<AActor*> TurretActors; 
    UGameplayStatics::GetAllActorsOfClass(GetWorld(), APawnTurret::StaticClass(), TurretActors);
    return TurretActors.Num();
}

Probably should have also asked for the PlayerControllerBase.cpp as well, sorry. Could you show that?

sure

#include "PlayerControllerBase.h"




void APlayerControllerBase::SetPlayerEnabledState(bool SetPlayerEnabled)
{
    if (SetPlayerEnabled)
    {
        GetPawn()->EnableInput(this);
    }
    else
    {
        GetPawn()->DisableInput(this);
    }
    bShowMouseCursor = SetPlayerEnabled;

}

Is line 11 of the PlayerControllerBase this?

GetPawn()->EnableInput(this);

Well that is implying GetPawn is returning nullptr which is odd. Or maybe it’s an old build and you previously did GetOwner by mistake (suggesting as more than one person did that)?

Could you try rebuilding?

How should I rebuild it sorry

Sorry I thought that was covered. In VS Code with Unreal closed

Ctrl + Shift + B > ProjectNameEditor Platform Development Rebuild.

Where platform is the platform you’re building for e.g. Win64. Be sure to choose the editor version.

1 Like

I do that and it only brings up C/C++: cl.exe build active file. I can’t search for any others

Are you sure you have the workspace open?

image

Yeah I’m pretty sure Although I may have opened it differently

Doesn’t look like it. You should have

As well as the .code-workspace which I forgot to highlight. Do you not have that in your project directory?

I think I managed to turn it into a workspace
Capture

Well I see that you have a solution file. So if you open the solution in Community you can rebuild through that via Build > Rebuild.

Ok right I’ll give it a go.

Visual studio community?

Double click the .sln file i n File Explorer.

oh ok

Alright, I rebuilt the .sln file

And?

Here is the log sorry for taking so long

1>------ Skipped Rebuild All: Project: UE4, Configuration: BuiltWithUnrealBuildTool Win32 ------
1>Project not selected to build for this solution configuration 
2>------ Rebuild All started: Project: ToonTanks, Configuration: Development_Editor x64 ------
2>Cleaning ToonTanksEditor and UnrealHeaderTool binaries...
2>Creating makefile for ToonTanksEditor (no existing makefile)
2>Parsing headers for ToonTanksEditor
2>  Running UnrealHeaderTool "D:\C_Unreal_course\ToonTanks_4.25\ToonTanks\ToonTanks.uproject" "D:\C_Unreal_course\ToonTanks_4.25\ToonTanks\Intermediate\Build\Win64\ToonTanksEditor\Development\ToonTanksEditor.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -abslog="C:\Users\Windows 10\AppData\Local\UnrealBuildTool\Log_UHT.txt" -installed
2>Reflection code generated for ToonTanksEditor in 6.3809528 seconds
2>Building ToonTanksEditor...
2>Using Visual Studio 2019 14.27.29112 toolchain (C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110) and Windows 10.0.18362.0 SDK (C:\Program Files (x86)\Windows Kits\10).
2>Building 21 actions with 4 processes...
2>  [1/21] Default.rc2
2>  [2/21] SharedPCH.Engine.ShadowErrors.cpp
2>  [3/21] ProjectileBase.cpp
2>  [4/21] HealthComponent.cpp
2>  [5/21] PawnBase.cpp
2>  [6/21] TankGameModeBase.cpp
2>  [7/21] PlayerControllerBase.cpp
2>  [8/21] PawnsTank.cpp
2>  [9/21] HealthComponent.gen.cpp
2>  [10/21] PawnTurret.cpp
2>  [11/21] PawnsTank.gen.cpp
2>  [12/21] PawnTurret.gen.cpp
2>  [13/21] PlayerControllerBase.gen.cpp
2>  [14/21] ProjectileBase.gen.cpp
2>  [15/21] ToonTanks.cpp
2>  [16/21] ToonTanks.init.gen.cpp
2>  [17/21] PawnBase.gen.cpp
2>  [18/21] TankGameModeBase.gen.cpp
2>  [19/21] UE4Editor-ToonTanks.lib
2>     Creating library D:\C_Unreal_course\ToonTanks_4.25\ToonTanks\Intermediate\Build\Win64\UE4Editor\Development\ToonTanks\UE4Editor-ToonTanks.lib and object D:\C_Unreal_course\ToonTanks_4.25\ToonTanks\Intermediate\Build\Win64\UE4Editor\Development\ToonTanks\UE4Editor-ToonTanks.exp
2>  [20/21] UE4Editor-ToonTanks.dll
2>     Creating library D:\C_Unreal_course\ToonTanks_4.25\ToonTanks\Intermediate\Build\Win64\UE4Editor\Development\ToonTanks\UE4Editor-ToonTanks.suppressed.lib and object D:\C_Unreal_course\ToonTanks_4.25\ToonTanks\Intermediate\Build\Win64\UE4Editor\Development\ToonTanks\UE4Editor-ToonTanks.suppressed.exp
2>  [21/21] ToonTanksEditor.target
2>Total time in Parallel executor: 32.48 seconds
2>Total execution time: 55.14 seconds
========== Rebuild All: 1 succeeded, 0 failed, 1 skipped ==========

I then tried to play the game and it still crashed

It is probably the same as this

Privacy & Terms