# Change Material of a mesh with mouse click event in runtime with blueprint

**URL:** <https://forums.unrealengine.com/t/change-material-of-a-mesh-with-mouse-click-event-in-runtime-with-blueprint/310217>\
**Category:** Rendering\
**Tags:** unreal-engine, mouse-click, Blueprint, question\
**Created:** [March 9, 2015, 11:28pm UTC](https://forums.unrealengine.com/t/change-material-of-a-mesh-with-mouse-click-event-in-runtime-with-blueprint/310217 "2015-03-09T23:28:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_ab1ea73f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ab1ea73f](https://forums.unrealengine.com/u/anonymous_user_ab1ea73f)\
**Post date:** [March 9, 2015, 11:28pm UTC](https://forums.unrealengine.com/t/change-material-of-a-mesh-with-mouse-click-event-in-runtime-with-blueprint/310217/1 "2015-03-09T23:28:02Z")

</div>

Hi guys, I need to do something very specific and I don’t know how, so if you be so kind to help me, i will be very grateful.  
I need a blueprint to assign to several actors (meshes) a property to change material with a mouse click over it. For example a Wood Wall change to a Concrete wall doing click over the mesh.  
The second that I need for the same meshes is show a specific text in HUD when the mouse pass over the specific mesh, with “mouseover” property. At the same time, when the cursor (crosshair) is passing over the mesh, change the drawing of the crosshair for something like “finger” or “clickable”.  
The meshes are six in total.

Thank you again, and I hope you can help me

greetings!

Héctor

---

<div class="post-metadata">

**Author:** ![MarcAndreG](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MarcAndreG](https://forums.unrealengine.com/u/MarcAndreG)\
**Post date:** [March 9, 2015, 11:45pm UTC](https://forums.unrealengine.com/t/change-material-of-a-mesh-with-mouse-click-event-in-runtime-with-blueprint/310217/2 "2015-03-09T23:45:40Z")

</div>

Hi g0mo,

this should give you a great starting point

I created a variable click Id that will loop from 0 to 2. [0,1,2,0,1,2,0, etc], then I set a material on the current static mesh to the associated material created in the array.

Just be sure to set the correct material in your default variables

Cheers,

 ![33377-clickchangematerial.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/c/d/1cd034d4023584a273019a9d9c2a0cd1d0ca6524.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ab1ea73f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ab1ea73f](https://forums.unrealengine.com/u/anonymous_user_ab1ea73f)\
**Post date:** [March 9, 2015, 11:55pm UTC](https://forums.unrealengine.com/t/change-material-of-a-mesh-with-mouse-click-event-in-runtime-with-blueprint/310217/3 "2015-03-09T23:55:39Z")

</div>

Thank you MarcAndreG, i will check and try to make it. Did you do it on Character Blueprint or in a new BluePrint?  
If I have some new question i will ask you again 🙂

Thanks!

---

<div class="post-metadata">

**Author:** ![MarcAndreG](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MarcAndreG](https://forums.unrealengine.com/u/MarcAndreG)\
**Post date:** [March 9, 2015, 11:59pm UTC](https://forums.unrealengine.com/t/change-material-of-a-mesh-with-mouse-click-event-in-runtime-with-blueprint/310217/4 "2015-03-09T23:59:51Z")

</div>

Sure do not hesitate if you have any questions.

This was on a new blueprint assumed to be the blueprint on which you want to click and have the material change.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ab1ea73f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ab1ea73f](https://forums.unrealengine.com/u/anonymous_user_ab1ea73f)\
**Post date:** [March 10, 2015, 12:07am UTC](https://forums.unrealengine.com/t/change-material-of-a-mesh-with-mouse-click-event-in-runtime-with-blueprint/310217/5 "2015-03-10T00:07:31Z")

</div>

Thanks for your good willingness.

Ok, so I will follow your steps.

In the blueprint appears “Material 1” “Material 2”, etc. How do you add it in the blueprint?

what kind of action is the “Click id” and “Material” node?

This Blueprint works alone or with another?

Cheers!

---

<div class="post-metadata">

**Author:** ![MarcAndreG](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MarcAndreG](https://forums.unrealengine.com/u/MarcAndreG)\
**Post date:** [March 10, 2015, 2:05am UTC](https://forums.unrealengine.com/t/change-material-of-a-mesh-with-mouse-click-event-in-runtime-with-blueprint/310217/6 "2015-03-10T02:05:39Z")

</div>

If you’re not sure how to add variable to a blueprint, I think the first step would be to go watch a few tutorial to get the hang of it.

If you’ve never touched UE4 / blueprints, the Unreal has great tutorial series too that I’d recommend watching

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

Here’s one made by someone(aka not unreal) that seems to teach how to handle mouse click and touch events. It’s probably with a previous version of the engine but it still will get you some insight.

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/c/c/5cc734bb4a6ee26f42000d8ce4ca6b70090bb61c.jpeg "UE4 Blueprint Mouse Click and Touch Events | UE4 Blueprint Tutorial by Devin Sherry") ](https://www.youtube.com/watch?v=eddauM-nP4U)

Cheers,

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ab1ea73f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ab1ea73f](https://forums.unrealengine.com/u/anonymous_user_ab1ea73f)\
**Post date:** [March 12, 2015, 3:01am UTC](https://forums.unrealengine.com/t/change-material-of-a-mesh-with-mouse-click-event-in-runtime-with-blueprint/310217/7 "2015-03-12T03:01:45Z")

</div>

Hi MarcAndreG, I watched all the videos and now I understand the concept of variable and how can I create it, but I still having doubts about a lot of things.

The first thing that I’m trying to do is change the mouse cursor image (a custom image) when pass over a specific mesh. I know that I have to intervene 3 differents blueprint: Mouse\_Controller, HUD and Mesh Blueprint (seeing how do I built my demo).

In the Mouse\_Controller BluePrint I created two variables: “Mouse Pointer Image” (change the image of cursor) and “Shift Mesh” (variable that represent the mesh that makes the mouse’s cursor changes when it’s over it).

And two Events: “Begin Mouse Over” and “End Mouse Over”.

Basing on my low knowledge I think (in logical terms) would be like:

1.- Mouse pass over the mesh (Event happen)

2.- The Mouse Cursor change its image.

Following this, I connect “Begin Cursor Over” with “Set Mesh” with “Mouse Pointer Image”, but I receive an error: “Literal values are not allowed for array parameters”

I understand that I’m connecting nodes from different nature between them, but I don’t know how connect them or what conversor node have to use.

 ![33767-blueprint_mouse_controller.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/0/a/50aed635aa6ea4ca549ded057f7f306bbadc71a0.png)

In HUD BluePrint, apparently everything its ok.

 ![33769-blueprint_hud.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/8/2/4827e92fd73d95275184b1b8ba3a3f406e0e1cd5.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ab1ea73f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ab1ea73f](https://forums.unrealengine.com/u/anonymous_user_ab1ea73f)\
**Post date:** [August 12, 2017, 4:34pm UTC](https://forums.unrealengine.com/t/change-material-of-a-mesh-with-mouse-click-event-in-runtime-with-blueprint/310217/8 "2017-08-12T16:34:41Z")

</div>

Well finaly i did this to make the material change. I post it if someone need to know how to do it. Is very simple.

Cheers!

 ![204271-character.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/6/7/66785d714d9c31df4794f05a025522b7f2ee4974.jpeg)
