• 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
Question by s_guy · Jan 17, 2015 at 08:04 PM · shadermaterialruntimeseamlesspop

How do I change render.material at runtime seamlessly?

I have an enemy death effect that requires a different material. When I set the renderer.material to a new material (happens in an animation event callback), I get a few frames of nothing being rendered for the mesh before it reappears with the new material. I'd like it to be continuous, i.e. one render frame it's the old material and the next it's the new one.

Is there a solution or workaround? Am I just going about this the wrong way?

Comment
NirielNabokov

People who like this

1 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Owen-Reynolds · Jan 17, 2015 at 10:44 PM

I've swapped around plenty of materials, and never seen anything like that. Even if it was some sort of loading issue, there would be a frame drop - it wouldn't just run the game without things loaded. And even if it did, I think the object would be pink, not invisible.

My guess is it's a completely unrelated problem (but maybe triggered somehow by your changing the material, or not.)

Is there anything odd about the new material? Crazy custom shader with lots of moving vars? Does it happen with even a simple (diffuse blue) material?

Comment
s_guy

People who like this

1 Show 2 · 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 s_guy · Jan 17, 2015 at 11:21 PM 0
Share

It is a somewhat complex shader from a pack bought on the asset store. The problem doesn't happen with a simple diffuse shader. I don't know why I didn't think to try that. Thanks for the lead. I'll try to remember to update here if I find the specific issue.

avatar image s_guy · Jan 18, 2015 at 01:41 AM 0
Share

ANSWER: I was animating an alpha cutoff on the death material. Despite the material having a default opaque state and my animation curve starting at opaque, there was an animator state transition into the curve. It was interpolating between 0 and the starting value at frame 0 of the curve. I guess 0 is the default value for any float that is undefined in a previous animation state. I made the transition instant (no blending) and the frames of "nothing rendering" went away.

Seems obvious in hindsight...

avatar image

Answer by DaDonik · Jan 17, 2015 at 08:56 PM

My guess is that the texture belonging to the material you want to display is not already used somewhere else. Therefore Unity has to load the texture, which takes a while.

You could try to preload the material when you are starting the game/level. I would test it by simply assigning the material to a cube, placed offscreen where it's not seen by the player. That way the texture will already be loaded into memory and switching materials should be instant.

I haven't tried this, but it's not that complicated to do so =)

Comment

People who like this

0 Show 2 · 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 s_guy · Jan 17, 2015 at 09:44 PM 0
Share

It's a good guess, but that's not it. I made an item in the scene as you suggested (tried in the view too), with the death material permanently on it to verify.

avatar image DaDonik · Jan 17, 2015 at 09:47 PM 0
Share

Hmm thats strange. Sadly that was my best guess... Let's hope someone with more experience can shed some light on this.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

27 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Check What Material is Being Used? 1 Answer

How to update texture during runtime to display damage? 0 Answers

Building a Unity 5 Standard Material at runtime 3 Answers

Multi materials for one mesh 0 Answers

material Instance only updates after changes, when the Material Component is expanded or folded 0 Answers


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