#Is there a way to try get an aspect from an Entity?
1 messages · Page 1 of 1 (latest)
Actually, there are no TryGetComponent either... so how can I check if a given entity does have one?
Oh, I see there is HasComponent, but no HasAspect
I don't see anything either
aspects have a ComponentType[] RequiredComponents, you could create a helper function that checks all the component types one by one 🤷
Oh, ok
HasComponent<T> requires a generic, it doesn't accepts a ComponentType @woeful vault
there are 2 overloads without generic as well
unless they removed them after pre15 but that seems unlikely 😛
Ohh, I was looking into SystemAPI, it seems there are not there but in EntityManager.
Thanks
btw @languid swan what version of entities do you use? now, in pre65, I dont have the RequiredComponents on my aspect anymore so I am a little confused myself 😂
In pre65, EntityQueryBuilder now has a WithAspect<T>() to help out; I would expect the entitymanager has similar helpers
on the aspect there's also a generated enumerator that takes a query
1.0.0-pre.65
In order to check if the entity has the aspect or not, I used EntityManager.HasComponent(Entity, ComponentType) per component in the aspect
you were able to get the components used by the aspect?
I hardcoded that manually as an static method in my aspect
MyAspect.HasAspect(EntityManager, Entity)
I found another way, too, using EntityQueryMask
EntityQuery aspectQuery = new EntityQueryBuilder(Allocator.Temp).WithAspect<CharacterAspect>().Build(EntityManager);
EntityQueryMask aspectQueryMask = aspectQuery.GetEntityQueryMask();
bool hasAspectIgnoreFilter = aspectQueryMask.MatchesIgnoreFilter(myEntity);
yes, but ignoring any filter on the query and includes disabled components
mm, no idea what are filters actually, I guess I'll have to read doc haha.
Though, when you put an aspect in a IJobEntity.Execute, does it includes aspects with disabled components or not? I mean, does this uses the same criteria than IJobEntity? 🤔