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
0
Question by apixel · Aug 05, 2016 at 06:14 PM · scripting problembug

LineRenderer SetPositions gives a SetPosition index out of bounds

I believe that LineRenderer.SetPositions is not behaving correctly. When given an array longer than what was set with SetVertexCount, it always shows an index out of bounds error, even though the points within the count are available. One is forced to pass an array which length matches the SetVertexCount number. This seems inefficient as one should be able to maintain a larger array that is ready to handle a short or long line. The line is drawn correctly either way.

The script below is the simplest way to show the problem. In both cases, the line is drawn properly, but one way throws an error.

 using UnityEngine;
 using System.Collections;
 
 public class LR_Bug : MonoBehaviour {
 
     /*
      * Default Empty Scene
      * Attach a LineRenderer to the Main Camera, and this script to the Main Camera
      * 
      * */
     private LineRenderer LR;
     private Vector3[] points10, points2;
     private int evenOrOddSeconds;
 
     // Use this for initialization
     void Start () {
     
         LR = this.GetComponent<LineRenderer> ();
 
         // create an array with 10 items, but only init 2
         points10 = new Vector3[10];
         points10 [0] = new Vector3 (0F, 0F, 10F);
         points10 [1] = new Vector3 (10F, 10F, 10F);
 
         // create an array with 2 items, and init both
         points2 = new Vector3[2];
         points2 [0] = new Vector3 (10F, 0F, 10F);
         points2 [1] = new Vector3 (20F, 10F, 10F);
 
     }
     
     // Update is called once per frame
     void Update () {
 
         // swap lines every second
         evenOrOddSeconds = (int)(Time.time % 2);
 
         if (evenOrOddSeconds == 0) {
             /* 
              you will get "LineRenderer.SetPosition index out of bounds!"
              even though you are saying to use only the first two elements
              which are properly initialized
              The LR does draw the line correctly.
              */
             Debug.Log ("Using an array of length 10, but only asking to draw 2 - shows error");
             LR.SetVertexCount (2);
             LR.SetPositions (points10);
 
         } else {
             /*
              * array matches vertext count - no error 
              * 
              */
             Debug.Log ("Using an array of length 2, no error");
             LR.SetVertexCount (2);
             LR.SetPositions (points2);
 
         }
             
     }
 }


Can anyone reproduce this? Should I not worry about the error? Should I not worry about having to create a new array of the proper size every time I need to update the line, instead of keeping track of a single larger array?

Thank you,

Andres

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to keep other Attributes when working with custom ones? 0 Answers

Level Select screen Messed Up - Please help! 0 Answers

Unity can't use the script. 0 Answers

Bug With My Level Select Screen 2 Answers

Instantiated UI elements not rendering on canvas 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