Search Unity

EditorJsonUtility.ToJson(CinemachineVirtualCamera); Doesn't seems to work

Discussion in 'Cinemachine' started by usernameHed, Mar 26, 2019.

  1. usernameHed

    usernameHed

    Joined:
    Apr 5, 2016
    Posts:
    93
    Hello, I am saving / loading monobehaviours scripts for some editor tools.
    and it works great, except for CinemachineVirtualCamera monobehaviour...

    When I save with EditorJsonUtility.ToJson(CinemachineVirtualCamera), here in the editor:


    and here is the json data saved :
    Code (CSharp):
    1. {"MonoBehaviour":{"m_Enabled":true,"m_EditorHideFlags":0,"m_Name":"","m_EditorClassIdentifier":"","m_ExcludedPropertiesInInspector":["m_Script"],"m_LockStageInInspector":[],"m_StreamingVersion":20170927,"m_Priority":11,"m_StandbyUpdate":2,"m_LookAt":{"instanceID":0},"m_Follow":{"instanceID":0},"m_Lens":{"FieldOfView":120.0,"OrthographicSize":10.0,"NearClipPlane":0.10000000149011612,"FarClipPlane":5000.0,"Dutch":0.0,"LensShift":{"x":0.0,"y":0.0}},"m_Transitions":{"m_BlendHint":0,"m_InheritPosition":false,"m_OnCameraLive":{"m_PersistentCalls":{"m_Calls":[]},"m_TypeName":"Cinemachine.CinemachineBrain+VcamActivatedEvent, Cinemachine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"}},"m_LegacyBlendHint":0,"m_ComponentOwner":{"instanceID":0}}}
    Here we can see the monobehaviour is saved, with the FOV 120 for exemple, but m_LookAt and m_Follow is set to 0, and I don't have all the other information of the tracked dolly and so on...

    When I try to load it from the Json, like that:
    EditorJsonUtility.FromJsonOverwrite(stringJsonVCam, cinemachineVirtualCamera);


    Here is the result:


    Exept the priority, and the FOV, the Follow/Lookat is gone, and no information in Body, Aim and Noise :/


    Ok, so my question is: first, why ?
    Secondly, how can I manage to save all data I need and get it back without EditorJsonUtility ?


    Thanks you ! :)
     
  2. usernameHed

    usernameHed

    Joined:
    Apr 5, 2016
    Posts:
    93
    Ok, my first tought is to do a GetCinemachineComponent<CinemachineTrackedDolly>() for exemple, and save this component. I will try to figure out a way.

    For the m_LookAt and m_Follow set to 0, it seems to be a bug, and I will save manually this data.
    From the CinemachineVirtualCamera, how can i know if the CinemachineVirtualCamera have a TrackedDolly, or a Transposer or other ? How can I access the enum ?

    I will work on that today and I'll keep you informed.
     
  3. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
  4. usernameHed

    usernameHed

    Joined:
    Apr 5, 2016
    Posts:
    93
    Thanks you Jakub, Now I have manage to Save the CinemachineTrackedDolly component by doing a GetCinemachineComponent<CinemachineTrackedDolly>() .

    But now, I would like to access the enum

    How can I do ? I could I gess create a special function who test every component with GetCinemachineComponent, and then determine the enum index.... But It would be great to access it directly...
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    You can get them all with a call to GetComponentsInChildren<CinemachineComponentBase>();
    You can't use GetComponents() directly because the Cinemachine subcomponents are on an invisible child of the vcam.