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
1
Question by Peaj · Jul 31, 2017 at 02:31 PM · laglinerendererdelayupdate-order

linerenderer lags behind object positions

Hi,

I have a problem with the line renderer lagging one frame behind the target positions. the line renderer positions are set to the position of two transforms like this:

 for (int i = 0; i < Points.Length; ++i)
 {
     LineRenderer.SetPosition(i, Points[i].position);
 }

I already tried using Update, FixedUpdate, LateUpdate and OnRenderObject to set the position. Neither of them worked. It seems like it is the line renderer itself which updates too late. Does anybody have a fix or workaround? Maybe changing the execution order or forcing the line renderer to update?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by michaelfelleisen · Jun 17, 2020 at 07:48 AM

https://answers.unity.com/questions/1742489/linerenderer-lagging-behind.html?childToView=1742595#answer-1742595

had the same problem and found a solution!

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 michaelfelleisen · Jun 23, 2020 at 12:52 PM 0
Share

reposting my post:

Okay, there are multiple solutions to this.

The one I used in the end uses the Application.onBeforeRender delegate like this:

  private void OnEnable()
  {
      Application.onBeforeRender += UpdateLineRenderer;
  }
  
  private void OnDisable()
  {
      Application.onBeforeRender -= UpdateLineRenderer;
  }

If you dont want to use delegates, another way would be to move the script on a camera of your choice and use OnPreRender().

This function will not be called if the script is NOT on a camera!

  private void OnPreRender()
  {
      UpdateLineRenderer()
  }

sources:

https://docs.unity3d.com/ScriptReference/Application-onBeforeRender.html

https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnPreRender.html

avatar image jrpaglu michaelfelleisen · Nov 05, 2020 at 05:43 AM 0
Share

Great ! Its Works Thanks $$anonymous$$ate

avatar image Gsbzin jrpaglu · Nov 07, 2020 at 05:04 PM 0
Share

@michaelfelleisen hello, I had the same problem, and I used

void LateUpdate () { Application.onBeforeRender + = UpdateRoute; }

it worked on playermode, but as I compiled the game it doesn't work.

avatar image
1

Answer by Amneloris · Mar 21, 2018 at 10:37 AM

Peaj,

I have exactly the same problem. it's because the "UseWorldPosition" is checked. When I go local, no more lag.

no solution for now on my side.

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 Peaj · Mar 21, 2018 at 09:19 PM 0
Share

I found out that in my case the problem is related to VR motion tracking. As the position of the controlers is being updated at the latest possible time the linerenderer would have to be updated even after that. Sadly it does not seem to be possible to change when the linerenderer is being updated. The same problem occurs when attaching UI elements to the controlers btw.

avatar image Amneloris · Mar 22, 2018 at 07:29 AM 0
Share

indeed, exactly the same prolem for me. In VR, I attached my line to the controller ... So, I have this "lags". (I had already noticed the concern with the UI, but it was less disturbing ...) there is still a real problem ... Too bad the late update is not triggered after the detection of the position of the controller.

avatar image
1

Answer by partnery51 · Mar 20, 2020 at 12:51 PM

use lateUpdate to update the points because setting position when its rendernig cuase the lag try late update works well,use Late Update

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 FlaSh-G · Jul 31, 2017 at 10:25 PM

The LineRenderer does not have its own update cycle or anything. So putting your code in different update functions won't change anything, at least not for the LineRenderer. It's the code itself that lags behind for some reason.

First off, you can make sure the loop isn't faulty by removing it. Use LineRenderer.SetPositions instead, which sets all points at once rather than one by one in a loop.

Then, check the code that puts the data in your Points array. The data that is put in this array might actually be a frame behind. For example, if your objects move in Update and your script reads their positions in Update as well. Since you tried LateUpdate (which is a good idea in this case) and it didn't work, your problem seems to be more complex. Can't tell more though without knowing the code in question.

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 Peaj · Aug 01, 2017 at 07:46 AM 0
Share

Thanks for your reply. I already tried SetPositions and it didn't make any difference.

The linerenderer connects 2 objects. A kinematic rigidbody which is a child of a S$$anonymous$$mVR controller and a non kinematic rigidbody which is connected via spring joint.

The offset happens at the controller child. I can only get rid of it by using local space for the linerenderer which then leads to an offset on the other end.

So maybe the problem is when and where the S$$anonymous$$mVR controller positions are being updated. I thought it should be Update but maybe I'm wrong.

Then again it seems odd to me that updating the linerenderer in LateUpdate does not work because it should be right before rendering and could only be wrong if transform positions change after LateUpdate. I really just use the transform position (of a child) of the controller object.

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

73 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

Related Questions

Unity interface lags behind by one action... 0 Answers

iOS : Delayed response to touch began? 1 Answer

Android lag on Nexus 7 (2012) 0 Answers

How to prevent input lag/delay? 1 Answer

What causes long delay after hitting run in editor, how to reduce it? 0 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