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 KAMyAw · Dec 30, 2015 at 07:27 AM · scripting probleminspectorpublic variable

Some Public Variables doesn't display in Inspector

Just like below, this is my script, it's very strange that the public variables can't all display in the inspector. It just displays "myScriptableObject" in the inspector but other public variables no matter what type and which it's serializable. How can I solve this problem?

     using UnityEngine;
     using System;
     using System.Collections;
     using System.Collections.Generic;
     
     public class AttributesControl : MonoBehaviour
     {
         public MyScriptableObjects myScriptableObject;
         public float randomMin;
         public float randomMax;
         public float attrMin;
         public float attrMax; 
     }
 



Comment
Add comment · Show 3
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 KAMyAw · Dec 30, 2015 at 11:03 AM 0
Share

$$anonymous$$y ScriptableObject just like this

 using UnityEngine;
 using System.Collections;
 using System;
 using System.Collections.Generic;
 
 [Serializable]
 public class $$anonymous$$aterialsObject : ScriptableObject {
 
     [Serializable]
     public class $$anonymous$$aterial : ScriptableObject
     {
         public int materialId;
         public string materialName;
         public int materialRarilty;
     }
 
     public List<$$anonymous$$aterial> materialList;
 }

Is this coding correct?

avatar image tanoshimi KAMyAw · Dec 30, 2015 at 11:41 AM 0
Share

That's not the definition of $$anonymous$$yScriptableObjects - that's the definition of $$anonymous$$aterialsObject...

avatar image KAMyAw tanoshimi · Dec 30, 2015 at 11:46 AM 0
Share

I know, I just change it here they're exactly correct in my project and I have built my project with no error sure I haven't use $$anonymous$$aterialsObject at all and the $$anonymous$$yScriptableObject is exactly the same as $$anonymous$$aterialsObject. And now the inspector can display the public instance but no public variables.

2 Replies

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

Answer by Bunny83 · Dec 30, 2015 at 12:17 PM

The ScriptableObject class is used to create seperate assets which aren't gameobjects. If you declare a variable to a ScriptableObject you can only assign a ScriptableObject asset to that variable. Just like any other asset reference. ScriptableObjects have to be created explicitly in the editor and they can be edited seperately. Also ScriptableObjects have a similar restriction as MonoBehaviour classes. They also need to be placed in their own script file and have their filenames match the classname.

To me it looks like you actually don't want to use ScriptableObjects here. Just use serializable classes:

 [Serializable]
 public class MaterialsObject
 {
     [Serializable]
     public class Material
     {
         public int materialId;
         public string materialName;
         public int materialRarilty;
     }
     public List<Material> materialList;
 }

While it's possible to call your own class "Material" it will just cause problems with Unitys Material class.

Comment
Add comment · Show 3 · 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 KAMyAw · Dec 30, 2015 at 12:50 PM 0
Share

Understood, but why I can't see any variables in the inspector? Looks like I removed all scripts and scriptableobjects then make a new script only includes one line code "public int test" and the default codes, it neither displays public variables at all.......I have no idea why this happens.......PS: I found something just now and looked like it will be useful, anyway, thanks a lot, man

avatar image Bunny83 KAMyAw · Dec 30, 2015 at 02:26 PM 0
Share

As i said, ScriptableObjects are standalone assets. You will only see a reference field when you create a variable of your ScriptableObject type. Unity also doesn't create an instance automatically for you like it does for "normal" serializable classes. You don't see the variables just like you don't see the variables of a different $$anonymous$$onoBehaviour script. Example:

 public class SomeClass : $$anonymous$$onoBehaviour
 {
     public int someInt;
     public string someText;
 }
 
 public class Test : $$anonymous$$onoBehaviour
 {
     public SomeClass other;
 }

Here when you attach the Test class to a gameobject, you won't see the "someInt" and someText variables in the Test class. You only see a reference field called "other" where you can link an instance of the "SomeClass" class. The variables of that instance can only be viewed, when you inspect the SomeClass instance directly. ScriptableObjects work exactly the same way, but they are not components attached to gameobjects. They are used to store information as a seperate asset file in your project. When you select such an asset, you can view and edit it's variables.

Unitys TerrainData class is the only classic example of a ScriptableObject in use. Though its serialized variables are hidden on purpose since you shouldn't edit that data directly.

Here's a great introduction to ScriptableObjects but it's a bit lengthy.

As i said ScriptableObjects are mainly used for storing data as assets. Unity has even added the CreateAsset$$anonymous$$enuAttribute to simplify the creation of an asset. ScriptableObjects always have to be created explicitly

avatar image KAMyAw Bunny83 · Dec 31, 2015 at 12:44 AM 0
Share

Thank you for your answer, easy to me to understand. I have found out where the problem is. Anyway, thanks!

avatar image
0

Answer by rajan4uto · Dec 30, 2015 at 09:34 AM

I think there are error in other script on same project. Just check it once. If yes then correct it then after you can see in inspector.

Comment
Add comment · Show 1 · 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 KAMyAw · Dec 30, 2015 at 10:12 AM 0
Share

but have built project with no error......

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to prevent the value in the Inspector from overriding the value in a script? 4 Answers

Display the same string in multiple text boxes 1 Answer

Best way to defining scripts within a list inside the editor? 1 Answer

Setting color with a public enum and displaying the change in editor? 1 Answer

How can I make the Random.Range in this spawning script a PUBLIC adjustable variable? The (0, 35) code limit gives errors when I need the prefab list to fluctuate. An example code would help. Thanks! 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