When debugging some Unity-related problem, there is often need of finding which game object in the scene does something. We can use transform.name (or gameObject.name), but there are often multiple objects in the scene with such name. The better solution would be to log full path in the scene graph (in a manner : objectsGrandParent/objectsParent/theObject).
I don't know of any built-in solution for that, here is the helper class I've created for that purpose.
It takes transform as a parameter, of course we can call it with gameObject.transform if necessary.
It can be used like this:
As a result, if we add the MyBehaviour script to MyObject object in hierarchy like this:
... and run our scene, the logs will show up:
No comments:
Post a Comment