Change static mesh to other object with UMG button

Hello I am still new in using the Unreal Engine. I start my project with the shooter starter content. After follow a tutorial, I am able to change the static mesh object to another by shooting. This is the blueprint how I set.

I want to change the current static mesh object to another by using the UMG button and this is my blueprint.

But the button is not working. I know the “cast to destructive wall” need an object reference. In the event hit, the “other” pin will detect whether the object hit is same as the object references cast to. In the UMG button, What should I do to detect and get all the object match to the “cast to destructive wall”? How to change the static mesh to another by only click a button? Really appreciate if get any help or advice!

In the first two images, you know that your projectile is actually hitting something, and therefore the Event Hit is triggered.

In this case, where you want to change a static mesh of some actor, the widget doesn’t know what actor to change the static mesh on, unless you tell it. You can create a new variable on the widget, and make it of type DestructiveWall (you actually don’t need to cast then, as the variable knows what type it is), then on the button click, you’d change the static mesh of your referenced actor. Here’s a simple blueprint to show what I mean:

I’ve marked the interesting things with orange. You’re welcome to ask any questions regarding this solution, and I’ll do my best to answer them :slight_smile:

Hi, thank you for your reply. I followed exactly to the tips you give but it doesn’t work :frowning: Is there any mistake on the actor? I am really sure the button can function (tried with set the visibility of button).

Do you set the reference variable? Please take an image of the blueprint where you add the widget to the viewport.

This is the blueprint of the widget where I put my button.

I already set the reference variable as below.

260845-8.png

I tried to figure out the problem of the blueprint with color image. This is the widget and the blueprint.

If the set static mesh return a false boolean, the image color at top of the gameplay will change to green. I also set the static mesh to movable. Why the set static mesh always return false?

I tried to figure out the problem of the blueprint with color image. This is the widget and the blueprint.

If the set static mesh return a false boolean, the image color at top of the gameplay will change to green. I also set the static mesh to movable. Why the set static mesh always return false and the object did not change to new mesh?

I figured out why my button doesn’t work. Because the object reference did not specify which object is want to change (it is possible to have many same objects). After the object is defined as an array index ‘0’, the static mesh can be set!

If you expose this variable on spawn (3rd checkbox in the variable details), you can set the variable whenever you spawn the widget