HOW to deal with ReplaceMaterial() lag (maybe parallel scripting?)

Hello all,

I have noticed the following: when I define a region3 on the terrain and call replacematerial(), then it takes sometimes a WHOLE SECOND for the material to change. There’s some built-in lag there - it happens no matter what.

Problem: I dont want the player to see the material change (as i cannot fade out fade in in this case with either tween or lerp or setting visibility, as far as i know). But if i check with raycast worldtoviewpoint then i do the check, call replacematerial() and the player turns their camera and BAM the material is replaced in full view.

How do i tell the function to…delay? yield? stop? the moment the point that is being changed is in view?

I’ve looked at coroutines, task.cancel, parallel scripting…but I have no clue how to set something like that up - that the condition is being continously checked DURING execution of ReplaceMaterial() and that execution stopped in time. Or if its even possible.

Thanks in advance to anyone who might be able to help

knijn