#TryGet / Has for Aspect Lookups?

1 messages · Page 1 of 1 (latest)

past halo
#

I just started using Aspect lookups but noticed they don't have anything like TryGetAspect~ or HasAspect~. Meaning the exception they throw is the only safety-net. This means use cases where failing lookups are expected aren't possible. Is there a correct way to do this?

Thanks!

simple pagoda
# past halo I just started using Aspect lookups but noticed they don't have anything like Tr...

Did you see the samples? https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/Docs/examples/components_systems.md

Aspects

These methods return instances of an aspect:
SystemAPI.GetAspectRW<T>(Entity)
SystemAPI.GetAspectRO<T>(Entity)
EntityManager.GetAspect<T>(Entity)
EntityManager.GetAspectRO<T>(Entity)
These methods throw if the Entity passed doesn't have all the components included in aspect T.
So this seems like the intended behavior and way of doing things to me, but I'm not a DOTS pro.

past halo
#

I had a hard time finding examples of Aspect lookups. Ended up cobbling my impl together from a few forum posts.

ISystem Member

[NativeDisableContainerSafetyRestriction] [ReadOnly] private FooAspectRO.Lookup _fooLookup;

in ISystem::OnCreate

_fooLookup = new FooAspect.Lookup(ref state, true);

in ISystem::OnUpdate

_fooLookup.Update(ref state)

in IJobEntity

[NativeDisableContainerSafetyRestriction] [ReadOnly] public FooAspect.Lookup FooLookup;

...

FooAspect foundAspect = FooLookup[entityToFind];
low pecan
#

TransformAspect.Lookup

#

it's nested type

past halo
simple pagoda
past halo
#

I assume they just failed to codegen those validity check methods. Maybe it is coming in a future update with more aspect polish.

sonic sorrel
#

I manually wrote these extensions for transform aspect

#

But yeah not a universal solution

#

I too found it weird they were missing

oak ivy
#

I ran into the same issue. To add to the list of options I am using an EntityQuery for the entitylist to check if its on there and then getting it from the lookup with that same entity.

Query.ToEntityArray(Allocator.Temp).Contains(myEntity)```