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
4
Question by dawsonsmythe · Mar 30, 2015 at 09:31 AM · materialanimated

After animating a custom material/shader parameter, how do I get an accurate value from script?

For example, I create a new shader with a Color parameter, then create a new material that uses that shader.

I assign that material to a new 3D object, and use an Animator (on another object) to animate that object's material's Color values. Hitting Play, I can see the object changing color correctly.

However, I have a component on the object where I just want to query the current animated color from the material. e.g.

void Update {

Debug.Log(GetComponent().material.GetColor("_Colour"));

Debug.Log(renderer.material.color);

Debug.Log(GetComponent().sharedMaterial.GetColor("_Colour"));

Debug.Log(renderer.sharedMaterial.color);

}

All of these only output the value that the Color attribute was BEFORE playing, not while the animation is live. How can I get the live animated value?

Comment
Add comment · Show 1
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 hicks · Jan 28, 2016 at 01:03 PM 0
Share

Same problem here. I can't find a way to get the actual color of that material, which gets correctly displayed by the editor.

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by hicks · Jan 28, 2016 at 05:38 PM

Just found an answer! I noticed a message in the inspector saying that a MaterialPropertyBlock is used to control the values. I guess the animator does that during playmode.

Reading from the property block solves this issue:

 MaterialPropertyBlock properties = new MaterialPropertyBlock();
 renderer.GetPropertyBlock(properties);
 Vector4 color = properties.GetVector("_Color");
 Debug.Log("color: " + color);
Comment
Add comment · 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 coolraiman · Jan 29, 2016 at 01:37 PM 0
Share

mark it as solved even if it is your own answer

avatar image Wanderer13 · Feb 23 at 04:40 PM 0
Share

Thanks! Used this in LateUpdate

avatar image
1

Answer by lassade · Jan 28, 2016 at 01:40 PM

Try use the LateUpdate event, it works the same way but gets called after the animations.

Check this out http://docs.unity3d.com/Manual/ExecutionOrder.html

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

Answer by LTPStudioXR · Mar 26, 2018 at 06:08 PM

Been wracking my brain trying to figure this out and scouring forums for this. Was trying to get the animation > animation.clip > animation.clip.property(curves, component, etc) so Thank You!

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

6 People are following this question.

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

Related Questions

Animated material 1 Answer

Material doesn't have a color property '_Color' 4 Answers

Changing two different objects renderer colour 1 Answer

Cubemaps disappearing from objects with identical material? 1 Answer

Video Tutorial - Dynamically Changing material on multiple objects 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