Forum rules - please read before posting.

Cinemachine camera with Hotspot's "Limit to camera"

I wanted to change to use Cinemachine cameras since they offer so much more than the AC cameras, but not it seems that some of the logic in hotspots no longer work. I can't just add the Cinemachine virtual camera into the hotspot in the inspector. Do anyone have any suggestions to fix this?

Comments

  • edited November 2020

    See the Manual's "Adding custom cameras" chapter: attaching an AC "Basic camera" component to a custom camera type will make it selectable in AC camera fields such as the Hotspot's "Limit to camera" field.

    However, this technique only works if you're still using AC's MainCamera to perform the actual rendering - as outlined in the "Working with Cinemachine" chapter.

    In that suggested workflow, the Cinemachine Brain is treated like a regular AC GameCamera that the AC MainCamera can attach itself to. Which CM Virtual Camera is then used is then independent from AC.

    A quick-hack way around this would be to rely on an Interactive Boundary for the Hotspot instead, so that it's activation is dependent on the Player's position rather than the active camera.

    Otherwise, you'll have to update the Hotspot when switching to/from the Virtual Camera in question. This can be done with the Object: Send message Action (Turn On / Turn Off), or through script.

  • I tried the script in AC wiki to set priorities. It works perfectly fine the way it is, but when I parameterized it, it only worked once. Do you have any ideas why?

  • edited November 2020
    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using Cinemachine;
    
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
        [System.Serializable]
        public class ActionCinemachineCamera : Action
        {
            // Declare variables here
            public GameObject CM_cam;
            public int priority;
            public int constantID_CM_cam;
            public int parameterID_CM_cam, parameterID_priority = -1;
    
            public ActionCinemachineCamera()
            {
                this.isDisplayed = true;
                category = ActionCategory.Camera;
                title = "CM Priority";
                description = "Changes CM priority";
            }
    
            override public void AssignValues(List<ActionParameter> parameters) {
                CM_cam = AssignFile(parameters, parameterID_CM_cam, constantID_CM_cam, CM_cam);
                priority = AssignInteger(parameters, parameterID_priority, priority);
            }
    
            override public float Run()
            {
    
                if (CM_cam)
                {
                    if (CM_cam.GetComponent<CinemachineVirtualCameraBase>())
                    {
                        CM_cam.GetComponent<CinemachineVirtualCameraBase>().enabled = true;
                        CM_cam.GetComponent<CinemachineVirtualCameraBase>().MoveToTopOfPrioritySubqueue();
                    }
                    CM_cam.GetComponent<CinemachineVirtualCameraBase>().Priority = priority;
                }
                return 0f;
            }
    
            #if UNITY_EDITOR
    
            override public void ShowGUI (List<ActionParameter> parameters)
            {
                parameterID_CM_cam = Action.ChooseParameterGUI("Interaction System:", parameters, parameterID_CM_cam, ParameterType.GameObject);
                if (parameterID_CM_cam >= 0) {
                        constantID_CM_cam = 0;
                        CM_cam = null;
                } else  {
                    CM_cam = EditorGUILayout.ObjectField("CM Camera:", CM_cam, typeof(GameObject), true) as GameObject;
                    constantID_CM_cam = FieldToID(CM_cam, constantID_CM_cam);
                    CM_cam = IDToField(CM_cam, constantID_CM_cam, true);
                }
                parameterID_priority = Action.ChooseParameterGUI("Interaction System:", parameters, parameterID_priority, ParameterType.Integer);
                if (parameterID_priority >= 0) {
                        priority = -1;
                } else  {
                    priority = EditorGUILayout.IntField("Priority:", priority);
                }
    
                AfterRunningOption();
            }
    
            public override string SetLabel ()
            {
                string labelAdd = "Changes virtual camera priority and moves to top queue";
                return labelAdd;
            }
    
            #endif
        }
    }
    
  • I've updated the wiki script with parameter support - give it another try.

  • Now it works perfectly! Thanks!

  • Hi again, I tried to use Basic camera script with Cinemachine brain and set the script execution order of State handler larger that Cinemachine scripts, but I get no display and and error saying this:

    NullReferenceException: Object reference not set to an instance of an object
    AC.KickStarter.get_CameraMainTransform () (at Assets/AdventureCreator/Scripts/Game engine/KickStarter.cs:1093)
    AC.PlayerInput._FixedUpdate () (at Assets/AdventureCreator/Scripts/Controls/PlayerInput.cs:1992)
    AC.StateHandler.FixedUpdate () (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:352)
    

    I do like to use Cinemachine for the more options it offers, but still want to use AC cameras in close ups, so I can tie most of the hotspots to certain cameras.

  • Problem seems to be that AC turns off the Main camera. After turning it on manually, there's no problem, but every time I turn on Play mode AC turns the camera off.

  • Also the Camera switch doesn't refresh Hotspots with the Camera limit.

  • And after updating to AC 1.72.4 camera switches don't work at all.

  • I have to turn on the camera via script on start, but there is no camera switch. The hotspots connected to camera are turned on though. The debug shows that the camera switch has the correct camera name, but when turning on the right camera manually, the gameplay interaction works as if in the main camera - so that mouse clicks and hotspots appear in main camera configuration. Any ideas what's wrong?

  • I get no display and and error saying this:

    First of all, uncheck Cache 'Camera.main' variable? in your Settings Manager.

    AC turns off the Main camera.

    Your Main camera should still be the AC MainCamera. If you're using the Cinemachine Brain like a regular AC GameCamera (by attaching the Basic Camera component), then the Camera should be disabled at runtime so that the AC MainCamera can perform the rendering, while "attaching" itself to the CM Brain for reference.

    If your MainCamera is not the same as the AC MainCamera, then that'll likely be related to the switching / mouse clicks issue as well. Reconfigure your cameras as above, and share more details on the way things are set up if you continue to have trouble.

  • The Cache 'Camera.main' variable? was off already. Brain camera was the main camera and I created another Main camera for AC. Still I need to run the script that turns on the main camera and then switches to Brain camera. After that everything seems to work fine.

  • I would still recommend having AC as the MainCamera, not the Brain camera - but if things are working now, they're working.

  • AC is the main camera. Brain is now a child camera of AC.

  • What scripts you should have on these cameras? Maybe there's a script missing?

  • It typically shouldn't be - the two should be separate, with the AC MainCamera attaching itself to the Brain camera as it would any other GameCamera.

  • Well I mean that it has the Basic camera script and now I can switch cameras with AC.

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.