#Resolved: AuraAIController - NULL on bHitReacting

21 messages · Page 1 of 1 (latest)

faint ore
#

Section 14 of the GAS Topdown Course

Crashing when the bHitReactTagChanged is triggered which relies on AuraAIController which is returning a nullptr.

Slightly confused about what is wrong here as have been through and triple checked everything, even found a few things I missed but nothing resolves this. Maybe its meant to be like this at this point?

Heres some screenshots of the debug..

faint ore
static dagger
#

Can you surround your hit react setting in a check

#
  if (AuraAIController && AuraAIController->GetBlackboardComponent()) {
    AuraAIController->GetBlackboardComponent()->SetValueAsBool(FName("HitReacting"), bHitReacting);
  }
#

The AI Controllers should onlly be active on the server so if your client finds its way here, it will be null

faint ore
#

Morning, lets see. Current HitReactTagChanged function

{
    bHitReacting = NewCount > 0;
    GetCharacterMovement()->MaxWalkSpeed = bHitReacting ? 0.f : BaseWalkSpeed;
    AuraAIController->GetBlackboardComponent()->SetValueAsBool(FName("HitReacting"), bHitReacting);
}```
#

Changed to

{
    bHitReacting = NewCount > 0;
    GetCharacterMovement()->MaxWalkSpeed = bHitReacting ? 0.f : BaseWalkSpeed;
    if (AuraAIController && AuraAIController->GetBlackboardComponent())
    {
        AuraAIController->GetBlackboardComponent->SetValueAsBool(FName("HitReacting"), bHitReacting);
    }
}```
#

That fails to build with error
AuraEnemy.cpp(136): [C2227] left of '->SetValueAsBool' must point to class/struct/union/generic type

#

I am going to add a check for AuraAIComponent != nullptr within an if statement

#

Okay, that fixed it weirdly enough (not weird, just that I didn't think it was that simple but it was 5am admittedly).

#

🙂

#
{
    if (AuraAIController != nullptr)
    {
        bHitReacting = NewCount > 0;
        GetCharacterMovement()->MaxWalkSpeed = bHitReacting ? 0.f : BaseWalkSpeed;
        AuraAIController->GetBlackboardComponent()->SetValueAsBool(FName("HitReacting"), bHitReacting);
    }
}```
#

Tested in Listen Mode & Client Mode (dedi) with multiplayer to be working also.

wheat sapphire
# faint ore ```void AAuraEnemy::HitReactTagChanged(const FGameplayTag CallbackTag, int32 New...

The correct code would be:

bHitReacting = NewCount > 0;
GetCharacterMovement()->MaxWalkSpeed = bHitReacting ? 0.f : BaseWalkSpeed;
if (AuraAIController && AuraAIController->GetBlackboardComponent())
{
    AuraAIController->GetBlackboardComponent()->SetValueAsBool(FName("HitReacting"), bHitReacting);
}

The first 2 lines are not suppose to be inside the if statement.
Also, just to clarify. This check is important because the AIController will only exist in the server. In the Client, it will be nullptr. But we still want to change the other 2 variables

faint ore
#

I can remove the first two lines from the IF statement, that makes sense to me anyway .

#

On closer inspection I get it. It’s checking if AuraAIController and if GetBlackboardComponent is true valid

wheat sapphire
faint ore
#

Thanks for clarifying, my nullptr check does work also and not had any adverse effects yet of having those 2 lines inside the if statement but I have moved them out now.

static dagger
faint ore