Dipping effect at runtime (dynamic alpha channel) - How would you do this?

Hi folks,
this is what I want to achive:
I want an animated mesh changing its material for those parts that go below a certain level (e.g. a Z value) or intersec with another mesh/volume. Both ways would work for me. Then, when going up again (or leaving the intersection), all changed parts should stay changed. Its like dipping a stick into a bucket of paint. Once a part was painted it will never go back.

What I tried:
In the material editor I can get the absolute world position, filter it by Z axis and pan a half-half (upper half white, lower half black) alpha mask texture. The mask is then used to lerp between two textures With this, the material can change for all parts that undergo a certain level and it works at runtime too. Now comes the tricky part. The changed parts mustn’t change back when the mesh rises again. Therefore I want to access the alpha mask to store it and merge it with the new alpha mask after a change of position has occured. Please see the blueprint. The problem is that I was not able to figure out how to access the result of “Blend_Darken” if this is even possible.

What might be a better idea:
Also, I thought about using vertex painting at runtime but I’ve read that it is not possible at runtime.

What are your thoughts on this problem?

Thanks,
Gaussman

You can do it by using either blueprint or C++. On each tick, calculate the difference between the object’s Z and the “paint” surface Z and if it’s smaller than the previous frame value, store it in a variable and pass that value to the material as a parameter to use to do the masking.

@manoelneto: I’m not sure if I got your idea correctly. It’s not just about saving a Z-Value, because if I lift the object out of the paint, its alpha mask must be frozen so I can then move and rotate the object in all dimensions. Then, when dunking in the paint again, it must be possible that other parts of the object get painted too, regardless what was painted first.