How do you select a static mesh element by clicking the left mouse button in the running mode?

How do you select a static mesh material element by clicking the left mouse button in the running mode?
I want to click on the model to get the material element of clicks to change the texture.

A bit confused here regarding whether you want to obtain the material or static mesh reference. The topic and description mention both. Generally you’d go about it like this:

  • enable Click Events in the controller
  • ensure Static Meshes have collision enabled (works fine with default settings)
  • use Static Meshes’ onClicked event to Get/Set Material

227909-capture.png

Alternatively, you could trace from mouse position and project it to 3d world, check what you hit, change its material

And yet another way is to use the GetHitResultUnderCursorForObjects node:

Thank you very much! But I want to get Element Index by clicking.

This ground is a Mesh, But there are four kinds of materials, I want to click the corresponding position with the left mouse button, get the corresponding Material Element Index.

This ground is a Mesh, But there are
four kinds of materials, I want to
click the corresponding position with
the left mouse button, get the
corresponding Material Element Index.

Got it. I misunderstood you initially, my bad. You will need to use Complex Tracing (the tick box in the trace node) for this:

The last node up here will produce both - material slot index and the material slot name (GetDisplayName).

Always output only the contents of index 0.

(post deleted by author)

1 Like

This is my blueprint.

But just print 0.

This is my blueprint.And I just want to identify the static object instead of the blueprint.

But just print 0.

And that (pretty!) chair has more than 1 material element?

When you say:

[…] And I just want to identify the
static object instead of the
blueprint.

What do you mean by β€œstatic object”? Static mesh name?

Also, instead of the SectionIndex, could you try printing the DisplayName of the ReturnValue from the node Get Material From Collision Face Index?

Yes static mesh .

Also,display name always print element 0 material name.

Cool, so at least we’re can see the element 0 name. So we know the tracing is working.

Could you please test one more thing then? Could try printing the Face Index directly from Break Hit Result node and see what kind of numbers you’re getting there.

HAHA . face index always print -1…

228113-timg-1.jpg

What time is it now?

(post deleted by author)

I think I got it, open your mesh and enable per poly collision:

Also, I just found out why my numbers where jumbled up initially. I mistook the LOD section for material index. There, I learnt something today.

Thank you for your patience.
But still not.

First of all,face index always print -1

Not sure. Perhaps you could explain how your actor is constructed:

228131-capture.png

It seems to be more than just an actor with a static mesh component. Maybe you could test it with another actor. As simple a setup as it gets.