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
0
Question by konsnos · Feb 02, 2015 at 01:14 PM · inspectorproperties

How to manually create property fields of a class

Hey all, here is my problem.

I have a class that I want to reference another base class say Class2 from which other classes will inherit. However I want to be able to dynamically add it to inspector without it being a MonoBehavior added to a GameObject. I want to take it from the project pane and assign it there.


If this isn't possible can I simply show the properties of a Type Class2? I could then save them to a text file and load them manually, while instantiating the class in game.

Thanks for reading.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by VesuvianPrime · Feb 02, 2015 at 02:11 PM

I suspect you want your Class2 to be a ScriptableObject http://docs.unity3d.com/ScriptReference/ScriptableObject.html

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 konsnos · Feb 02, 2015 at 04:37 PM 0
Share

@VesuvianPrime Hm, that's interesting. I didn't know that. I tried to use it but I failed. I'm not sure what I'm doing wrong.

I've made this code for the Editor script but it never creates an instance of the script. What I'm doing is assigning an object variable of the script and then checking its type and Creating an Instace from the ScriptableObject class.

Then again I may be doing something wrong. Haven't used ScriptableObjets ever.

 public override void OnInspectorGUI()
     {
         DrawDefaultInspector();
 
         if(class2 == null)
         {
             if(class2Object != null)
             {
                 System.Type type = class2Object.GetType();
                 class2 = ScriptableObject.CreateInstance(type) as Class2;
             }
         }
     }
avatar image konsnos · Feb 03, 2015 at 08:29 AM 0
Share

$$anonymous$$y algorirthm was wrong. I used an Object as a variable in inspector where I should use a $$anonymous$$onoScript. Seems to work so far.

avatar image
0

Answer by fafase · Feb 02, 2015 at 04:53 PM

Let' consider you have

 [System.Serializable]
 public class NonMono:ParentNonMono
 {
    [SerializeField]
    private bool dataBool;
    [SerializeField]
    private string dataString;
 }

then you can use:

 public class Test:MonoBehaviour{
    [SerializeField]
    NonMono nonMono = null;
 
    void Start(){
       nonMono = new NonMono(); 
    }
 }

This will show the member of nonData.

This is for the second case if you don't want to use ScriptableObject

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 konsnos · Feb 02, 2015 at 05:03 PM 0
Share

Can I declare in the Test the variable non$$anonymous$$ono as a ParentNon$$anonymous$$ono and assign a Non$$anonymous$$ono on it? I need to use inheritance to make my project work.

avatar image fafase · Feb 03, 2015 at 08:17 AM 0
Share

Yes you should. I suspect you need ot also set the parent as Serializable.

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

20 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

Related Questions

Material inspector, missing properties bug 1 Answer

Why does Unity3D encourage use of public variables instead of setters/getters? 1 Answer

How to Add Render Queue property in Inspector to LightWeight Shader ? 1 Answer

Custom Inspector. Aligning properties? 1 Answer

Project view script settings not being used 0 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