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 TSCSimulation_AH · May 15, 2019 at 10:56 AM · mecanimfloatattributemax

Use Another Float Value As Range Attribute's Max Value

Hi guys,

I want to use a float value to define the max range of the Range attribute.

For example,

 float a = 4.0f;
 [Range(0.1f, a)]
 public float b;

Is this possible?

Thanks!

Comment
Add comment · Show 2
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 Magso · May 15, 2019 at 12:34 PM -1
Share

Yes it is, are you getting errors?

avatar image TSCSimulation_AH Magso · May 15, 2019 at 12:59 PM 0
Share

Hi, yeah I am: CS0120. It's saying An object reference is required for the non-static field.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kim-Nobre · May 15, 2019 at 03:50 PM

You can do this by using the "const" keyword in the "a" field.

  const float a = 4.0f;
  [Range(0.1f, a)]
  public float b;
Comment
Add comment · Show 4 · 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 TSCSimulation_AH · May 16, 2019 at 07:39 AM 0
Share

Hi, I tried this and it's compiled, but its removed the fields in the Inspector. I've tired to serialise it, to no avail. Any ideas?

avatar image Bonfire-Boy · May 16, 2019 at 10:50 AM 1
Share

I think there's an implication in the question that the OP wants to be able to change the allowed range. Otherwise... why bother?

$$anonymous$$aking the range depend on a const just changes where a fixed range is defined, doesn't make it adaptive in any way at all.

@TSCSimulation_AH I wouldn't have thought it possible to do what I'm assu$$anonymous$$g that you're asking for without writing your own editor code. But should be quite possible in a custom editor or property drawer.

avatar image TSCSimulation_AH Bonfire-Boy · May 17, 2019 at 07:41 AM 0
Share

Hi, yeah, I wanted to just make it so that the range of one float could never be higher than the other, so if I set a to be 400 b could only ever be 0 - 400, for example, as I've got $$anonymous$$/max logic elsewhere. It's just a nice to have for the rest of the $$anonymous$$m so mistakes aren't made so easily, if it's not possible, it's not the end of the world.

avatar image Bonfire-Boy TSCSimulation_AH · May 17, 2019 at 09:34 AM 0
Share

Like I said, I'm sure it is possible by writing your own editor. I've not done this specifically, by have done similar things such as making the options in an inspector dropdown for an asset be deter$$anonymous$$ed by the contents of an array in another asset. If you're up to speed on writing basic property drawers and inspectors then my guess is that what you're asking for would be pretty straightforward. Possibly the fiddliest bit would be dealing with the situation where things get broken (eg you'd need to think about what you want to happen when the range-deter$$anonymous$$ing variable gets changed to something that means the range-limited variable is now out of range - do you allow that? do you automatically clamp the range-limited variable? do you need to message the user that these kind of things have happened? and so on)

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

116 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 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

Random float parameter for idle animations 1 Answer

[mecanim] conditions for float are < or > but no == 1 Answer

Is there a limit to how large a position value can go? 1 Answer

mecanim keep feet planted 0 Answers

How do I fix this lerp this float so it doesnt snap from animation to another 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