Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 UyenLam_LNW · May 06 at 10:13 AM · array of gameobjects

Is it possible to drag multiple copies of one object into an array?

I know how to drag multiple objects, but I need to drag several copies of one object. I don't think it's possible but I figured I should just ask. Does anyone have any insight on this?

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 Caeser_21 · May 06 at 12:50 PM 0
Share

Do you mean through the inspector?

avatar image MickyX · May 06 at 02:08 PM 0
Share

Can you clarify what you mean by several copies of one object?

If you duplicate one object to create a "copy" the copy is still its own object which can be added to an array.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by swanne · May 06 at 04:04 PM

You can drag the same object into an array multiple times, if that's what you are asking? This will just create an array of N x object01, which has no benefit over an array with 1 x object01.

However, if you are doing something like adding 3 different objects into an array and want the probability of any one surfacing at random more than the others, then you can drag one instance of 2 objects in and drag the 3rd one in multiple times. You could end up with an array of 10 objects which will look like:
0: object01
1: object02
2: object03
3: object03
4: object03
5: object03
6: object03
7: object03
8: object03
9: object03

Comment
Add comment · 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
0

Answer by UyenLam_LNW · May 06 at 04:10 PM

Hi yes to clarify I do mean through the inspector.

@swanne I have a prefab object in one of my project asset folders and I need several of it in an array in the inspector -- however I don't want to make copies of it in the scene.

So it would be 0: prefab 1 1: prefab 2 2: prefab 3 3: prefab 3 4: prefab 3 5: prefab 3 6: prefab 3 (etc)

Comment
Add comment · Show 6 · 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 Caeser_21 · May 06 at 04:14 PM 0
Share

Can you not just add the same object into the array again and again? Or as a shortcut just add it once and just keep clicking the 'Plus' Icon

avatar image UyenLam_LNW Caeser_21 · May 06 at 04:59 PM 0
Share

I could, but I need to add about 60 copies, so I wondered if there was a quicker way, but I don't think there is for the particular object type we're using.

avatar image swanne · May 06 at 04:17 PM 0
Share

Cool. Just drag the prefab instance into the array multiple times then.

avatar image UyenLam_LNW swanne · May 06 at 05:01 PM 0
Share

I did end up doing that, but it was like 60 copies so it was a hell of a hassle.

avatar image Caeser_21 UyenLam_LNW · May 06 at 05:12 PM 0
Share

I'm pretty sure that is the only if you want no copies in the actual game scene...

Show more comments
avatar image
0

Answer by MickyX · May 06 at 05:24 PM

FYI adding the prefab from assets into an array in the inspector 60 times while technically you can do it what it means is that you are actually creating 60 references to the same prefab and not any gameobjects, any changes done on that prefab will filter to all other objects in the list and the prefab will be changed. Its like editing the prefab directly.

If that is the behaviour you want then yes just drag it 60 times. Otherwise you need to instantiate the prefab to create the copies

 //Put your prefab here
     public GameObject prefabGO;
 
     //This will hold all the copies
     public GameObject[] gameObjectArray;
 
     //The number of copies you want set in inspector
     public int numOfCopies;
 
     void Start()
     {
         gameObjectArray = new GameObject[numOfCopies];
         for (int i = 0; i < numOfCopies; i++)
         {
             gameObjectArray[i] = Instantiate(prefabGO);
         }
     }
Comment
Add comment · 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

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

138 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 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 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 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 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 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

Public Array of GameObjects 2 Answers

Array values changing after gameObject is instantiated from prefab 1 Answer

How to create an array of prefabs with a specific script attached 3 Answers

Instantiating a prefabs from an array of prefabs gives a NullReferenceException error 1 Answer

Using an int to find the index of a GameObject 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