Sometimes when working with ClickObject or other similar commands, it appears as though the object is found and a click command sent, but the logs often paint a different picture, as if the clicked coordinates are outside of a valid screen area (negative values or values greater than the max viewport/window/screen resolution). This is usually caused by a difference between the position of the object relative to the active camera in the scene which is used for rendering.


ClickObject uses Camera.Main to locate and click objects by default. If the currently rendering camera is not tagged as 'MainCamera' or if multiple main cameras are present in the scene, the default way of picking the camera may not be accurate.

public bool ClickObject(MouseButtons buttonId, string hierarchyPath, ulong frameCount, 
    string cameraHierarchyPath = "", int timeout = 30)

ClickObject call has a cameraHiearchyPath parameter that can be used to specify which camera object should be used to generate the click. Note that the parameter expects a camera component so please target the component as seen in the example below.

//*[@name='Main Camera (1)']/fn:component('UnityEngine.Camera')



Steps to take to identify the correct camera


Navigate to the HPathREPL tool and do a lookup of all the camera objects in the scene. The tool will automatically select all the matching objects in the hierarchy window. (Note: This functionality will soon be moved over to the HPath debugger, so if you are no longer able to find the REPL tool under the GameDriver menu, please use the debugger instead)

//*[contains(.,fn:type('UnityEngine.Camera')) and @activeSelf='true']


This next section is specifically to troubleshoot clicks on regular GameObjects using Raycasts


If you know that your code specifically expects the Raycast to originate from a camera tagged 'MainCamera' and you have multiple of those on the scene, you can do a lookup of all objects tagged 'MainCamera' from the HPathREPL tool

//MainCamera[@activeSelf='true']