- Home /
Which is better performance-wise?
Hi guys,
If I have a sprite renderer and I want it to disappear.
Which way would be better performance-wise?
Deactivating the gameObject
Disabling Setting sprite renderer
Making sprite renderer's alpha 0
Those sprite's don't have any colliders or scripts so I don't care about interactivity etc. I'm asking because I vaguely remember someone stating that setting gameObject as active/inactive is not good for performance but I can't search for this info, that's why I'm asking here.
As a bonus to your answer, could you also point me to the place where I could find out similar information? Unity's manual is not a very good source for that and when I need to know what's the most optimal way to go, I have no answer (unless I already learned it somehow by asking around).
Thanks a bunch!
Not quite sure here, but I would definitely avoid 3, as any scripts you have in the scene does not know what alpha 0 means, and you might end up with an invisible object affecting other things.
You also have situations with fallback shaders - if your user is running an old graphics card that doesn't support whatever shader your sprite renderer's using, it might fall back to a different shader that doesn't support transparency on alpha, and the "invisible" sprite would suddenly be visible.
Disabling the sprite renderer is probably faster than disabling the game object, but unless you're doing this very often (like every frame), it shouldn't be a difference you can measure.
hmm, thanks for the input Baste! Any other opinions?
If it really bothers you, just make 10,000 sprites, add a button that randomly spawns 10$$anonymous$$ more when clicked, and try both methods.
But, in practice, it comes down to other coding issues. Probably one way or the other will be easier with the rest of your program.
So none of them is noticeably faster or slower than the other? is there any place online where all these functions in Unity are somehow sorted by performance or something like this?
Answer by ChrPunx · Feb 12, 2015 at 04:23 PM
float prcent = \\transparence, value must be between 0 and 1 ... (min/max) = ?
\\ (20 / 60) = 0.3
GetComponent<SpriteRenderer>().color = new Color(prcent, prcent, prcent, 1);
Your answer
Follow this Question
Related Questions
Are .gameObject and .transform both using GetComponent() in the background? 1 Answer
Merging together all GameObjects of an Array? 1 Answer
Sprite Alpha Performance 0 Answers
Optimize huge number of Destroy() calls (cannot use object pooling) 3 Answers
Calling gameobject.transform vs. just calling transform directly - Performance negligible? 1 Answer