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
2
Question by Dasky14 · May 30, 2018 at 07:25 AM · inspectorscriptableobjectrange

Public field Range() not working inside ScriptableObject

I made a sound class with ranges on values, but trying to make a data file out of them just ignores the range() attribute completely.

 [System.Serializable]
 public class Sound {
     public string name;
     public AudioClip clip;
 
     [Range(0f, 1f)]
     public float volume = 1f;
     [Range(0.5f, 1.5f)]
     public float pitch = 1f;
     [Range(0f, 1.5f)]
     public float randomVolume = 0f;
     [Range(0f, 1.5f)]
     public float randomPitch = 0f;
 }

and here is my tiny ScriptableObject:

 [CreateAssetMenu(fileName = "SoundData", menuName = "SoundData", order = 1)]
 public class SoundData : ScriptableObject {
     [SerializeField]
     public Sound[] sounds;
 }

What ends up happening is that I don't see the range slider at all. This used to work while I just had the data inside the audio manager instead of a scriptableobject. Object screenshot

Is there a way to fix this?

unity-2018-05-30-10-21-49.png (30.2 kB)
Comment
Add comment · Show 4
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 SohailBukhari · May 30, 2018 at 08:28 AM 0
Share

Your code is just fine its a unity bug.

avatar image Dasky14 · May 30, 2018 at 09:10 AM 0
Share

I'm not sure if I like the sound of that, but... thanks for the info!

avatar image Hellium · May 30, 2018 at 09:30 AM 0
Share

Are you sure you don't have any custom editor for Sound or SoundData?

avatar image Dasky14 Hellium · May 30, 2018 at 10:05 AM 0
Share

I have no custom editors, and looking at the sound element array when fetched into the Sound$$anonymous$$anager works just fine.

2 Replies

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

Answer by Bunny83 · May 30, 2018 at 10:27 AM

Sorry but i can't reproduce this problem.

SoundData

I've copied your exact code into my two test projects and it shows up like this. I've tested with Unity 2018.1.0b11 (beta version) as well as with my Unity 5.6.1f1 version. Both look like in the image i've posted.


You haven't mentioned your Unity version or if you have tried it in a new empty project. For me it works as it should. So there has to be something else which you did not mention. Any PropertyDrawers? Do you use Assembly Definition Files? Do you use namespaces? Are the two classes in seperate files or in the same? Does the filename of the scriptfile that contains the SoundData class match SoundData.cs? Do you use actual scriptfiles in your project or do you use pre-compiled assemblies?


sounddatascriptableobject.png (10.9 kB)
Comment
Add comment · Show 10 · 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 Dasky14 · May 30, 2018 at 11:01 AM 0
Share

I'm not an experienced Unity user. SoundData and Sound are in the same file (separating them did nothing), I haven't used PropertyDrawers or Assembly Definition Files, I don't use namespaces (I'm a rather new C# dev, basically my first personal project), and now the SoundData file is called SoundDataClass.cs. And I use actual script files made in the unity editor.

avatar image Dasky14 · May 30, 2018 at 11:11 AM 0
Share

Oh, and I'm using 2018.1.2f1

avatar image Hellium · May 30, 2018 at 12:04 PM 0
Share

SoundData should be defined in a file called SoundData.cs.

Because Sound is a plain C# class, you can define it in the same file as SoundData if you want, or in a file called Sound.cs

avatar image Adam-Mechtley Hellium · May 30, 2018 at 12:40 PM 0
Share

To add some context here: It is a quirk of Unity that $$anonymous$$onoBehaviour- and ScriptableObject-derived classes must be defined in a file with the same name as the class. It's pretty non-obvious in the UI, but the indicator here is the Script field that has nothing assigned. When it is done properly, it should have the $$anonymous$$onoScript asset that defines the class. Basically, Unity has created an object with the same serialization layout you have specified, but it doesn't actually know what it is.

avatar image Dasky14 Hellium · May 30, 2018 at 12:43 PM 0
Share

Defining it in SoundData.cs did nothing, and neither did defining Sound in Sound.cs or SoundData.cs.

avatar image Dasky14 Hellium · May 30, 2018 at 01:05 PM 0
Share

Never $$anonymous$$d, I had to recreate the data asset, then it worked. Thank you for the help. :)

avatar image Bunny83 · May 30, 2018 at 12:56 PM 0
Share

Ok, so for actually trying the provided classes in two different Unity versions, verifying that it does work as expected, providing a screenshot of the result i get a downvote? Well, i guess I take another break from answering questions... have a nice day debugging...

avatar image Hellium Bunny83 · May 30, 2018 at 01:09 PM 0
Share

Don't know who downvoted you and converted my comment to an answer, but your answer was the right one.

avatar image Adam-Mechtley Bunny83 · May 30, 2018 at 01:39 PM 1
Share

Sorry. I converted @Hellium's comment to an answer because I thought it made it easier to identify the specific solution to this problem, so future readers wouldn't have to look through the whole thread unnecessarily to find it.

It also looks like I accidentally down-voted this thread. I had up-voted it but then decided to up-vote the new answer ins$$anonymous$$d. I clicked down on this thread to cancel my up-vote ins$$anonymous$$d of re-clicking the up-vote to toggle it off. Sorry for the confusion.

avatar image Dasky14 Bunny83 · May 30, 2018 at 08:50 PM 0
Share

No idea who downvoted, but thanks for the help. Your answer was helpful. :)

avatar image
2

Answer by c8theino · Jun 16, 2020 at 10:48 AM

I found one possible reason why this could happen. It seems that if you have your Inspector in "Debug" mode, the sliders are not working. Change back to "Normal" mode and everything should work just fine.

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

90 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

Related Questions

[Range] attribute saves to undo-history too often. 1 Answer

Editing custom types in the inspector 1 Answer

Add AudioSource-Like Range to Script 1 Answer

Editor: How to save changes to a ScriptableObject loaded from Resources? 1 Answer

can't see property of asset created from scriptable object 2 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