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
1
Question by Josai · Apr 27, 2017 at 12:39 PM · arrayarraysarray of gameobjects

Dynamic Array Generation via Inspector

I have a problem and have no idea how to solve this issue. I want to have a lot of public GameObject arrays and the size of the arrays should be changeable with an integer. So I need an array of the public GameObject array. Hope you can help me with that

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 SohailBukhari · Apr 27, 2017 at 01:25 PM 0
Share

if you want to change the size on runtime then use lists ins$$anonymous$$d of arrays.

      public List<GameObject> Objects = new List<GameObject>();
 
 // you can find with tag or type and then add to list
  var gameObjectsWithTag = GameObject.FindGameObjectsWithTag("Objects");
         foreach (var item in gameObjectsWithTag)
         {
             Objects.Add(item);
         }


this list will be visible in inspector and add your GameObjects.

avatar image Josai SohailBukhari · Apr 30, 2017 at 01:21 PM 0
Share

It's not exactly what I need, I want an array that contains other arrays, and this should update in inspector while i'm not in play mode. Thanks for your hekp but i think I know, that I need to use the Editorscript for that.

avatar image SohailBukhari SohailBukhari · May 02, 2017 at 06:44 AM 1
Share

You can make arrays with in arrays using data classes.

 using UnityEngine;
 using System.Collections.Generic;
 public class ArrayContainerTest : $$anonymous$$onoBehaviour
 {
 
     public ArrayConytainer[] NewArrayConytainer;
 }
 [System.Serializable]
 public class ArrayConytainer
 {
     public List<GameObject> ObjectsList = new List<GameObject>();
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Apr 30, 2017 at 03:22 PM

You just want to use a simple serializable custom class. Like i mentioned in this answer over here. Just replace the string array with whatever you want.

edit

Here's an example:

 [System.Serializable]
 public class GameObjectArray
 {
     public GameObject[] objects;
 }
 
 public class YourComponent : MonoBehaviour
 {
     public GameObjectArray[] arrays;
     void Start()
     {
         for(int i = 0; i < arrays.Length; i++)
         {
             for(int n = 0; n < arrays[i].objects.Length; n++)
             {
                 Debug.Log("Pos: " + arrays[i].objects[n].transform.position;
             }
         }
     }
 }

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 Josai · Apr 30, 2017 at 06:46 PM 0
Share

I tried this, but it doesn't work with GameObject Arrays

I could create such an array as GameObject, but couldn't access the containing GameObjects

avatar image Bunny83 Josai · Apr 30, 2017 at 07:12 PM 0
Share

Of course it works. I added an example that does work for sure. The example iterates through all arrays and through all objects in each array and prints out the position of each object.

avatar image Josai Bunny83 · Apr 30, 2017 at 07:47 PM 0
Share

Oh well thanks I dunno what I did wrong today, now it works xD

Show more comments

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

Get all GameObjects by variable value 2 Answers

How to set parents of all objects in an array? 1 Answer

How many audio clip arrays are supported? 1 Answer

accessing gameObject script from an array 3 Answers

Passing an array to a function by reference? 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