Inspector values not registering while playing
Posted: Sun Aug 11, 2013 6:22 pm
I figure this is already a known issue, but just in case:
Once you hit play and adjust a Chipmunk object in the inspector, the change will not actually take effect in the simulation even though it'll update the value in the inspector. This is due to using Unity's default inspector which only exposes public fields and not properties - the property accessors being the ones that take care of registering the values in Chipmunk's simulation. I figure this is a known issue since the property backing fields are being exposed publicly, which seemed weird to me.
Anyways, all that is needed is a custom inspector to access an object's properties explicitly. Like so for a ChipmunkBody:
But then modifying some properties, like isKinematic, while playing will break the simulation. Any plans on addressing this soon or should I go about implementing my own inspectors?
Thanks
Once you hit play and adjust a Chipmunk object in the inspector, the change will not actually take effect in the simulation even though it'll update the value in the inspector. This is due to using Unity's default inspector which only exposes public fields and not properties - the property accessors being the ones that take care of registering the values in Chipmunk's simulation. I figure this is a known issue since the property backing fields are being exposed publicly, which seemed weird to me.
Anyways, all that is needed is a custom inspector to access an object's properties explicitly. Like so for a ChipmunkBody:
Code: Select all
using UnityEditor;
[CustomEditor(typeof(ChipmunkBody))]
public class MyChipmunkBodyEditor : Editor
{
public override void OnInspectorGUI()
{
var newMass = EditorGUILayout.FloatField("Mass", _body.mass);
if(_body.mass != newMass)
{
_body.mass = newMass;
}
var newMomentCalculation = (ChipmunkBodyMomentMode) EditorGUILayout.EnumPopup("Moment Calculation", _body.momentCalculationMode);
if(_body.momentCalculationMode != newMomentCalculation)
{
_body.momentCalculationMode = newMomentCalculation;
}
var newCustomMoment = EditorGUILayout.FloatField("Custom Moment", _body.moment);
if(_body.moment != newCustomMoment)
{
_body.moment = newCustomMoment;
}
var newIsKinematic = EditorGUILayout.Toggle("Is Kinematic", _body.isKinematic);
if(_body.isKinematic != newIsKinematic)
{
_body.isKinematic = newIsKinematic;
}
var newInterpolationMode = (ChipmunkBodyInterpolationMode) EditorGUILayout.EnumPopup("Interpolation Mode", _body.interpolationMode);
if(_body.interpolationMode != newInterpolationMode)
{
_body.interpolationMode = newInterpolationMode;
}
}
private ChipmunkBody _body;
private void OnEnable()
{
_body = (ChipmunkBody) target;
}
}
Thanks