Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Can not use the AxisState with AxisStateProperty in my custom code.

Discussion in 'Cinemachine' started by watsonsong, Mar 13, 2018.

  1. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    267
    I want to use AxisState as the Z axis input for camera distance, as the free look camera does not supply.
    When I add the AxisStateProperty tag to the AxisState SerializeField, the error as follow is report:

    Cinemachine.Editor.AxisStatePropertyDrawer.ValueRangeIsLocked (UnityEditor.SerializedProperty property) (at C:/ProgramData/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.1.12/Editor/PropertyDrawers/AxisStatePropertyDrawer.cs:72)
    Cinemachine.Editor.AxisStatePropertyDrawer.GetPropertyHeight (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at C:/ProgramData/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.1.12/Editor/PropertyDrawers/AxisStatePropertyDrawer.cs:62)
    UnityEditor.PropertyDrawer.GetPropertyHeightSafe (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at C:/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyDrawer.cs:36)
    UnityEditor.PropertyHandler.GetHeight (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at C:/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:216)
    ...


    This happened in the AxisStatePropertyDrawer class and GetPropertyHeight method, which use reflect to find a property:

    bool ValueRangeIsLocked(SerializedProperty property)
    {
    bool locked = false;
    PropertyInfo pi = typeof(AxisState).GetProperty(
    "ValueRangeLocked", BindingFlags.NonPublic | BindingFlags.Instance);
    if (pi != null)
    locked = bool.Equals(true, pi.GetValue(SerializedPropertyHelper.GetPropertyValue(property), null));
    return locked;
    }


    BTW, could the free look camera support a input to control the camera distance. So I can use the mouse wheel or the guesture on mobile phone the control the camera distance to the target.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,416
    I tried it with an empty project and the following test and got no errors. Could it be that you have a naming conflict in your project, possibly SerializedPropertyHelper?

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using Cinemachine;
    4.  
    5. public class AxisTest : MonoBehaviour
    6. {
    7.     [AxisStateProperty]
    8.     public AxisState m_VerticalAxis = new AxisState(-90, 90, false, false, 300f, 0.1f, 0.1f, "Mouse Y", true);
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.      
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update () {
    17.      
    18.     }
    19. }
    upload_2018-3-13_10-25-40.png
     
    Last edited: Mar 13, 2018
  3. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    267
    I am using the Unity2018.1beta10, and I reference the Cinemachine by the PackageManager.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,416
    Yes that is what I did too.