Get time of animation curve with value

Im currently designing the UI animation for my game, and i need a way to get the time (x) of a monotonic curve based on a value (y).

I have seen multiple attempts by reversing the curve, however they seem to either be outdated or fail to work at all, especially when tangents are introduced.

Anyone got an idea to do this?

Preemptive Thanks

-Lemon

Example of what im trying to do:

The curve:

The curve but reversed/flipped, with x representing the y of the previous curve:
9889299--1427301--upload_2024-6-13_21-40-26.png

Since an AnimationCurve can have any shape of Y values for each keyframe, there is no guarantee you can create an inverse function. For example, imagine an AnimationCurve that starts at 0, peaks at 1, and returns to 0. There are then at least two X places along the curve for Y=0.5.

You can make a guess value for X, and decide whether to move to a smaller or larger X based on the slope of the evaluated curve near your guess. How you decide “near” or how you decide to “move” your guess is up to you. There’s a whole branch of mathematics involved, but start with Euler’s Method or Runge-Kutta solvers.

ETA: If you know your function can be reversed, just start with a guess of X=0 and slowly increase X until the evaluated result passes your desired Y.