#TryGet / Has for Aspect Lookups?
1 messages · Page 1 of 1 (latest)
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.
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];
lookups for aspects are code gened
TransformAspect.Lookup
it's nested type
Surprising expert knowledge about aspect 'existence' on an entity is needed for usage. I assume try/catch doesn't work in Burst?
Yeah, afaik that doesn't work, so probably your supposed to never ask an Aspect of an entity that doesn't have all the required components.
But as I said, I'm not a DOTS pro, and were getting in that territory, so I think waiting for someone more knowledgeable would be the best idea.
I assume they just failed to codegen those validity check methods. Maybe it is coming in a future update with more aspect polish.
I manually wrote these extensions for transform aspect
But yeah not a universal solution
I too found it weird they were missing
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)```