- Home /
What drawback of frequently changing of Game Object's Layer?
I want to use Layers for ignoring specified Colliders before each Ray Cast (and Shape Casts, like Sphere, Capsule, et.c. Cast). I want to save Layers of ignored Collders before Ray Cast, set them Layers to zero (aka "No Layers"), perform Cast and then restore Layers of ignored Colliders from saved values.
.
The question is: is there any perforamce issues may take place when using such technique? As I understand, Layers are used in Ray Cast Broad Phase only (in PhysiX PreFilter, I think), not affecting heavy Quad Trees constructing algorithms - so this operation should be light weighted. Additionaly, Unity Layers documenetation have no warnings about frequent Layers changes... But I want to check my opinion.
.
I know that answer may be "just profile it, dude". I will do this if some perforamce issues will appeare (and put profiling results here). But if someone knows something about asked topic - it will be helpful for me and for everybody.
.
Thanks a lot for answerers.
Never prematurely optimise it and yeah... just profile it dude.