While using Python Script ,how to reset a variable after stop button is pressed

For example , there is a variable recording runtime since I pressed play button. After I pressed stop button it will reset to 0.

Hi @1031521414

You can subscribe to stage events and modify the variable according to the desired event

import carb.events
import omni.usd

# callback
def on_stage_event(event):
    if event.type == int(omni.usd.StageEventType.SIMULATION_START_PLAY):
    elif event.type == int(omni.usd.StageEventType.SIMULATION_STOP_PLAY):
# subscription 
stage_event_sub = (omni.usd.get_context()
                   .create_subscription_to_pop(on_stage_event, name="subscription name"))

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.