So after getting an AI Controller set up in C++ I wanted to create a “Food” pickup that when the AI hits refills their hunger. The problem is the collision does not want to work. I have turned the generate hit event on for both actors. Checked to make sure the nav mesh let the AI touch the food object, but I can’t for the life of me get it to work. Here is a sample of my code.
Character class .h
#pragma once
#include "GameFramework/Character.h"
#include "Slime.generated.h"
UCLASS()
class XENOSLIME_API ASlime : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
ASlime();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
UPROPERTY(EditAnywhere, Category = Behavior)
class UBehaviorTree* slimeBehavior;
UPROPERTY(EditAnywhere)
float hunger;
void OnHit(AActor* other, UPrimitiveComponent* otherComp, FVector NormalImpulse, const FHitResult& ASlime::OnHit);
};
Character Class .cpp
this->GetCapsuleComponent()->OnComponentHit.AddDynamic(this, &ASlime::OnHit);
void ASlime::OnHit(AActor* other, UPrimitiveComponent* otherComp, FVector NormalImpulse, const FHitResult &Hit)
{
if(other)
{
hunger += 50.0f;
Destroy();
}
}
the if-statement is just place holder just to test functionality. I would greatly appreciate some help on this problem. Also I’m using OnHit instead of OnBeginOverlap/OnEndOverlap because the AI will be able to interact with the pickups in other ways.
Thank you,
Russ.