Detecting OnPlay and OnStop within Cpp Extensions

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

1 Like

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!

I ran across this Timeline library Timeline — Omniverse Kit.

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)

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

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