Can you add interface event to a static mesh?

I have a door blueprint, which contains a door frame, the door itself, and a button that will open the door when clicked.

I’v created an interaction interface and I setup ray tracing in the players class, so that it will send an interact message to anything that the player interacts with.

My issue is that I can’t figure out how to add the interact event from the interface to the static mesh. I can add it to the blueprint class itself, but not the button static mesh.

If you want the static mesh component to be directly responsible for handling the interact event then you’ll need to extend the StaticMeshComponent class into your own blueprint.

Once you’ve done that you can implement the interaction interface into your new class and setup the interact event’s code.

Personally I would just allow the blueprint that contains the mesh component to implement the interface and handle the event. Once the blueprint gets the event you can make whatever changes you need to the mesh.

How will I tell if it was the button that the user interacted with and not just the entire door if I had the event on the blueprint?

Your trace interaction should have a HitResult object that contains some useful information including
the specific component that was hit on an object.

If you look at the link below you’ll see a “Hit Component” as part of the Break Hit Result. If you pass the Hit Result or just the Hit Component through the event to the blueprint it can check to see if that hit component was the button.

Ok, so I am accepting an Actor in the interface, and I pass in the hit component.

How do I compare the hit component to the static mesh?

Currently, I cast the hit component to a static mesh component, but the compare doesn’t come out true when it should be. Also, when I print the display names of both the variables, they come out different. Even though they are the same objects.

You shouldn’t need to cast the Hit component to a static mesh component. The hit component is a Primitive component which the button (static mesh component) is a child class of.

Can I see a screenshot of the blueprint code for the interface and the blueprint that is handling the comparison?

It prints the following :
Door_1202.StaticMesh door_pad Door_1202.Pad door_pad

I thought I uploaded the picture. Here it is again :

It seems that both variables have the same name, but one is a StaticMesh and the other is a Pad (Which is the name of the static mesh).

The interface just has a function called Interact that takes an Actor Component variable.

So Pad is the static mesh (button)?

What are you passing into the Hit Result parameter from the Interact interface? The hit component or the actual hit result?

Can I see the code that handles the interact event being sent?

Hit component is being passed into the hit result

Yes, the pad is the static mesh button

In the interface, the HitResult parameter is of type Actor Component.

But, what was being printed out was this :
Door_1202.StaticMesh door_pad Door_1202.Pad door_pad

Which I assume are both door_pad variables, right? They both are named door_pad. Maybe I am reading it incorrectly? (The one on the left is what was clicked (Which I assume is the pad, judging by the name), the one on the right is the actual static mesh pad.

Also, when I click the door frame, it’s prints out a different variable.

I have a feeling that both are the correct variables, but they are maybe just different classes? Not being casted correctly for comparison?

Objects doesn’t need to be cast to the same version in order to succeed. As long as they are the same object they can be held as any parent/child version.

I’m seeing…

Door_1202.StaticMesh door_pad

and

Door_1202.Pad door_pad

That tells me they are different, and both are a part of door_pad. Check the display name in the detail panel.

I’m guessing that the component being hit and returned is not the pad. It’s the door mesh. You said the display name was the same in your code above, but what you posted in a previous comment seems to have a difference between the two names.

If the Trace is indeed hitting the door and not the pad then the door’s collision is covering the pad’s collision. Try fixing this if possible.

If not then I’d recommend going with my original suggestion of extending atatic mesh component to your own class and implementing the interface. Then adding it to the door’s blueprint.