When I execute a BehaviorScript and with a timeline subscription or physics subscription as in the class below, and an error occurs, the script execution stops, but the subscriptions remain.
When I then fix the error and on_init()
is executed again, new subscriptions are stacked on top.
The cleanest workaround for me is to completely shut down and re-launch the Omniverse app once a while during development.
How can I get rid of this and have a clean subscription management?
import carb.events
import omni.physx as physx
from omni.kit.scripting import BehaviorScript
from omni.timeline import TimelineEventType
class PhysicsBehaviorScript(BehaviorScript):
def on_init(self):
self._timeline_sub = self.timeline.get_timeline_event_stream()\
.create_subscription_to_pop(self.on_timeline_event)
self._physics_sub = physx.get_physx_interface().subscribe_physics_step_events(self.on_physics_update)
print("subscriptions initialized")
def on_timeline_event(self, e: carb.events.IEvent):
type = TimelineEventType(e.type)
if type == TimelineEventType.PLAY:
self.on_play()
elif type == TimelineEventType.PAUSE:
self.on_pause()
elif type == TimelineEventType.STOP:
self.on_stop()
def on_update(self, current_time: float, delta_time: float):
pass
def on_physics_update(self, delta_time):
pass
def on_play(self):
pass
def on_pause(self):
pass
def on_stop(self):
pass
def on_destroy(self):
self._physics_sub = None
self._timeline_sub = None
def __del__(self):
self.on_destroy()