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 xpavelos · Dec 27, 2015 at 11:05 AM · inspectormonobehaviourserializable

Is there a way to show Monobehaviours class properties inside another Monobehaviour class in the Unity inspector?

Hi all. Just as the title says - is there any equivalent to [System.Serializable] on Monobehaviour classes so I could put that into another class and its properties could be still editable in the inspector? Basically what I am trying to do is to be able to create mission objectives in the Unity inspector that may dynamically change during the game and this functionality could be very useful, but I am not sure if it's even possible.

So I have this MissionObjectives class (simplified) which derives from MonoBehaviour. I would like to put this class into another MonoBehaviour class and still be able to edit its serializable classes properties in the Unity inspector. Is it possible?

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System;
 
 public class MissionObjectives: MonoBehaviour
 {
     [Serializable]
     public class Objective
     {
         [Serializable]
         public class EntityToSpawn
         {
             public Entity entity_pref;
             public Transform spawnPosition;
         }
         
         public string objectiveDescription;
         public List<EntityToSpawn> entitiesToSpawn = new List<EntityToSpawn>();
         public List<Entity> entitiesToDestroy = new List<Entity>();
         
         public void StartObjective()
         {

         }
 
         public void UpdateObjective()
         {
 
         }
 
     }
     public List<Objective> objectives = new List<Objective>();
 
     void Start()
     {
         objectives[0].StartObjective ();
     }
 }
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
0

Answer by jmonasterio · Dec 28, 2015 at 04:18 PM

It's not super clear what you want because you wrote things like: 'put this class into another' and 'class properties inside another'. It's not exactly clear what you mean by this.

I think, though, you may want inheritance like:

 public class MissionObjectives: Objectives
  {
  // All properties/methods of MissionObjectives available in inspector, plus these extra ones defined below.

// In constructor you can set some default values, if you like public MissionObjective() { }

  }

and

 public class Objective : MonoBehaviour
 {
 // Your objectives class here.
 }

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 xpavelos · Dec 28, 2015 at 05:49 PM 0
Share

Thanks for your comment. But that's not the answer. Let's say I have a class:

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class $$anonymous$$bClass : $$anonymous$$onoBehaviour
 {
     [Serializable]
     public class AnotherClass
     {
         public float value1;
         public float value2;
     }
 
     public AnotherClass anotherClass;
     public float valueA;
     public float valueB;
 
 }

When I attach $$anonymous$$bClass to a GameObject in Unity, I will be able to set values in the Unity inspector of AnotherClass (which sits inside of $$anonymous$$bClass). I am able to do that thanks so Serializable attribute.

And now, my question is: Is it possible to put $$anonymous$$bClass into yet another class so that I can edit all of the values in the inspector. For example I would create $$anonymous$$bClass2 which will have a list of $$anonymous$$bClass classes, but I want to be able to edit all of the values of $$anonymous$$bClass in Unity Inspector.

In other words is there a [Serializable] attribute equivalent for $$anonymous$$onobehaviour classes?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Custom Display for system.object Editor 1 Answer

Select monobehaviour function from inspector 1 Answer

Logic Problems using for loops 0 Answers

Display Non Monobehaviour array in inspector C# 1 Answer

How can I determine if property was set to 'None (Audio Clip)' 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