Files
sbox-public/engine/Sandbox.Engine/Scene/GameObject/GameObject.Flags.cs
Sam Pavlovic 862028291f Static GameObjects (#5256)
* Mark MeshComponents and ModelRenderer GameObjects that have no behavour as static and make them render under Static SceneObject layers

https://files.facepunch.com/sampavlovic/1b2211b1/wpaNd6VF6L.png

* Remove IsHierarchyStatic, just use and implement GameObject.IsStatic

* Hide tick icon since we drive the enabled state of this widget

* Static GameObjects get static physics bodies and skip transform interpolation

* Revert Static menu option for GameObject, redundant since we have a button
2026-07-07 10:40:23 +01:00

123 lines
2.8 KiB
C#

namespace Sandbox;
[Flags]
public enum GameObjectFlags
{
None = 0,
/// <summary>
/// Hide this object in hierarchy/inspector
/// </summary>
Hidden = 1,
/// <summary>
/// Don't save this object to disk, or when duplicating
/// </summary>
NotSaved = 2,
/// <summary>
/// Auto created - it's a bone, driven by animation
/// </summary>
Bone = 4,
/// <summary>
/// Auto created - it's an attachment
/// </summary>
Attachment = 8,
/// <summary>
/// There's something wrong with this
/// </summary>
Error = 16,
/// <summary>
/// Loading something
/// </summary>
Loading = 32,
/// <summary>
/// Is in the process of deserializing
/// </summary>
Deserializing = 64,
/// <summary>
/// When loading a new scene, keep this gameobject active
/// </summary>
DontDestroyOnLoad = 128,
/// <summary>
/// Keep local - don't network this object as part of the scene snapshot
/// </summary>
NotNetworked = 256,
/// <summary>
/// In the process of refreshing from the network
/// </summary>
[Obsolete]
Refreshing = 512,
/// <summary>
/// Stops animation stomping the bone, will use the bone's local position
/// </summary>
ProceduralBone = 1024,
/// <summary>
/// Only exists in the editor. Don't spawn it in game.
/// </summary>
EditorOnly = 2048,
/// <summary>
/// Ignore the parent transform. Basically, position: absolute for gameobjects.
/// </summary>
Absolute = 4096,
/// <summary>
/// The position of this object is controlled by by physics - usually via a RigidBody component
/// </summary>
PhysicsBone = 8192,
/// <summary>
/// Stops this object being interpolated, either via the network system or the physics system
/// </summary>
NoInterpolation = 16384,
/// <summary>
/// This object never moves during gameplay. Applies to children too.
/// Lets rendering, physics and navmesh make static optimizations.
/// </summary>
Static = 32768,
}
public partial class GameObject
{
public GameObjectFlags Flags { get; set; } = GameObjectFlags.None;
/// <summary>
/// True if this GameObject is being deserialized right now
/// </summary>
public bool IsDeserializing => Flags.Contains( GameObjectFlags.Deserializing );
/// <summary>
/// This object never moves during gameplay, letting rendering, physics and navmesh
/// make static optimizations. Children inherit this via <see cref="GameObjectFlags.Static"/>
/// on any ancestor.
/// </summary>
public bool IsStatic
{
get => HasFlagOrParent( GameObjectFlags.Static );
set => Flags = Flags.WithFlag( GameObjectFlags.Static, value );
}
/// <summary>
/// Do we or our ancestor have this flag
/// </summary>
internal bool HasFlagOrParent( GameObjectFlags f )
{
if ( Flags.Contains( f ) ) return true;
if ( Parent is null ) return false;
return Parent.HasFlagOrParent( f );
}
}