Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Bigproblem01 · Feb 12, 2015 at 01:34 PM · gameobjectperformanceoptimizationalphaspriterenderer

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?

  1. Deactivating the gameObject

  2. Disabling Setting sprite renderer

  3. 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!

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Baste · Feb 12, 2015 at 03:03 PM 1
Share

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.

avatar image Bigproblem01 · Feb 12, 2015 at 03:36 PM 0
Share

hmm, thanks for the input Baste! Any other opinions?

avatar image Owen-Reynolds · Feb 12, 2015 at 04:17 PM 0
Share

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.

avatar image Bigproblem01 · Feb 13, 2015 at 09:25 AM 0
Share

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?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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);

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges