• 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
Question by Jep · Sep 27, 2012 at 10:09 PM · inspectorarraysbuiltin

Builtin Array of different data types to Inspector?

Hello Unity Community!

I'm trying to build a simple inspector tool that involves duplication of multiple data types at the click of a button. So for example I need:

String

GameObject

Int


In the Inspector for ease of editing. So essentially I will be able to change the size of the array in editor and keep adding Data Blocks of Strings, GameObjects and Ints to my hearts desire.

I'm wondering how to go about this. I tried to be smart by scripting a builtin array of ArrayLists but of-course that failed miserably.

Any help will be greatly appreciated!

Comment
honor0102

People who like this

1 Show 0
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
Best Answer

Answer by Loius · Sep 28, 2012 at 01:08 AM

Create a new class, use that:

 class Multitype {
   var x : int;
   var y : String;
   var z : GameObject;
 }
 
 var things : Multitype[];
Comment
shaderop
Zmeyk
honor0102

People who like this

3 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 Jep · Sep 28, 2012 at 01:31 AM 0
Share

Ahh! A class. Thanks a Million! Exactly what I needed. +1 Louis. You've helped greatly!

avatar image pixartist · Mar 20, 2013 at 06:33 PM 0
Share

This doesn't seem to work with c#

avatar image fafase · Mar 20, 2013 at 07:17 PM 0
Share

Maybe because c# requires the MonoBehaviour inheritance to use the GameObject. Also you might have to make it public as it is private by default. Finally if you only have few items like in the example, you might want to use a struct considering you know the whole value/reference type thing to use it appropriately.

avatar image robertbu · Mar 20, 2013 at 07:28 PM 3
Share

Here is the @Loius's example in C#.

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class Multitype {
   public int x;
   public string y;
   public GameObject z; 
 }
 
 public class Demo : MonoBehaviour {
     public Multitype[] things;
     
     void Start () {
     
     }
     
     void Update () {
     
     }
 }

Note for C# you need the [System.Serializable] and you need to make the class and any variables you want available in the inspector explicitly public.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

Implementing a 2D array as a field on a ScriptableObject? 1 Answer

Inspector overring array. 1 Answer

Custom Construct Arrays in the Editor - can I control the name of the element? 0 Answers

Writing Jagged Arrays 1 Answer

Adding variables to inspector strings 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