- Home /
is there an *external* API for Unity?
Is there a way to embed the unity engine within another program? I would like to be able to fire up Unity within a (for example) c++ program, attach it to a GL context, tell it when to draw, send it mouse clicks, keyboard events, other user interactions, etc.
My motivation for doing this is to create a test rig where the GL context actually dumps to a video file, and the user interactions actually come from a pre-specified data file.
One good answer on doing this from a script inside unity was given here: http://answers.unity3d.com/questions/254287/render-scene-from-script.html, but I'm wondering whether it's possible to do something like this from "outside" Unity.
Answer by DaveA · May 18, 2012 at 10:42 PM
You could try embedding the web player, but last I tried (2 years ago) it was not supported, didn't work. Seems like it could be done if UT wanted it to.
What I did was make an HTML control to embed in my app, then load an HTML page with the Unity web player in it into that. Then uses some 'glue' javascript in that HTML page to talk to the plugin via SendMessage and ExternalCall (and the API's that let my containing app talk to the HTML page's javascript). It was quite messy.
Not sure about the GL context thing, but there are ways to use GL with Unity. And you can use various techniques to get commands into Unity from external sources. Ex you can use the WWW object to poll a server which would send coded messages, and decode them in your Unity script. Or set up a socket client/server thing.
Your answer
![](https://koobas.hobune.stream/wayback/20220613071641im_/https://answers.unity.com/themes/thub/images/avi.jpg)