- Home /
If a projector is told to Ignore all layers, is it effectively turned off?
Hey! I'm trying to increase performance here. The project at the moment includes a selection script (Drag and drop to select units) and to show that the unit is selected they have a ring around them, at the moment I am using a projector to do this.
Instead of adding and removing projectors all the time, is it worth just setting a projector to ignore ALL layers when its off and then set the layers to use when its on?
I'm guessing that if the projector doesn't have a layer to push out onto that it'll just turn itself off and save CPU, or am I wrong about that?
Cheers
Answer by skovacs1 · Oct 28, 2010 at 07:58 PM
I would say you're right, but I'm not 100% sure about the performance gain of masking all layers for a projector because that's fairly specific to the internals of the implementation of Projector. In theory masking all layers away should only cost the function calls to attempt projection and then to check the layers, depending upon the implementation Unity went with.
If you simply want to turn something off, why not just set active? Setting active does not destroy the object so you can still change it, but will stop any scripts on it and will cut the cost of rendering.
//Turn off projector.gameObject.active = false;
//Turn on projector.gameObject.active = true;
or for your specific case, you could disable just the Projector which will prevent it from projecting and should save you the cost of rendering/calculating the projections.
//Turn off (projector.GetComponent(Projector) as Projector).enabled = false;
//Turn on (projector.GetComponent(Projector) as Projector).enabled = true;
This is very true, I literally coded that in just a moment ago and it worked a charm! Thanks Skovacs1
Your answer
Follow this Question
Related Questions
Better Projector alternatives for object selection 0 Answers
How to render projector in front of walls but behind player? 1 Answer
Light or light projector? 0 Answers
Why is performance so slow in Unity 4.0? 0 Answers
Not a question - just some performance metrics for rendering from Unity scripts 0 Answers