How to change the physical material every 3 seconds

Hi everyone, I’m doing a physical material replacement, and my goal is to randomly change a physical material every three seconds when I run it. (The physical material already exists in my stage). I used an asynchronous operation, a physical step, which didn’t seem right, but I couldn’t find any other way to solve this problem.

If I just used the physics step, it would be changing the physics material every frame, so I used an asynchronous operation, but it didn’t work properly either. Hope to get some help.

import numpy as np  
from omni.isaac.core.utils.prims import define_prim  
from omni.isaac.core.materials import PhysicsMaterial  
import random  
import omni.physx as _physx  
import omni.usd  
import asyncio  
import omni.client  
from pxr import UsdPhysics  

_timeline = omni.timeline.get_timeline_interface()  
_physxIFace = _physx.acquire_physx_interface()  

def physics_step(step):
    async def a () : 
        time = 0.0  
        while time < 3.0:  
            time = time + await  

        random_number= random.randint(10, 15)
        geometry_prim = GeometryPrim(prim_path="/World/Plane_01")
        geometry_prim.apply_physics_material(PhysicsMaterial(prim_path= f"/World/PhysicsMaterial_test_{random_number}"))
_physx_subscription = _physxIFace.subscribe_physics_step_events(physics_step)

changing the material should work, why dont you just get the dt from the step and change the material when you hit your counter, something like:

time = 0.0
def _on_physics_step(self, dt):
   time = time + dt
   if time > 3.0:
       # change material

Would that work for you?