x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.18
Tags:
more ▼

asked Jan 22 '18 at 09:28 AM in Blueprint Scripting

avatar image

魔力嘿嘿嘿
1 2 2

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

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

alt text

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:

alt text

capture.png (58.0 kB)
capture2.png (112.9 kB)
more ▼

answered Jan 22 '18 at 09:45 AM

avatar image

Everynone
12.5k 71 24 51

avatar image 魔力嘿嘿嘿 Jan 22 '18 at 11:21 AM

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

avatar image Everynone Jan 22 '18 at 01:35 PM

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:

alt text

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

capture.png (111.4 kB)
avatar image 魔力嘿嘿嘿 Jan 23 '18 at 01:39 AM

Always output only the contents of index 0.

avatar image Everynone Jan 23 '18 at 08:47 AM

It works pretty well on my end with one correction: Section Index returns jumbled results (2 out of 6 indexes were swapped around [edit: that's because the LOD section is returned here - that's quite different from material element index] so I modified it slightly and now it seems to work correctly:

alt text


The material:

alt text

The end result:

https://gyazo.com/76caa9520464297062a61187146acb60 - -

If you can't get it to run, consider posting a screenshot of the tracing implementation against the floor. Perhaps you're not hitting the right thing? You can always print the name of the actor so make sure the trace fires as expected.

graph.png (236.9 kB)
mat.png (75.2 kB)
avatar image 魔力嘿嘿嘿 Jan 23 '18 at 09:01 AM

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

But just print 0. alt text

one.png (221.2 kB)
two.png (1.2 MB)
avatar image Everynone Jan 23 '18 at 09:09 AM

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?

avatar image 魔力嘿嘿嘿 Jan 23 '18 at 09:17 AM

Yes static mesh . alt text

three.png (331.5 kB)
avatar image 魔力嘿嘿嘿 Jan 23 '18 at 09:24 AM

Also,display name always print element 0 material name.

avatar image Everynone Jan 23 '18 at 09:29 AM

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.

avatar image 魔力嘿嘿嘿 Jan 23 '18 at 09:40 AM

HAHA . face index always print -1...

alt text

timg-1.jpg (9.8 kB)
avatar image 魔力嘿嘿嘿 Jan 23 '18 at 09:42 AM

What time is it now?

avatar image Everynone Jan 23 '18 at 09:46 AM

Hm, interesting, indeed. For me the FaceIndex is a bit more responsive than that:

https://gyazo.com/24fcc6d662e2babc8465990fbbda05c6

I'll try to investigate and post if I find something.

avatar image Everynone Jan 23 '18 at 09:50 AM

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

alt text

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.

capture.png (91.5 kB)
avatar image 魔力嘿嘿嘿 Jan 23 '18 at 10:48 AM

Thank you for your patience. But still not. alt text

aasss.png (110.7 kB)
avatar image 魔力嘿嘿嘿 Jan 23 '18 at 10:57 AM

First of all,face index always print -1
alt text

sfsf.png (86.6 kB)
avatar image Everynone Jan 23 '18 at 12:05 PM

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

alt text

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.

capture.png (44.2 kB)
avatar image 魔力嘿嘿嘿 Jan 24 '18 at 01:45 AM

Can you send me your test file for reference? My Email is 576435459@qq.com

avatar image 魔力嘿嘿嘿 Jan 24 '18 at 01:45 AM

I'm really troubled.

avatar image Everynone Jan 24 '18 at 10:01 AM

Sent you the project. Good luck!

avatar image Everynone Jan 24 '18 at 09:49 AM

Sure thing, I can send you the project. But one last thing, could you double check the material slot name and material name in your mesh - they need to be the same for this to work properly:

alt text

untitled.png (42.1 kB)
avatar image 魔力嘿嘿嘿 Jan 25 '18 at 03:36 AM

Thank you very much. 么么哒!~

(comments are locked)
10|2000 characters needed characters left

alt text

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.

more ▼

answered Jan 22 '18 at 11:30 AM

avatar image

魔力嘿嘿嘿
1 2 2

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question