Forum rules - please read before posting.

Camera to another camera with different culling mask

Hi everyone

I have a simple 2D game which, upon finishing some dialogue would switch to a camera that only culls a certain UI layer to get rid of the backgrounds and the game world etc, only the new UI for a canvas. However upon the game switching to the new camera, it still culls everything.

I think it's to do with the main camera because by default it culls everything and if I just enable the disabled camera component on my new camera then it works as intended but obviously that isn't how AC works... just looking for advice on this?

Using AC 1.73.8

Thanks so much

Comments

  • When switching camera, the MainCamera will adopt the new camera's position, rotation and FOV values - but not the culling mask.

    You can, however, hook a custom script into the OnSwitchCamera custom event to do automate this:

    using UnityEngine;
    using AC;
    
    public class UpdateCullingMask : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnSwitchCamera += SwitchCamera; }
        private void OnDisable () { EventManager.OnSwitchCamera -= SwitchCamera; }
    
        private void SwitchCamera (_Camera old, _Camera newCamera, float tt)
        {
            KickStarter.mainCamera.Camera.cullingMask = newCamera.Camera.cullingMask;
        }
    
    }
    
  • edited September 2021

    Hey Chris,
    Thanks for that! I am a bit stuck hooking it into the onswitchcamera custom event though, I havent done it before and the links you sent go past me. I made a script with the code you sent me but I'm lost from there (sorry i'm dumb as hell)

    Edit: Oh I just had to add the game object with the script to the scene...? It works but I feel like i'm missing something or is that it? :D

  • So long as the script is present in the scene, it'll work.

    The script itself is just an example, though - you may want to adapt it to only work when transitioning to/from a specific camera, as currently the script will work for all cameras.

  • Hi,

    I recently noticed this script has stopped working. I have updated to the newer version of AC in the meantime (v.1.78.4 and Unity 2022.3.0), could that be the reason? How do I fix that? This resulted in massive performance drop because all scene cameras are rendering every layer again...

  • The event is the same - what's the exact behaviour you get?

    All the script does is copy the active GameCamera's Culling Mask over to the MainCamera - it won't affect what layers are renderered by the GameCameras, whose Camera components should be disabled.

  • You're right - it does still work. Except it turns out the new non-AC camera that I've recently added to the scene to render mirror texture breaks things a bit... But once I turned it off and on again the game started respecting the GameCamera's Culling Mask again. It's still a little wonky, though - sometimes it culls, sometimes it doesn't...

    This non-AC camera has Universal Additional Camera Data (Script) component on it. Is that something AC adds automatically or is it a Unity thing? (was thinking maybe that was causing it).

    Anyway, all my GameCameras have Camera component disabled by default. I thought that was intended since when you create one it is always this way and if you enable it, it shows up in game window instead of showing what MainCamera is seeing (which is useful sometimes).

  • Univeral Additional Camera Data is part of Unity, added automatically depending on your render pipeline.

    I'm not 100% clear on your issue, but if you pause the game when it occurs, check the Inspectors of your various Camera components. The script above doesn't affect anything that isn't visible in the Camera Inspector, so you should be able to compare Inspectors to see what's set up in the wrong way.

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.