diff --git a/src/OECS/World.cs b/src/OECS/World.cs index badbf23..2435b0d 100644 --- a/src/OECS/World.cs +++ b/src/OECS/World.cs @@ -251,14 +251,14 @@ public class World : IDisposable _changes.Pending.MarkComponentRemoved(entity, typeof(T)); } + /// /// /// Returns a reference to the component of type /// for the given entity. Throws if the entity does not have the component. /// - /// During iteration (inside or a Select loop), - /// components accessed through this method are automatically marked as - /// modified when the iteration scope ends. Outside of iteration, - /// must be called explicitly. + /// During iteration, this access is auto-marked as modified since it + /// returns a mutable ref. Use if you + /// only need to read the value. /// public ref T GetComponent(Entity entity) where T : struct { @@ -267,10 +267,21 @@ public class World : IDisposable return ref _components.Get(entity); } + /// + /// Returns a copy of the component of type + /// for the given entity. Never auto-marks as modified — use this when + /// you only need to read the value. + /// + public T ReadComponent(Entity entity) where T : struct + { + return _components.Get(entity); + } + /// /// Tries to get the component of type for the /// given entity. Returns true and copies the value to /// if the component exists; otherwise returns false. + /// Never auto-marks as modified. /// public bool TryGetComponent(Entity entity, out T value) where T : struct { @@ -352,7 +363,7 @@ public class World : IDisposable /// /// Returns a reference to the singleton component of type . - /// Throws if the singleton has not been set. + /// Throws if the singleton has not been set. Auto-marks as modified during iteration. /// public ref T GetSingleton() where T : struct { @@ -360,6 +371,16 @@ public class World : IDisposable return ref GetComponent(SingletonEntity); } + /// + /// Returns a copy of the singleton component of type . + /// Never auto-marks as modified — use this when you only need to read the singleton. + /// + public T ReadSingleton() where T : struct + { + EnsureSingleton(); + return ReadComponent(SingletonEntity); + } + /// /// Returns true if a singleton component of type exists. ///