New to UE4 and C++. I am trying to get some basic collision/proximity code working. I can see the ProxSphere in blueprint editor and the sphere is visible in the editing viewport. When I run the scene it logs out the “NPC INIT” message from the constructor, but I can’t seem to be able to get the Prox function to run when player character
enters the sphere.
NPC.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Character.h"
#include "NPC.generated.h"
UCLASS()
class GOLDENEGG_API ANPC : public ACharacter
{
GENERATED_BODY()
■■■■■:
// The sphere that the player can collide with to get item
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
USphereComponent* ProxSphere;
ANPC();
UFUNCTION()
void Prox(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
};
NPC.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "GoldenEgg.h"
#include "NPC.h"
#include "Avatar.h"
#include "MyHUD.h"
// Sets default values
ANPC::ANPC()
{
UE_LOG(LogTemp, Warning, TEXT("NPC INIT"));
ProxSphere = CreateDefaultSubobject<USphereComponent>(TEXT("Proximity Sphere"));
ProxSphere->InitSphereRadius(120.0f);
ProxSphere->AttachParent = RootComponent;
ProxSphere->OnComponentBeginOverlap.AddDynamic(this, &ANPC::Prox);
}
void ANPC::Prox(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
UE_LOG(LogTemp, Warning, TEXT("In Prox"));
}