Sometimes it is necessary to add or instantiate the GDIO Agent component to the project programmatically, rather than through the UI. This could be due to a requirement to remove the agent from the final build of the project (which is recommended), or simply due to wanting to control the inclusion of the agent via the build system and target. In any case, the agent can be added to a scene using the same approach as any other object, such as calling:


GameObject agentObject = new GameObject("TestAgent");
gdio.unity_agent.GDIOAgent agent = agentObject.AddComponent<gdio.unity_agent.GDIOAgent>();


The above should be called in the Awake function, to allow the agent to start before most game components. To have this script load only in certain conditions, such as when enabled by the build server, add a script definition making sure to add this definition to the Editor when you wish the agent to be enabled for testing. For more information on script defines and conditional compilation, see the Unity docs.


A sample script has been included below for reference.