Is it possible to find the index of an instanced static mesh via its collider?

Is there any way to access the instance index of an instanced static mesh by means of the mesh’s collider? Specifically, I need to know which instance is being overlapped by another physics object.

On trace hit, you can get the index that that instance is stored in in the TArray which the engine creates in the background to store it.

This isn’t super handy if you’ve got multiple different types of meshes instanced though, because info about WHICH TArray that index is in is not exposed.

However…I was able to get around this by storing the world position of my instances, along with info about ‘what’ they are in a separate struct array. Then I compare the word position of the instance to the array to find a match and retrieve the info that way.

Obv that is not going to be super scalable if you are looking through thousands of records, but it works.

Could you please explain this in more detail? I cant see an array pin on the hit result if that is what you meant in the first paragraph? And how do you make a struct array that holds the positions of the instances?

I don’t know if there is a better way to do this in blueprint now, I solved it a few versions back. As you can see in the hit result, you can know what index the item is stored at internally, as well as the location via the “Get instance transform” function.

What I did, was when I would spawn an instance, I’d store it’s location in my own array along with data about what it is. Then, I could ‘look up’ info about it in my array by comparing it’s location to the locations stored in my array till I found a match. Essentially I’m doing a key-value pair thing by location.

If you simply want to know what ‘type’ of object it is though, then you don’t need to go to all that trouble you can just use the Hit Component to return the type.

22383-capture.jpg

Excellent thanks, but I cant seem to be able to create array variables, are they called something different in the variable type list? and what type of variable do you use to hold the positions of multiple objects?

You can actually see some more info about the item on the trace hit, so depending on your own use case you won’t need to rely on the method I’m using, the trace hit results may be more than enough info for what you are doing. In my case, I built a system to switch between instanced and ‘real’ versions of any given mesh so I needed to maintain my own array of custom info about each item.

Sorry I missed this when it was new! I am working with thousands of records but if you submit this as an answer I’ll be happy to accept.

This works for me in oncomponenthit, but it returns -1 if I do with oncomponentoverlap, could someone help me?

You just need to get hit component and cast to instanced static mesh component, you can then get index with get hit item.