mujoco
mujoco copied to clipboard
Unity Plugin: compiler directive to enable builds and synchronising C# scripts with MuJoCo
Description
Two small additions:
- The plugin's Editor scripts were not ignored during build, leading to unresolved references preventing standalone builds. The scripts that prevented the build were wrapped with the following directive:
#if UNITY_EDITOR
//Component Editor Script
#endif
Behaviour is not impacted in the editor, but builds are now successful. Fixes #245.
- An event was added to
MjScenethat allows C# scripts, such as custom controllers and agents to subscribe handlers that are invoked betweenmj_step1andmj_step2. This can improve the stability of certain actuator controllers, and can guarantee order of execution instead of relying on separateFixedUpdate()s. If no such handler is subscribed, thenmj_stepis executed as usual. Pointers to the simulation data for event handlers are included in a customEventArgs. Related to #233.
I propose an alternative fix to the compiler directives, by configuring the .asmdef in the Editor folder correctly
https://github.com/deepmind/mujoco/pull/303
This avoids having to create a lot of #ifdef directives and keeps the code cleaner overall.
I edited this pull request to only add the events to MjScene that can be used to synchronise behaviour with C# scripts, and removed the edits to the Editor scripts, as I believe #303 handled that part better. Furthermore I added events that happen before and after mjStep, as these can be used to control order of execution independent of project settings, useful for example in behaviours in MlAgents environments.
I will submit a separate pull request for the event synchronising functionality from a branch thats more in sync with the deepmind main.