- Home /
Disabling line renderer stops animation rendering
Hi guys, i ran into the rather interesting problem while making shooting effects in my game.
This shooting effect is rather simple and is represented by a rendered line from the barrel end to target. A line renderer is enabled and disabled as a component in the script to make it blink and represent shooting. When I ran the game I saw the following: https://www.youtube.com/watch?v=m7n6kCDK8Pw
As you can see, char is frozen somewhere between animations' transitions until the next time LineRenderer component is enabled. To investigate the problem I tried to increase lasting time of the shooting effect: https://www.youtube.com/watch?v=1DLib-_PbAI
Same problem, but subroutine starts later, and character freezes later too. This breaks other animations of the Object as well.
I have workaround now. Instead of disabling the component, I just set width from zero/zero to 0.3/0.3. Everything runs smoothly: https://www.youtube.com/watch?v=J2kz4J8tWcw
But I want to understand why this happens to avoid such problems in future and expand knowledge:) If anyone has the answer, please.
P.S. Some additional info to solve the issue.
My LineRenderer component and SkinnedMeshRenderer both attached to the one child object of the parent. Parent is actually a container for all model's components.
Here are update and disableshootingeffect functions:
protected override void Update() { base.Update(); if (currentAim != null) { if (myShootingPrefs.IsAbleToShoot) { if (Vector3.Distance(transform.position, currentAim.transform.position) >= myShootingPrefs.MaxShootingDistance) { myShootingPrefs.IsAbleToShoot = false; myAnimController.SetBool("isAttacking", false); } else Shoot(); } else { if (Vector3.Distance(transform.position, currentAim.transform.position) <= myShootingPrefs.ShootingStartDistance) { myShootingPrefs.IsAbleToShoot = true; myNavAgent.SetDestination(transform.position); myAnimController.SetBool("isAttacking", true); } else myNavAgent.SetDestination(currentAim.transform.position); } } if (Time.time > effectFinishTime && gunline.enabled) TurnOffShootingEffects(); } void TurnOffShootingEffects() { gunline.SetWidth(0f, 0f); //if we change to gunline.enabled problem with animation occurs! }
Huge if-else construction is used to decrease unnecessary calculations in the Update() func, because it already has a lot of instructions.
Hello! Without the rest of the code it seems impossible to solve the problem. I'd recommend debugging all interactions with the gunline's enabled variable. So add comments after each gunline reference. What class used it for what purpose debug the changes on the variable, maybe it's a loop that causes this animation freeze.
Your answer
![](https://koobas.hobune.stream/wayback/20220612082343im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can the animation editor create local rotational data? 3 Answers
Adding animation clips via script 2 Answers
Get Line Renderer to restart from start everytime using coroutine. HELP?!?!?!? 1 Answer
Can I make animations snap to a frame? 1 Answer
Get line Renderer code to restart animation every time mouse is clicked 1 Answer