Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 noonoox · Jul 23, 2017 at 04:50 PM · arrayprogrammingnot workinglinerenderergradient

alphaKeys in linerenderer gradient not being set

I'm using a gradient on a linerenderer, more specifically it's alpha, to make an effect of moving in and out of the ground. In theory this should work fine, but wherever I attempt to actually SET any kind of variable in the gradient, it doesn't work.

Renderer.colorGradient.alphaKeys[alphaPos].alpha = pos.z; (where alphaPos is which key to edit (out of 8. There will always be 8 in my circumstance, not that me setting it to have 8 does anything anyways)

Renderer.colorGradient.SetKeys(Renderer.colorGradient.colorKeys, newKeys), or Renderer.colorGradient.alphaKeys = newKeys (where newKeys is an array of the alphaGradientKeys) also do not work.

If I were to print pos.z and Renderer.colorGradient.alphaKeys[alphaPos].alpha, pos.z would be, say .5f, .7f, .100000003f, etc... the Renderer.colorGradient.alphaKeys[alphaPos].alpha would remain to be 1, and never be changed.

Edit: Making a new gradient and assigning it's alphaKeys, and then setting the colorGradient to that new gradient works, but even in that case I cannot manually set newGradient.alpha. This is troubling as I need this process to be as optimized as possible because this is happening many times per frame.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by TDZ · Mar 27, 2018 at 01:14 PM

 GradientAlphaKey[] alphakeys = new GradientAlphaKey[c.alphaKeys.Length];
  for (int j = 0; j < c.alphaKeys.Length; j++)
  {
        alphakeys[j] = new GradientAlphaKey(c.alphaKeys[j].alpha * _alphaPulse, c.alphaKeys[j].time);
  }
  c.SetKeys(c.colorKeys,alphakeys);
  _lineRenderers[i].colorGradient = c;

you just need to generate a brand new gradientalphakey and apply it instead of just changing the value in it.

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 Bunny83 · Mar 27, 2018 at 01:31 PM 1
Share

Don't this this: c.alpha$$anonymous$$eys[j]. Gradient.alpha$$anonymous$$eys is a property. Reading that property will create a new array every time you read it. You can simply do:

 Gradient c = lineRenderer.colorGradient;
 GradientAlpha$$anonymous$$ey[] alpha$$anonymous$$eys = c.alpha$$anonymous$$eys;
 for (int j = 0; j < alpha$$anonymous$$eys.Length; j++)
 {
     alpha$$anonymous$$eys[j].alpha = yourValue;
 }
 c.alpha$$anonymous$$eys = alpha$$anonymous$$eys;
 lineRenderer.colorGradient = c;
avatar image TDZ Bunny83 · Mar 27, 2018 at 01:44 PM 0
Share

Ah ya ofc, much better, thanks.

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

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

Related Questions

Multiple Cars not working 1 Answer

help! I can't get an array from another script 1 Answer

Listing multiple objects 2 Answers

Copy Childen Of GameObjects From Array 1 To Array 2 1 Answer

Index Out of Range Exception - can't figure it out 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