I’m pretty new at working in Unreal (and c++ has never been my strongpoint) and I was wondering how to go about taking an inputted object from an engine function, and determining if that object’s class is a specific subclass that I have defined.
Take for example the onHit member function from the example first-person shooter project.
void AExampleProjectile::OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
// Only add impulse and destroy projectile if we hit a physics
if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL) && OtherComp->IsSimulatingPhysics())
{
OtherComp->AddImpulseAtLocation(GetVelocity() * 100.0f, GetActorLocation());
//Check if OtherActor is an instance of my subclass ASpecialWallMesh
//If so, call subclass' member function ::doStuff
Destroy();
}
}
This seems like a pretty essential piece of knowledge for starting out on extending any unreal classes, so I’m surprised I couldn’t find any useful information about it. I experimented with using dynamic_cast but the documentation on how to use it wasn’t very helpful for the Unreal context and I kept running into ‘invalid target type for dynamic_cast’, so I’m pretty sure I don’t know what I’m doing with it.