I’m trying to use the example code from OnActorBeginOverlap | Unreal Engine Documentation as a guide to figure out how to configure a component on my Actor to listen for other Actors to enter the overlap sphere attached to him. I made a test class, UAoETester.cpp/h, and I have the following in the cpp:
I expect this to print my debug message to the output console whenever a new actor enters the sphere, but I get two errors on compile, both from the line that begins OnActorBeginOverlap:
error C2065: ‘OnActorBeginOverlap’ : undeclared identifier
error C2228: left of ‘.__Internal_AddDynamic’ must have class/struct/union
I’m assuming this means that OnActorBeginOverlap isn’t recognized, but shouldn’t it be? My contextual fill-in doesn’t have it, it does have ENGINE_ReceiveActorBeginOverlap, but I assume that’s a different thing.
What do you have for includes in your header? If OnActorBeginOverlap doesn’t appear when you begin typing it, I would guess you are missing a required include.
but when I commented it out in my code to see, nothing happened. I have it included through other header files though, so I’d still give it a try if I were you.
Hmm, I gave it a try, but no dice- it got the same two errors as in the OP. That makes sense to me, though- unless I’m mistaken, isn’t OnActorBeginOverlap a delegate meant to intermediate between Actor and Component, so components can hear overlap events on their actor without being manually messaged?
Yea, I tried it with Actor.h included, and generated.h as the last include- for precision, let me paste the entire header file, it’s very rudimentary: just the extra include, and the function declaration:
#pragma once
#include "Components/ActorComponent.h"
#include "GameFramework/Actor.h"
#include "AoETester.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class CODEPROJ_API UAoETester : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UAoETester();
// Called when the game starts
virtual void BeginPlay() override;
// Called every frame
virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;
void OnOverlapBegin(class AActor* OtherActor);
};
I think I’m using the wrong tool here, re-reading OnActorBeginOverlap’s documentation confirms that it’s supposed to be run from an Actor, not a Component. I think what I need to do to make a component react to its actor’s overlap event is run this from the root character class, and add whatever override code I have in each specific component to the OnOverlapBegin delegate.
this is the right solution. Add a collision component to your actor, make sure you have the collision channels setup the way you want. Don’t trust the documentation too much, it is often wrong, incomplete or outdated, in my experience