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 AGaballo · Dec 21, 2018 at 02:28 PM · uilinerendererextension

UIExtensions - LineRenderer not updating

Hi, I'm using the UILineRenderer from the UI extensions asset to plot something. I'm periodically updating the set of points in the LineRenderer however the line doesn't seem to change in Play mode even if I see the points changing. If I try to toggle one of the object options the line gets updated so I think there's a rendering issue here. Here's an example of the code:

     using UnityEngine.UI.Extensions;
     using UnityEngine.UI;

     void Start(){
          StartCoroutine("coroutine");
     }

     public class Plot : MonoBehaviour {
          Vector2[] linePoints;
          int pTime;
          IEnumerator coroutine(){
                 Debug.Log("Start service");
                 while(true){
                     pTime = Random.Range(-50,50);
                     updateLine();
                     yield return new WaitForSeconds(1);
                 }
         
             }
         
             void updateLine(){
                 Debug.Log("Updating");
                 int i;
                 for(i = 0; i < numPoints-1; i++)
                     linePoints[i].y = linePoints[i+1].y;
                 linePoints[i].y = pTime;
                 
                 lineRenderer.Points = linePoints;
             }
 }
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 andrew-lukasik · Jan 07, 2019 at 11:56 AM 0
Share

I have no fix for you but other things in your code "smell" a bit. Let me unpack those in comments:

 public class Plot : $$anonymous$$onoBehaviour
 {
     Vector2[] linePoints;
     void Start ()
     {
         StartCoroutine( LineRendererRoutine() );//do not use string argument here (slower, bug-prone, redundant)
     }
     IEnumerator LineRendererRoutine ()
     {
         var second = new WaitForSeconds(1);//creating this small object every frame is a kind of memory leak; it will introduce ugly cpu spikes (GC)
         while( true )
         {
             #if DEBUG
             if( linePoints.Length==0 ) { Debug.LogWarning( "linePoints contains nothing" , gameObject ); }
             #endif

             //update line renderer:
             {
                 int pTime = Random.Range( -50 , 50 );
                 int numPoints = linePoints.Length;
                 for( int i = 0 ; i<numPoints-1 ; i++ )
                 {
                     //get data from array:
                     Vector3 p0 = linePoints[ i ];
                     Vector3 p1 = linePoints[ i+1 ];
 
                     //calculate new point
                     Vector3 p0New = p0;
                     p0New.y = p1.y;
                     p0New.y = pTime;//...but you changed 'y' line above already https://i.imgur.com/1vZr6hs.jpg
 
                     //update data in array:
                     linePoints[ i ] = p0New;
                 }
                 //PROTIP: skip "{}" brackets when using 'for' loop to introduce silly bugs
 
                 //update line renderer when array when job is done:
                 lineRenderer.Points = linePoints;
             }
 
             //await:
             yield return second;
         }
     }
 }
avatar image AGaballo andrew-lukasik · Jan 07, 2019 at 01:01 PM 0
Share

Hi @andrew-lukasik, thanks for your answer. $$anonymous$$y problem is not that the points in the array are not changing, but the fact that the new points are not rendered. I can see from the Inspector that the values of my points are changing, however they remain the same on the screen unless I modify something of the UI Line Renderer from the Inspector (e.g. toggle Use Native Size).

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by AGaballo · Jan 08, 2019 at 10:48 AM

Solved by calling lineRenderer.SetAllDirty() after updating the points.

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 mikelantzelo · Sep 26, 2020 at 04:12 PM 0
Share

Thank you!!!! Working!!!

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

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

Line Renderer in GUI 0 Answers

I have questions about ui linerender and linerender. 1 Answer

How do I get the default scene GUI for a CustomEditor for RectTransform? 1 Answer

How to make UI circle follow UI Line Renderer 0 Answers

Draw a line to a new pontential character position/target 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