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"

Per Instance Id For Static Mesh Instances


I'd like to access the unique instance Id of each static mesh instance.. is there a way to do this? This would be similar to the value passed in via the SV_InstanceId semantic.

Is there a way to do this? I've tried adding a custom HLSL node to my function, but it doesn't look like the instance id is avaliable in the generated function.

Cheers! Andy

Product Version: UE 4.12
more ▼

asked Aug 02 '16 at 06:42 AM in Rendering

avatar image

23 6 9 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Hello, hidsmurf2000,

You can retrieve the index of a given static mesh by using the "Hit Item" output pin (int) from a hit result. Then you can use that to get the particular properties of that instance (such as its transform) after you have casted to the InstancedStaticMesh class from the hit actor.

See this tutorial for details: https://youtu.be/F_RS1vlBYXI?t=822

Also, if you are talking about accessing the index from within the material, there is a material node that will get a random number out of the instance index and that will help you to randomize your looks a bit.

See this answer: https://answers.unrealengine.com/questions/280115/is-it-possible-to-use-instanced-material-on-instan.html

As for passing parameters to the material instance of a particular instanced mesh, remember that they are all the same draw call and are sharing the same material, so you would be affecting them all.

more ▼

answered Aug 02 '16 at 10:54 AM

avatar image

586 13 10 34

avatar image kidsmurf2000 Aug 02 '16 at 11:02 AM

Thanks Diego, yes I'm after an instance id in the material. The random number isn't quite enough for me, as I need to specifically lookup data on a per-instance basis - for example storing the color of each instance in a texture and then looking up a color per-instance (which cannot be random).

avatar image Diego_Visualma Aug 02 '16 at 09:15 PM

As far as I know there is no way to do this yet. If they are offering us a node to get a random number seeded by the instance index, I don't see why we shouldn't be able to access the instance index directly. It is stored on the gpu, right? Wouldn't need to be additional draw calls? But the node isn't there.

Depending on your use case, you could maybe hack something out using worldPosition, and using only it's x,y components so you know where you are in a plane.

If your instances possible positions can be divided into a grid, and that grid's measures are known, then you could know if your world position is in a given repetition of that distance, so in a given grid number.

avatar image Diego_Visualma Aug 02 '16 at 11:33 PM

Come to think of it, wouldn't the actor position node give you the information necessary to do this check too?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Is there a solution to this problem? I have the same problem.

more ▼

answered May 16 '18 at 06:16 AM

avatar image


(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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