Forum rules - please read before posting.

Cinemachine workflow

I'll share here what's my workflow (workaround) for using cinemachine and timeline with AC, and see if it's the optimal way of integrating both.
Basically I use the AC camera as the brain, set my gameCamera (currently opsive's TPS) as as an external cinemachine camera, and disabling the cinemachine component on every other virtual camera, and use an AC action to set the priority of the virtual cameras and enabling them if I need them on the gameplay. My action

using UnityEngine;
using System.Collections;
using Cinemachine;

#if UNITY_EDITOR
using UnityEditor;
namespace AC
{

    [System.Serializable]
    public class ActionCinemachineCamera : Action
    {

        // Declare variables here
        public CinemachineVirtualCameraBase CM_cam;
        public int Priority;

        public ActionCinemachineCamera()
        {
            this.isDisplayed = true;
            category = ActionCategory.Camera;
            title = "CM Priority";
            description = "Changes CM priority";
        }


        override public float Run()
        {
            if (CM_cam)
            {
                if (CM_cam.GetComponent<CinemachineVirtualCameraBase>())
                {
                    CM_cam.GetComponent<CinemachineVirtualCameraBase>().enabled = true;
                    CM_cam.MoveToTopOfPrioritySubqueue();
                }
                CM_cam.Priority = Priority;
            }
            return 0f;
        }


#if UNITY_EDITOR

override public void ShowGUI ()
{
            CM_cam = (CinemachineVirtualCameraBase)EditorGUILayout.ObjectField("CM Camera:", CM_cam, typeof(CinemachineVirtualCameraBase), true);
            Priority = EditorGUILayout.IntField("Priority:", Priority);
            AfterRunningOption();
}

public override string SetLabel ()
{
string labelAdd = "Changes virtual camera priority and moves to top queue";
return labelAdd;
}


    }

}
This way I can use Cinemachine in timeline, custom cameras and also cinemachine cameras during gameplay. Any drawbacks ? Suggestions ? What is your way ?

Comments

  • Looks good to me!  It'd be very welcome on the community wiki.
  • Can you do it ? I have no idea how to post it there.
  • Hi Guys,
    Thanks for putting this together. I'm looking into extending this so that in integrates with AC's Default Camera Switch Action.

    I'd like to have it detect whether the cam has a cinemachine component on it, and if it does, raise the priority, while also switching the cam.

    Then I'd like to have it revert the priority back to the original number.

    I've been hunting around for the default Camera Switch Action code. I think taking it as a base, it should be fairly simple to put the rest together. Do you know wher eI can find it?

    Thanks!

  • Sounds intereseting, @juanelo_dev.

    You can edit the script of any Action via its cog menu in the ActionList Editor window. The Camera: Switch Action is stored in ActionCamera.cs - which you can subclass if you want to make an Action that derives from it.

    However, it's not just the Action that's used to switch camera - cameras are also set when entering scenes, and loading save games. From what you've described, it would be better to hook into the OnSwitchCamera custom event instead - which will allow you to run custom code whenever the camera is set. Something like:

    using UnityEngine;
    using AC;
    
    public class SetCMPriority : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnSwitchCamera += SwitchCamera; }
        private void OnDisable () { EventManager.OnSwitchCamera -= SwitchCamera; }
    
        private void SwitchCamera (_Camera old, _Camera newCamera, float tt)
        {
            // Check if newCamera has a Cinemachine component here
        }
    
    }
    
  • This is great, @ChrisIceBox. Thanks!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.
Do NOT follow this link or you will be banned from the site!