Search Unity

Question How do I access "Elapsed %" from the Timer node?

Discussion in 'Visual Scripting' started by oddtail, Feb 18, 2023.

  1. oddtail

    oddtail

    Joined:
    Jun 14, 2018
    Posts:
    2
    I am trying to create a script that uses the Timer node. Connecting the "Elapsed %" (or "Elapsed", for that matter) to anything returns this, or similar, error message:

    "InvalidOperationException: The value of 'elapsedSeconds' on 'Timer#1a7e8...' cannot be fetched dynamically, it must be assigned."

    This happened when I tried to connect Elapsed% directly to a Lerp node. I thought maybe seting a graph variable would work, but connecting "Elapsed %" to "Set Variable" returns the exact same error.

    I'm attaching a screenshot of the graph in case it's relevant.

    lerp.png

    Unless I'm missing something, there seems to be no way to access the "Elapsed %". How do I do this? Alternatively, is there any way to get values between 0 and 1 over a number of seconds for a lerp function? What I'm trying to accomplish is theoretically pretty simple - I want alpha of an image to go from 0 to 1 linearly.

    I have some rudimentary coding knowledge, but not much beyond basics - I wouldn't be using Visual Scripting otherwise.

    There is already a thread about this issue, but it's two years old and doesn't contain an actual answer ( https://forum.unity.com/threads/what-is-wrong-in-this-graph.1057853/ ). And I assume the way visual scripting works may've changed in the interim.

    EDIT: I managed to get around this by manually adding Delta Time to a float and dividing it by the original timer time (and not using the Timer node at all). But I'm still curious if it's possible to make "Elapsed %" work, since it'd make it possible to do in one node what I did in like, seven.
     
    Last edited: Feb 18, 2023
  2. Ignacii

    Ignacii

    Joined:
    May 23, 2013
    Posts:
    108
    It means that you are trying to use the elapsed values in another flow. You have to simply assign the elapsed values to a variable and then use that new variable to get the elapsed value anywhere you need.

    To put the elapsed values to a variable, use the tick flow and set the elapsed value to a variable while the Timer is running.

    In other words, you must use the Timer's flow to set the var, not Update's.
     
    Last edited: Feb 22, 2023
    oddtail likes this.
  3. oddtail

    oddtail

    Joined:
    Jun 14, 2018
    Posts:
    2
    It worked. It hadn't occurred to me to connect the assigning to the Tick output of the timer; thank you so much for your help, you probably saved me a lot of hassle down the road.
     
    Ignacii likes this.