# Detecting OnPlay and OnStop within Cpp Extensions

**URL:** <https://forums.developer.nvidia.com/t/detecting-onplay-and-onstop-within-cpp-extensions/317612>\
**Category:** Isaac Sim\
**Tags:** omniverse\_extension, isaac-sim-v4-2-0\
**Created:** [December 20, 2024, 2:56pm UTC](https://forums.developer.nvidia.com/t/detecting-onplay-and-onstop-within-cpp-extensions/317612 "2024-12-20T14:56:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex.perez1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@alex.perez1](https://forums.developer.nvidia.com/u/alex.perez1)\
**Post date:** [December 20, 2024, 2:56pm UTC](https://forums.developer.nvidia.com/t/detecting-onplay-and-onstop-within-cpp-extensions/317612/1 "2024-12-20T14:56:27Z")

</div>

Please provide all relevant details below before submitting your post. This will help the community provide more accurate and timely assistance. After submitting, you can check the appropriate boxes. Remember, you can always edit your post later to include additional information if needed.

### Isaac Sim Version

4.2.0

### Operating System

Ubuntu 22.04

### GPU Information

- Model: 4x RTX A4000
- Driver Version: 550.90.07

## Topic Description

### Detailed Description

Similar to how Behavior Scripts in python have onStart, onPlay, onUpdate, onStop functions, I want this functionality in cpp extensions for IsaacSim. It appears by default, I get from cpp extensions an onStartup and onShutdown function which correspond to when the extension is enabled/disabled. I have been able to achieve an onUpdate function by doing the following:

> if (auto app = carb::getFramework()-\>acquireInterface\<omni::kit::IApp\>())  
> {  
> // Subscribe to update events.  
> carb::events::ISubscriptionPtr m\_updateEventsSubscription =  
> carb::events::createSubscriptionToPop(app-\>getUpdateEventStream(),[this](carb::events::IEvent\*) {  
> onUpdate();  
> });  
> }

However, this calls onUpdate on every app update, which means this onUpdate function is getting called even when the simulation is not playing. One option that did work was using the dynamic\_control library’s isSimulating function, however, since this library is deprecated, I want to avoid using that.

Overall, what is the approach to achieve similar functionality to python behavior scripts in cpp extensions?

Thanks,  
Alex

---

<div class="post-metadata">

**Author:** ![sam.lovelace](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@sam.lovelace](https://forums.developer.nvidia.com/u/sam.lovelace)\
**Post date:** [December 20, 2024, 8:18pm UTC](https://forums.developer.nvidia.com/t/detecting-onplay-and-onstop-within-cpp-extensions/317612/2 "2024-12-20T20:18:07Z")

</div>

I have also run into this issue, would love to figure out a way to implement similar functionality to the python scripting components in a c++ extension!

---

<div class="post-metadata">

**Author:** ![alex.perez1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@alex.perez1](https://forums.developer.nvidia.com/u/alex.perez1)\
**Post date:** [December 20, 2024, 8:42pm UTC](https://forums.developer.nvidia.com/t/detecting-onplay-and-onstop-within-cpp-extensions/317612/3 "2024-12-20T20:42:06Z")

</div>

I ran across this Timeline library [Timeline — Omniverse Kit](https://docs.omniverse.nvidia.com/kit/docs/omni.timeline/latest/api/classomni_1_1timeline_1_1Timeline.html#classomni_1_1timeline_1_1timeline).

In the end, this is what I ended up doing. I could not get the callback functionality to work as this link suggests ( [C++ Usage Examples — Omniverse Kit](https://docs.omniverse.nvidia.com/kit/docs/omni.timeline/latest/USAGE_CPP.html))

> #include \<omni/timeline/ITimeline.h\>  
> omni::timeline::TimelinePtr timeline = omni::timeline::getTimeline();

> void onUpdate(carb::events::IEvent\* event)  
> {  
> if (!timeline-\>isPlaying())  
> {  
> return;  
> }  
> # Do stuff  
> }
