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 ForgeStudios · Mar 28, 2015 at 11:46 AM · c#arrayorganization

C# declaring an array of transform arrays

I'm looking to make an array of array of transforms that can be accessed from the unity editor window, how would I go about doing that? I tried using jagged arrays but they cannot be accessed through the editor window. I'm trying to do this to organize and categorize my items for a procedural generation script.

Comment
Add comment · Show 2
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 MakakWasTaken · Mar 28, 2015 at 12:30 PM 1
Share

Try this:

 [Serializable]
 public class TransformClass {
     public Transform this;
     public Transform[] transform;
 }
 
 public TransformClass[] transforms;

avatar image hexagonius · Mar 28, 2015 at 12:47 PM 0
Share

You can Serialize an array of a serializable struct containing another array. Should give you the array of arrays you want

1 Reply

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

Answer by lordlycastle · Mar 28, 2015 at 02:28 PM

If it’s just for use in Unity Editor, you could just create multiple public variable of arrays for different “category”, and they will show up as in categories. Otherwise you can create a Serializable class which contains a array variable, as pointed out by @MakakWasTaken in the comment above. Although, I would recommend that you not use array in C# because they are immutable i.e. cannot change it’s value after initialisation. Try to use Lists they are more handy.

 using System.Collections.Generic;
 
 [Serializable]
 public class Category {
     public List<Transform> items = new List<Transform>();
 }
 
 public List<Category> categories = new List<Category>();
 
 //To get object the format will be following
 
 var someTransform = categories[2].items[1];
 var otherTransform = categories[0].items.Find(someOtherTrasnform);

However, I would not recommend using this at all because this really isn’t that useful way to organise your data. I don’t know if you plan to use it, but if it's just for the Editor then I would recommend that you invest in an asset called Advanced Inspector it’ll help solve inspector display problems.

Comment
Add comment · 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 ForgeStudios · Mar 28, 2015 at 03:04 PM 0
Share

Hello, thank you for your answer, but I'm still having troubles with the serializable flag:

 [Serializable]

Unity refuses to recognize it, is there a library I need to call to get it working? Here is an excerpt of my code as it stands

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 [Serializable]
 public class TransformArray{
     public Transform[] arrayObject;
     
     public TransformArray(Transform[] _ao){
         arrayObject = _ao;
     }
 }
 
 public class buildingObject : $$anonymous$$onoBehaviour {
     public TransformArray[] longTransformArray;
         //The rest of my code...

avatar image fafase · Mar 28, 2015 at 03:19 PM 0
Share

When you get this kind of issue and you do not know where the class/atrribute comes from, right click on it then Resolve, it will add it. In your case it is System.

avatar image MakakWasTaken · Mar 28, 2015 at 03:23 PM 0
Share

As @lordlycastle said I think it might be better to use a List ins$$anonymous$$d so you can use .Add to add transforms at runtime, then if you need it as an array for a reference you can simply call

 Transform[] someArray = longTransformArray.arrayObject.ToArray();
avatar image ForgeStudios · Mar 28, 2015 at 07:15 PM 0
Share

@fafase Thank you, that did it! I used the resolve command in Unity's monodevelope interface, for future reference of anyone who has the problem all it does is add this to the code: using System;

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

23 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

C# Set Current Array GameObject to Active 1 Answer

How to check for an empty array? 1 Answer

Deleting an Element from an Array. 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