Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Arch.Tests/WorldTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,19 @@ public void TryGet()
That(_world.TryGet(entity, out Rotation _), Is.EqualTo(false));
}

/// <summary>
/// Checks if the non-generic TryGet returns the stored component value.
/// </summary>
[Test]
public void TryGetByComponentType()
{
var entity = _world.Create(new Transform { X = 1, Y = 2 });

That(_world.TryGet(entity, (ComponentType)typeof(Transform), out var component), Is.EqualTo(true));
That(component, Is.EqualTo(new Transform { X = 1, Y = 2 }));
That(_world.TryGet(entity, (ComponentType)typeof(Rotation), out _), Is.EqualTo(false));
}

[Test]
public void TryGetRefSuccess()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Arch/Core/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,8 +1547,8 @@ public bool TryGet(Entity entity, ComponentType type, out object? component)

ref var chunk = ref slot.Archetype.GetChunk(slot.Slot.ChunkIndex);
Debug.Assert(compIndex != -1 && compIndex < chunk.Components.Length, $"Index is out of bounds, component {type} with id {compIndex} does not exist in this archetype.");
var array = Unsafe.As<object[]>(chunk.Components.DangerousGetReferenceAt(compIndex));
component = array[slot.Slot.Index];
var array = chunk.Components.DangerousGetReferenceAt(compIndex);
component = array.GetValue(slot.Slot.Index);
return true;
}

Expand Down
Loading