mujoco icon indicating copy to clipboard operation
mujoco copied to clipboard

Unity Plugin: compiler directive to enable builds and synchronising C# scripts with MuJoCo

Open Balint-H opened this issue 3 years ago • 2 comments

Description

Two small additions:

  1. 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.

  1. An event was added to MjScene that allows C# scripts, such as custom controllers and agents to subscribe handlers that are invoked between mj_step1 and mj_step2. This can improve the stability of certain actuator controllers, and can guarantee order of execution instead of relying on separate FixedUpdate()s. If no such handler is subscribed, then mj_step is executed as usual. Pointers to the simulation data for event handlers are included in a custom EventArgs. Related to #233.

Balint-H avatar Apr 25 '22 16:04 Balint-H

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.

jespersmith avatar May 27 '22 13:05 jespersmith

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.

Balint-H avatar Jul 10 '22 13:07 Balint-H

I will submit a separate pull request for the event synchronising functionality from a branch thats more in sync with the deepmind main.

Balint-H avatar Nov 17 '22 11:11 Balint-H