The Scene culling mask defined for the GameObject. (Read Only)
Unity uses SceneCullingMasks to determine which scene to render the GameObject in. The sceneCullingMask
is a bitfield stored as an unsigned 64-bit integer ulong. Cameras only render an object in a scene if the bits set on the Scene's mask (retrievable withEditorSceneManager.GetSceneCullingMask) match those in the object's sceneCullingMask
.
using UnityEngine; using UnityEditor.SceneManagement;
[ExecuteInEditMode] public class ExampleClass : MonoBehaviour { void Start() { //Check if gameObject is visible in scene if(gameObject.sceneCullingMask == EditorSceneManager.GetSceneCullingMask(gameObject.scene)) { Debug.Log("Object is visible"); } else { Debug.Log("Object is not visible"); } } }
Additional resources: SceneCullingMasks, Camera.overrideSceneCullingMask, EditorSceneManager.SetSceneCullingMask