mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Add EnsureComponent(ref Entity<T?>) (#4516)
This commit is contained in:
@@ -699,6 +699,26 @@ namespace Robust.Shared.GameObjects
|
||||
return AddComponent<T>(uid);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool EnsureComponent<T>(ref Entity<T?> entity) where T : IComponent, new()
|
||||
{
|
||||
if (entity.Comp != null)
|
||||
{
|
||||
// Check for deferred component removal.
|
||||
if (entity.Comp.LifeStage <= ComponentLifeStage.Running)
|
||||
{
|
||||
DebugTools.AssertOwner(entity, entity.Comp);
|
||||
return true;
|
||||
}
|
||||
|
||||
RemoveComponent(entity, entity.Comp);
|
||||
}
|
||||
|
||||
entity.Comp = AddComponent<T>(entity);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool EnsureComponent<T>(EntityUid entity, out T component) where T : IComponent, new()
|
||||
|
||||
Reference in New Issue
Block a user