I need to somehow get all properties from a component through a script.
For example I need to get all properties of a rigidbody like velocitiy, is it active, does it use gravity and so on and so on.
I don't want to type every property manually, is it possible to somehow loop through the properties.
Kinda like looping through the hierarchy but with properties and not objects.
Thanks
You will probably have to use Reflection to examine a type then check each property of an individual object such as:
using System;
using System.Reflection;
using Unity Engine;
public class YourScript : MonoBehavior {
void Start () {
PropertyInfo[] properties = typeof(Rigidbody).GetProperties();
//Get all the properties of your class.
foreach(PropertyInfo pI in properties) {
Debug.Log( pI.GetValue(rigidbody) );
//This returns the value cast (or boxed) to object so you will need to cast it to some other type to find its value.
}
}
}
//I haven't tested this, but it should be mostly correct.