Skip to content

Commit

Permalink
use TQueryData for single()
Browse files Browse the repository at this point in the history
  • Loading branch information
andreakarasho committed Jan 27, 2025
1 parent 0c509dc commit 6b8b3d8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Bevy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,14 @@ public static ISystemParam<World> Generate(World arg)

public TQueryData Iter(EcsID id) => TQueryData.CreateIterator(_query.Iter(id));

public ref T Single<T>() where T : struct
=> ref _query.Single<T>();

public EntityView Single()
=> _query.Single();
public TQueryData Single()
{
EcsAssert.Panic(_query.Count() == 1, "'Single' must match one and only one entity.");
var enumerator = GetEnumerator();
var ok = enumerator.MoveNext();
EcsAssert.Panic(ok, "'Single' is not matching any entity.");
return enumerator;
}

public int Count()
=> _query.Count();
Expand Down

0 comments on commit 6b8b3d8

Please sign in to comment.