Trace material ID

There’s an actor that may have several material instances of the same parent material. These instances may also have different parameter values. When I’m tracing against this actor, how can I know, which material ID was hit? HitInfo.Material somehow references the parent material instead of the instance set in runtime.

I don’t know of any way to do that directly. But could you give the actor a way of remembering its material instance when it gets set? Then do a

TraceActor = Trace(HitLocation, HitNormal, End);
if(MyActor(TraceActor) != none)
    MaterialInstance = MyActor(TraceActor).TheMaterialInstanceISetEarlier;

Anyway, that’s the workaround I would try if there’s no way to get the material instance directly.

It remembers them, but Trace’s HitInfo ignores instances for some reason and just outputs default materials. If it worked correctly, I could make a workaround with ScalarParameters telling which instance is which.

Yeah, that’s why I didn’t use HitInfo.Material. Because it’s not going to return the material instance, just the parent material. So we ask the actor itself which material instance it saved in that variable. Did I not understand your question? Maybe if we knew what you were using this for we could help you with a workaround.

Do you mean that this actor has several materials on it at the same time? (And you just happen to cover the actor’s mesh with instances of the same parent material.) And you want to know which of those was traced to? If you can’t get that info from HitInfo, maybe you could find out which of the actor’s bones was hit on the trace. And then give the actor a function where you can tell it “I’m looking at this bone. Can you tell me which material instance is on it?” That wouldn’t be ideal if the materials don’t line up perfectly with the bones, but it might be good enough.

The mesh is a part of level geometry. Some of it’s materials have bMagnetic variable in PhysMatProperty. I couldn’t find a way to toggle variables of PhysMatProperty that way it only applied to a single actor and a single material on it. So, I simply added an array of structures that remember IDs and states of these magnetic materials. Like, 0 is on and 2 is off. Too bad trace doesn’t works as I expected.

The easiest solution is to separate meshes to smaller parts that include only one magnetic material.