• 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 benbendixon · Sep 01, 2015 at 06:49 PM · gameobjectinstantiatearrayarraysspawning

Cannot find the length of an array

Hello! I am getting an error when I try to find the length of an array! All I am trying to accomplish with t$$anonymous$$s script is spawn a random gameobject from an array. To do that I need to find the length of an array, yet for some reason Unity won't let me do that. The error I am getting is: CS0117 UnityEngine.GameObject[] does not contain a definition for 'Length'

Here is my code, also note I have tried to just print the length of the array to the console out of the instantiate and just in the start function, it resulted in the same error.

 using UnityEngine;
 using System.Collections;
 
 public class SpawnScript : MonoBehaviour {
     
     public GameObject[] objects;
     
     // runs spawn func
     void Start () {
         Spawn();
     }
     
     //spawns in a random item from an array and then does it every .5 seconds.
     void Spawn()
     {    
         Instantiate(objects[Random.Range (0, objects.Length)], transform.position, Quaternion.identity);
         Invoke ("Spawn", .5f);
     }
 }
 


Thanks for viewing (and hopefully helping)!

Comment
Add comment · Show 9
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 Dave-Carlile · Sep 01, 2015 at 06:55 PM 0
Share
avatar image kjakubison · Sep 01, 2015 at 07:12 PM 0
Share
avatar image benbendixon · Sep 02, 2015 at 02:42 AM 0
Share
avatar image Mikilo · Sep 02, 2015 at 03:21 AM 0
Share
avatar image getyour411 · Sep 02, 2015 at 03:33 AM 0
Share
Show more comments

3 Replies

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

Answer by benbendixon · Sep 06, 2015 at 03:29 PM

@bunny83 @wibble82 Yes I am sure I haven't changed anyt$$anonymous$$ng. I even created a new project and tried running a debug line that would just print the length of a simple array and that didn't work. I have not "given up" on t$$anonymous$$s question, I just simply don't have anyt$$anonymous$$ng to add. I have been trying to work with a support member. Feel free to mark the question as unreproduceable.

Comment
Add comment · Show 3 · 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 Mikilo · Sep 06, 2015 at 05:40 PM 0
Share
avatar image Bunny83 · Sep 07, 2015 at 01:56 AM 0
Share
avatar image benbendixon · Sep 07, 2015 at 04:00 AM 0
Share
avatar image
0

Answer by Cryptomane · Sep 06, 2015 at 04:07 PM

Works fine for me, even if the array was empty.

The only t$$anonymous$$ng that comes to my mind might be some corrupted library in your project, OR ...

Do you have a "GameObject" class in your project?

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 benbendixon · Sep 06, 2015 at 05:45 PM 0
Share
avatar image
0

Answer by OceKat3 · Oct 27, 2019 at 10:32 PM

@benbendixon T$$anonymous$$s is how I fixed the problem for myself: Use an uppercase L in "Length" instead of a lowercase one. The unity documentation makes it seem like you should use a lowercase L, w$$anonymous$$ch I find weird.

Comment
Add comment · Show 2 · 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 Mikilo · Oct 27, 2019 at 10:34 PM 0
Share
avatar image Bunny83 Mikilo · Oct 29, 2019 at 11:15 AM 0
Share

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiate from array into array? 2 Answers

How Do I Add An Instantiated Object To An Array? 3 Answers

instantiate gameobjects inside a canvas 0 Answers

Spawning according to screen width 3 Answers

How To Get A Reference To All Nearby GameObjects? 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