Logging an entire GameObject
More stuff from the shadowy corners of my hard-drive. Don’t remember the context, but someone needed to log every single piece of information available on a particular GameObject. I suppose this could be useful for end-user “This GameObject Just Went Completely FUBAR” ™ scenarios.
Anyway – it has reflection in it which by definition makes it cool.
Le codez:
public class Utilities
{
/* ... */
{
Component[] components = gameObject.GetComponents( typeof( Component ) );
FieldInfo[] fields;
PropertyInfo[] properties;
Debug.Log( gameObject.name + ":" );
foreach( Component component in components )
{
Debug.Log( " - " + component.GetType().Name + ":" );
fields = component.GetType().GetFields();
foreach( FieldInfo field in fields )
{
Debug.Log( " ." + field.Name + " = " + field.GetValue( component ) );
}
properties = component.GetType().GetProperties();
foreach( PropertyInfo property in properties )
{
Debug.Log( " ." + property.Name + " = " + property.GetGetMethod().Invoke( component, null ) );
}
}
if( children )
{
foreach( Transform transform in gameObject.transform )
{
Debug.Log( "->" );
LogGameObject( transform.gameObject, children );
}
}
}
{
LogGameObject( gameObject, false );
}
/* ... */
}
2 Comments
→
Reviewing my post I just realised that this will break if you have components on the GameObject which hold properties with no get defined.
Then again if you have a setup like that, you’re one crazy bastard and I have no desire to support your unholy coding.
Great stuff! Perhaps this cam help me diagnose why my sphere object is going completely “FUBAR” when user interaction scales it too rapidly. Hopefully I will be able to test it out soon.
iSensorii: http://vimeo.com/vjanomolee/videos