Always align newly created entities with the grid (#5915)

* align spawns with grids

* :godmode:

* Fix comment

* fix

* release notes
This commit is contained in:
Nemanja
2025-10-06 00:37:48 -04:00
committed by GitHub
parent ac45a0a64b
commit f75ce13f00
4 changed files with 7 additions and 6 deletions

View File

@@ -46,6 +46,7 @@ END TEMPLATE-->
### Bugfixes
* Fixed yaml hot reloading throwing invalid path exceptions.
* The `EntityManager.CreateEntityUninitialized` overload that uses MapCoordinates now actually attaches entities to a grid if one is present at those coordinates, as was stated in it's documentation.
### Other

View File

@@ -352,7 +352,9 @@ namespace Robust.Shared.GameObjects
throw new ArgumentException($"Attempted to spawn entity on an invalid map. Coordinates: {coordinates}");
EntityCoordinates coords;
if (transform.Anchored && _mapManager.TryFindGridAt(coordinates, out var gridUid, out var grid))
if (_mapManager.TryFindGridAt(coordinates, out var gridUid, out var grid)
&& MetaQuery.TryGetComponentInternal(gridUid, out var meta)
&& meta.EntityLifeStage < EntityLifeStage.Terminating)
{
coords = new EntityCoordinates(gridUid, _mapSystem.WorldToLocal(gridUid, grid, coordinates.Position));
_xforms.SetCoordinates(newEntity, transform, coords, rotation, unanchor: false);

View File

@@ -104,7 +104,7 @@ namespace Robust.Shared.GameObjects
/// <param name="prototypeName">Name of the <see cref="EntityPrototype"/> to spawn.</param>
/// <param name="coordinates">Coordinates to place the newly spawned entity.</param>
/// <param name="overrides">Overrides to add or remove components that differ from the prototype.</param>
/// <param name="rotation">Map rotation to set the newly spawned entity to.</param>
/// <param name="rotation">Local rotation to set the newly spawned entity to.</param>
/// <returns>A new uninitialized entity.</returns>
/// <remarks>If there is a grid at the <paramref name="coordinates"/>, the entity will be parented to the grid.
/// Otherwise, it will be parented to the map.</remarks>

View File

@@ -196,10 +196,8 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
var ent1 = sim.SpawnEntity(null, coordinates); // this raises MoveEvent, subscribe after
// Act
sim.System<MoveEventTestSystem>().ResetCounters();
sim.Transform(ent1).Anchored = true;
xformSys.AnchorEntity(ent1);
Assert.That(sim.Transform(ent1).ParentUid, Is.EqualTo(grid.Owner));
sim.System<MoveEventTestSystem>().AssertMoved();
traversal.Enabled = true;
}
@@ -497,7 +495,7 @@ namespace Robust.UnitTesting.Shared.GameObjects.Systems
// Act
sim.System<MoveEventTestSystem>().FailOnMove = true;
xformSys.Unanchor(ent1);
Assert.That(sim.Transform(ent1).ParentUid, Is.EqualTo(mapSys.GetMap(coordinates.MapId)));
Assert.That(sim.Transform(ent1).ParentUid, Is.EqualTo(grid.Owner));
sim.System<MoveEventTestSystem>().FailOnMove = false;
traversal.Enabled = true;
}