Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to trigger custom event only once per frame?

Discussion in 'Visual Scripting' started by AtomicLugia, Jan 29, 2022.

  1. AtomicLugia

    AtomicLugia

    Joined:
    Aug 15, 2020
    Posts:
    54
    I'm making something like a weapon selection UI where you cycle through weapons and select with left click like in Heavy Metal F.A.K.K.² and some FPS games IIRC.

    So I made that but when the game get's slower/laggy (when lots of stuff is happening for example), the selection UI seems to skip some elements when using the mouse wheel. For example, one scroll up, and it thinks I did this four times.

    Here's the flow machine that checks the mouse wheel and triggers the custom events:


    Is there a workaround or better way to trigger a mousewheel up/down once event regardless of FPS?

    Sorry if this is embarrassing tho.

    Unity 2020.2.1f1
    Bolt 1.4.13
     
  2. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    380
    Try using 'Update' rather than Fixed Update
     
  3. AtomicLugia

    AtomicLugia

    Joined:
    Aug 15, 2020
    Posts:
    54
    Already tried every Update method, didn't work.
     
  4. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    380
    Maybe use a boolean, eg. isScrolled. When it =< -1 and isScrolled = false, set isScrolled = true and trigger. When it = 0, isScrolled = false. Then it should only trigger for 1 frame until it returns to 0. Looks like it triggers over a few frames, depending on fps.
     
    haroldo7 likes this.
  5. AtomicLugia

    AtomicLugia

    Joined:
    Aug 15, 2020
    Posts:
    54
    Okay, I used now a boolean that disables the trigger for .01 second and this seems to do the trick, so the problem is solved now!

    Thanks for the hint.
     
    haroldo7 and Trindenberg like this.