Forum rules - please read before posting.

Camera switch issue

Hello,

I have a problem with the camera layers when switching to another camera.

In my scene I have created 2 cubes and 2 cameras and I have set different layers for each cube, so that camera 1 can only see for example ( the red cube) and camera 2 only sees (the blue cube) however, the issue is when switching from camera 1 to camera 2, there is a millisecond time that camera 2 will see the red cube which is only camera 1 is supposed to see and vice versa. Please find the attached video for more details.
Unity version: 2021.
AC: Latest.

Comments

  • I'm not clear of the scene's layout - are these two cubes next to each other, and is this a case of using the Camera's Culling Mask to affect what it can render?

    The MainCamera does not update its own Culling Mask when switching GameCamera - are you using a custom script to transfer its values?

  • Yes the 2 cubes are next to each other and yes I’m using Camera’s culling mask.

    I’m only using a script called “ac culling” on the main camera so that other game cameras can have their own culling mask
  • I would need to see the script, in that case.

  • `using UnityEngine;
    using AC;

    public class AC_CameraCulling : MonoBehaviour
    {
    //AC main Camera
    MainCamera _mainCamera;

    void Awake()
    {
        //get the AC Main Camera component from the current Unity MainCamera.
        _mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<MainCamera>();
    }
    
    void Update()
    {
        if (_mainCamera.attachedCamera != null)
        {
            Camera.main.backgroundColor = _mainCamera.attachedCamera.GetComponent<Camera>().backgroundColor;
            Camera.main.cullingMask = _mainCamera.attachedCamera.GetComponent<Camera>().cullingMask;
    
            //add more properties here if you want.
        }
    }
    

    }`

  • This is the script

  • You might get by with replacing "Update" with "LateUpdate", but it may be better to rewrite it to involve use of the OnSwitchCamera custom event:

    using UnityEngine;
    using AC;
    
    public class AC_CameraCulling : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnSwitchCamera += SwitchCamera; }
        private void OnDisable () { EventManager.OnSwitchCamera -= SwitchCamera; }
    
        private void SwitchCamera (_Camera old, _Camera newCamera, float tt)
        {
            Camera.main.backgroundColor = newCamera.Camera.backgroundColor;
            Camera.main.cullingMask = newCamera.Camera.cullingMask;
        }
    
    }
    
  • I have tested the script and it works well so far. I will do more testing and inform you back. Thank you for your hard work.
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.