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
0
Question by Exalia · Sep 12, 2013 at 11:27 AM · shaderdestroyruntimerendereranti aliasing

Destroying and recreating renderers/shaders at runtime

Hi, I am having trouble with changing Anti Aliasing at run time and I would like to find a work around, I believe it has something to do with not destroying and recreating renderers at run time. I have managed to destroy the renderers at run time but recreating them is proving difficult at the moment.

Has anyone had experience or has an idea how I would be able to do this?

             renderers = (Renderer[])FindObjectsOfType(typeof(Renderer));
 
             foreach (Renderer renderer in renderers)
             {
                 if (renderer.sharedMaterial.mainTexture != null)
                 {
                     //Save Textures
                     //textureForMaterial[renderer.sharedMaterial] = renderer.sharedMaterial.mainTexture;
                     //Remove Textures
                     //renderer.sharedMaterial.mainTexture = null;
                     Renderer.Destroy(renderer);
                     //print(renderer.sharedMaterial.shader);
                     //Shader.DestroyImmediate(renderer.sharedMaterial.shader, true);
                 }
             }
Comment
Add comment · Show 10
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 Benproductions1 · Sep 14, 2013 at 12:32 PM 0
Share

What does AA have to do with destroying and creating renderers at runtime???
Also you should avoid using Instantiate. It's probably the most expensive function there is, so if you don't want something to render, simply disable the renderer :)

avatar image Exalia · Sep 14, 2013 at 12:46 PM 0
Share

What? Unless I'm misinformed when you change AA you destroy your glContext and create a new one with the parameters of AA. Renderers being used in that context are stored. When you create a new context you have to reapply the renderers to the objects. On a mobile device there isn't a lot of RA$$anonymous$$ so whereas on PC you can destroy the context and create a new one then reassign the renderers and textures, mobile devices will free the renderers from memory before creating the new context then struggle to reassign the renderers and therefore textures.

Hope that makes sense, I assume you're not familiar with mobile graphics hardware and stuff

avatar image Benproductions1 · Sep 15, 2013 at 02:00 AM 0
Share

You are correct, but I've never heard of anyone who destroyed and recreated all the mesh renderers. Are you sure Unity doesn't do that for you? It would honestly be quite sad if it didn't.

avatar image Exalia · Sep 16, 2013 at 04:36 AM 0
Share

Something goes wrong when AA is changed so either it's unity (this will fix the problem) or it's the GPU (The company I work at can work on fixing it)

avatar image whydoidoit · Sep 16, 2013 at 04:47 AM 0
Share

I switch AA on and off using QualitySettings at run time.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by Skydive · Sep 15, 2013 at 03:03 AM

Assuming you want to enable/disable it. Open up the AntiAliasaing.cs or js file and look for OnRenderImage(...) From at the top of the method simply add.

 if(PlayerPrefs.GetInt("AAEnabled") == 0)
 {
     Graphics.Blit (source, destination);
     return;
 }

I hope this information helps you. ;) Worth a shot I guess.

Comment
Add comment · Show 1 · 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
avatar image Exalia · Sep 16, 2013 at 04:38 AM 0
Share

I'll have to look up what this all does but thanks for the suggestion I'll let you know how it goes :)

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

18 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

Related Questions

Building a Unity 5 Standard Material at runtime 3 Answers

Unity 5.4 - SetVectorArray - how to read values back from MaterialPropertyBlock? 0 Answers

How to tell if a texture was generated at runtime? 1 Answer

How to find and assign Default-Particle material to a renderer 2 Answers

Is it better to destroy and instantiate or turn off mesh renderer? 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