[Solved] Adjusting vignette value only works once - Image Effects

Hello folks,

I am trying to achieve the simple step that the vignette increases while my player is crouching, and decreasing the value while he isn’t crouching.

Here is the code where I call the method:


And here is my code for changing the value:


This works only once. I am pressing my crouchKey and the vignette appears smoothly. I press the key again and the vignette disappears smoothly. Good!
But as soon as I press the key again to crouch, the vignette instantly changes to the other value, but if I press the key to stand up it disappears smoothly again.

What could be the problem here?
Thank you!

I suspect it is because you have multiple ChangeVignetteValue running. Let’s walk through it.

First crouchkey. ChangeVignetteValue runs once. Enters crouching while loop.

Second crouchkey first ChangeVignetteValue exits and a new one starts, entering !crouching while loop!

Third crouchkey. Second ChangeVignetteValue exits !crouching while, but then enters crouching while. A third ChangeVignetteValue starts which also enters the crouching while. You now have two while loops running.

Now the second one sets it to full because it’s time.time - timeToStart returns a high enough value.

1 Like

EDIT: Ah I got it. You’re right, the coroutine was running multiple times. I just added a few more lines to stop it if it is already running. Thanks! :slight_smile:

So easy, but sometimes you just don’t know what to do.

Glad you got it working! And understood what I was trying to explain. :slight_smile:

1 Like