Hi, thanks for reading!
Can you think of a way to have a custom UActorComponent which responds to collisions/overlaps detected by the parent actor, without touching the parent actor’s C++ code?
I want to be able to make a UActorComponent which is independent from the parent so that it can be attached to many kinds of actors. And for the UActorComponent to respond to overlap events of the parent actor.
At the moment I have experimented with coding an actor class which in its constructor makes a spherical component to detect collisions. If I can assume that the parent will have some collision mesh already, is there some way that a child actor component can respond to the same hit/overlap events?
-edit- A second idea, which I think might be better:
Instead, when attaching my UActorComponent to an actor, it creates a simple collision object, like a USphereComponent which can then do the collision detection. I’ve just tried this out by mostly copying the code I had from my actor class (described below) but can’t get the USphereComponent to attach to the actor component. I’m guessing that UActorComponents dont have a RootComponent in the same way that actors do.
Actor Constructor .cpp
USphereComponent* SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("RootComponent"));
RootComponent = SphereComponent;
SphereComponent->InitSphereRadius(40.0f);
SphereComponent->SetCollisionProfileName(TEXT("Actor"));
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AVolumeCollider::OnOverlapBegin);
UActorComponent Constructor .cpp
USphereComponent* SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("ActorComponentCollider"));
RootComponent = SphereComponent;
SphereComponent->InitSphereRadius(40.0f);
SphereComponent->SetCollisionProfileName(TEXT("Actor"));
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &UTestComponent::OnOverlapBegin);