How to 'Cast To' a component type

I am sure this is pretty simple but how do you get the type of component from a Hit Result?

I have a BP with a load of Box Collision Components in it. When my line trace hits a particular Box Collision in the BP it I want to do stuff/disable the collision on the box that is hit

When I draw a node off the component hit result I assume I need to cast to the the box collision class but I do not that it as an option, is there another way?

I believe what you want to do is to cast the hit component directly (cast the blue pin to a component class), not its class (purple pin).

UMyComponentClass* CastComponent = Cast<UMyComponentClass>(HitComponent);
if (IsValid(CastComponent)) {
  // The hit component is of type UMyComponentClass and valid, so do stuff.
  CastComponent->DoYourCollisionMethod();
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.