Reputation: 2407
Is there any performance concern around calling MyAlreadyActiveGameObject.SetActive(true)
a ton, e.g., once per frame?
Put another way, is it ever worth pulling a gameObject.active
check upwards? Or caching/checking an _alreadyActive
?
Upvotes: 11
Views: 10435
Reputation: 73
If you are concerned about this, you could always do a basic if-check on the same line.
if(!myObject.activeSelf) myObject.SetActive(true);
Upvotes: 2
Reputation: 11452
When in doubt, try the simple thing first and see if it works. Sometimes it's worth focusing on optimization, but you should check if it's necessary effort. Unity's built-in profiling tools can give you an estimate on how long each operation is taking in each frame.
Is there any performance concern around calling
MyAlreadyActiveGameObject.SetActive(true)
a ton, e.g., once per frame?
It does take time, but not much. If you're doing this hundreds or thousands of times per frame, it might be worth worrying about. Up until then, the concern should be negligible.
If you are worried about performance for a large number of objects, you can look into pausing expensive behaviors for objects which are far away, out of view, etc.
Upvotes: 0