Warning: Dumb Question. Why are we hitting the component?

We’re using FHitResult’s GetComponent() method to get the component that was hit, while GetActor() returns the actor that owns the component getting hit.

I feel embarrassed asking something that’s probably so obvious but, why are we hitting a component and not the actor? I thought a “component” was something like ‘OpenDoor’ and ‘PositionReport’ but we haven’t attached any components to the chair?

Is the “component” we’re hitting something that comes with “being a PhysicsBody”?

1 Like

I’ll answer your second question first:
Which component are we hitting and where does it come from???

The Actors we are interested in, the chair and the table both have StaticMeshComponents:
We didn’t attach those component, you are right about that. They came with the objects.

You need something like a StaticMeshComponent (more specifically a UPrimitiveComponent or a derived class, just like StaticMeshComponent) which contains the actual 3d geometry to make any collisions or physics happen. If you don’t have any 3d shape or form you obviously can’t collide with anything.
So can’t hit an Actor all by itself, it needs a UPrimitiveComponent for that! An Actor is more or less just a conatiner with a position in space, but with no form.

On to your first question:
Why are we using FHitResult::GetComponent() instead of FHitResult::GetActor() ?
Very simple: We’re using both of them anyways because we need them both!

We need a UPrimitiveComponent for PhysicsHandle->GrabComponentAtLocationWithRotation()

1 Like

I see, I’m glad I wasn’t mistaken on my interpretation of the word ‘component’, I just didn’t consider the other components automatically granted to our props (like the static mesh). Makes perfect sense, thanks!

1 Like

Thanks for this explanation that was bothering me as well.

Privacy & Terms