Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

The CinemachineImpulseDefinition can not work for private field with SerializeField.

Discussion in 'Cinemachine' started by watsonsong, Aug 3, 2018.

  1. watsonsong


    May 13, 2015
    I use the CinemachineImpulseDefinition in my own script to simulate the camera shake.
    I write it like this:
    Code (CSharp):
    2. [SerializeField]
    3. [CinemachineImpulseDefinitionProperty]
    4. public CinemachineImpulseDefinition impulseDefinition =
    5.     new CinemachineImpulseDefinition();
    I want to change the public to private, because there is no need to access the impulseDefinition outside, but the editor inspector show a lot of error when I switch to private field.

    I see the EmbeddedAssetPropertyDrawer.cs may not support the private field:
    Code (CSharp):
    2. Type EmbeddedAssetType(SerializedProperty property)
    3. {
    4.     Type type = property.serializedObject.targetObject.GetType();
    5.     var a = property.propertyPath.Split('.');
    6.     for (int i = 0; i < a.Length; ++i)
    7.         type = type.GetField(a[i]).FieldType;
    8.         return type;
    9. }
    It use GetField but it may not work with private field.
  2. Gregoryl


    Unity Technologies

    Dec 22, 2016
    Yes, you are right, it only works with public fields. To fix it, the code should be
    Code (CSharp):
    1.         Type EmbeddedAssetType(SerializedProperty property)
    2.         {
    3.             Type type = property.serializedObject.targetObject.GetType();
    4.             var a = property.propertyPath.Split('.');
    5.             for (int i = 0; i < a.Length; ++i)
    6.                 type = type.GetField(a[i],
    7.                     System.Reflection.BindingFlags.Public
    8.                     | System.Reflection.BindingFlags.NonPublic
    9.                     | System.Reflection.BindingFlags.Instance).FieldType;
    10.             return type;
    11.         }
    Thanks for letting us know, we'll include a fix in the next release.