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 /
This question was closed Nov 25, 2013 at 04:49 AM by hirenkacha for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by hirenkacha · May 24, 2012 at 09:37 AM · arrayarrayswaypoints

IndexOutOfRangeException: Array index is out of range.

Hi all, I am trying to add waypoints to the array in C#. But my code is giving me the error. I checked potentialWaypoints[] length 18 as expected. Its showing the error at line indicated in code "IndexOutOfRangeException: Array index is out of range." my code is,

 public Transform[] waypoints=new Transform[18];
 private int i=0;
 void start()
 {
      GetWaypoints();
 }
 void GetWaypoints () 
 {
     
     Transform[] potentialWaypoints  = waypointContainer.GetComponentsInChildren<Transform>();
     
     foreach(Transform potentialWaypoint in potentialWaypoints)
     {
         if (potentialWaypoint != waypointContainer.transform) 
         {
 /*Error=====>*/    waypoints[i] = potentialWaypoint;
             i++;
         }
     }
 }
Comment
Add comment · Show 1
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 flamy · May 24, 2012 at 10:01 AM 1
Share

link the unity process through mono develop and keep a break point at the specified line, now check when it gives null reference(at wat value of i). That would be helpful

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by hirenkacha · May 26, 2012 at 07:00 AM

I declared size of the array inside Getwaypoints and got it working. The issue is the scope of the size of the array.

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
1

Answer by lyzard · May 24, 2012 at 09:45 AM

maybe you could start by reducing the scope of your index variable i to the GetWayPoints method, it is not safe to let it as a global variable like that, especially if you call GetWaypoints twice.

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 hirenkacha · May 24, 2012 at 09:51 AM 0
Share

I am not going to call that method twice. Its being called in Start() and only once.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Distance error: Cannot cast from source type to destination 0 Answers

How to return index of List element? 1 Answer

How many audio clip arrays are supported? 1 Answer

Get all GameObjects by variable value 2 Answers

accessing gameObject script from an array 3 Answers


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