# How to retrieve the time of events in a modeling toolkit solution?

**URL:** <https://discourse.julialang.org/t/how-to-retrieve-the-time-of-events-in-a-modeling-toolkit-solution/135009>\
**Category:** General Usage\
**Tags:** modelingtoolkit\
**Created:** [January 12, 2026, 6:33pm UTC](https://discourse.julialang.org/t/how-to-retrieve-the-time-of-events-in-a-modeling-toolkit-solution/135009 "2026-01-12T18:33:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [January 12, 2026, 6:33pm UTC](https://discourse.julialang.org/t/how-to-retrieve-the-time-of-events-in-a-modeling-toolkit-solution/135009/1 "2026-01-12T18:33:22Z")

</div>

I have a MTK system with a `@continuous_events` block. Is there a way to retrieve when these events are triggered somewhere in the solution ? I could not find anything about this in [Event Handling and Callback Functions · ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/stable/basics/Events/#Continuous-Events).

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 13, 2026, 2:30pm UTC](https://discourse.julialang.org/t/how-to-retrieve-the-time-of-events-in-a-modeling-toolkit-solution/135009/2 "2026-01-13T14:30:01Z")

</div>

It’s not necessarily saved unless you add that to the affect!

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [January 13, 2026, 4:08pm UTC](https://discourse.julialang.org/t/how-to-retrieve-the-time-of-events-in-a-modeling-toolkit-solution/135009/3 "2026-01-13T16:08:09Z")

</div>

Ok, but where should it be specified ? For instance on the [bouncing ball example from the documentation](https://docs.sciml.ai/ModelingToolkit/stable/basics/Events/#Example:-Bouncing-ball)

```julia-auto
@variables x(t)=1 v(t)=0

root_eqs = [x ~ 0] # the event happens at the ground x(t) = 0
affect = [v ~ -Pre(v)] # the effect is that the velocity changes sign

@mtkcompile ball = System(
    [D(x) ~ v
     D(v) ~ -9.8], t; continuous_events = root_eqs => affect) # equation => affect

tspan = (0.0, 5.0)
prob = ODEProblem(ball, Pair[], tspan)
sol = solve(prob, Tsit5())
@assert 0 <= minimum(sol[x]) <= 1e-10 # the ball never went through the floor but got very close
plot(sol)

```

Do you mean some option should be added to `[v~ -Pre(v), <some saving option ?>]` ?  
Or do you mean that an additional discrete parameter should be added to the system to store the time of these events, or something else ?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 13, 2026, 4:30pm UTC](https://discourse.julialang.org/t/how-to-retrieve-the-time-of-events-in-a-modeling-toolkit-solution/135009/4 "2026-01-13T16:30:07Z")

</div>

If you use a FunctionalAffect then you can just `push!(times,t)`

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [January 13, 2026, 4:44pm UTC](https://discourse.julialang.org/t/how-to-retrieve-the-time-of-events-in-a-modeling-toolkit-solution/135009/5 "2026-01-13T16:44:59Z")

</div>

So far, I have detected these events by finding double occurrences of a time step in `sol.t` which seems to work fine, but it is quite fragile I believe. Also it does not allow to keep track of which event or system in a complex model triggered the event.

As there is apparently no built-in way to store these events, do you think this could be done at the subsystem level so that it could be indexed in the solution later on ? That could at least allow to sort the events location per system, and even per event if one discrete is defined per event, as presented in [Event Handling and Callback Functions · ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/stable/basics/Events/#save_discretes)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 13, 2026, 5:39pm UTC](https://discourse.julialang.org/t/how-to-retrieve-the-time-of-events-in-a-modeling-toolkit-solution/135009/6 "2026-01-13T17:39:45Z")

</div>

We can add it in the future.

---

<div class="post-metadata">

**Author:** ![sablonl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sablonl/32/217805_2.png) [@sablonl](https://discourse.julialang.org/u/sablonl)\
**Post date:** [January 13, 2026, 8:17pm UTC](https://discourse.julialang.org/t/how-to-retrieve-the-time-of-events-in-a-modeling-toolkit-solution/135009/7 "2026-01-13T20:17:28Z")

</div>

You could also add a variable, set its derivative to zero in the equations and updating it to the current time in the callbacks.
