Follow the previous recipe to get an understanding of casting an Actor
pointer to an Interface pointer.
Note
Note that as this recipe relies on the casting technique used in the previous recipe, it will only work with objects that implement the interface using C++ rather than Blueprint. This is because Blueprint classes are not available at compile time, and so, technically, don't inherit the interface.
Create a new
Actor
class using the editor wizard. Call itAntiGravityVolume
.Add
BoxComponent
to the newActor
.UPROPERTY() UBoxComponent* CollisionComponent;
Override the following
Actor
virtual
functions in the header:virtual void NotifyActorBeginOverlap(AActor* OtherActor) override; virtual void NotifyActorEndOverlap(AActor* OtherActor) override;
Create an implementation within your source file, as follows:
voidAAntiGravityVolume::NotifyActorBeginOverlap(AActor* OtherActor) { IGravityObject* GravityObject = Cast<IGravityObject>...