#Is there a way to try get an aspect from an Entity?

1 messages · Page 1 of 1 (latest)

languid swan
#

I noticed that neither EntityManager.TryGetAspect<T>(Entity entity, out T value) nor SystemAPI.TryGetAspectRO<T>(Entity entity, out T value>) does exists.

#

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

woeful vault
#

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 🤷

languid swan
#

Oh, ok

#

HasComponent<T> requires a generic, it doesn't accepts a ComponentType @woeful vault

woeful vault
#

there are 2 overloads without generic as well

#

unless they removed them after pre15 but that seems unlikely 😛

languid swan
#

Ohh, I was looking into SystemAPI, it seems there are not there but in EntityManager.
Thanks

woeful vault
#

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

languid swan
#

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

woeful vault
#

you were able to get the components used by the aspect?

languid swan
#

MyAspect.HasAspect(EntityManager, Entity)

woeful vault
#

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);
languid swan
#

So.. that gives true if the entity has the aspect?

#

Interesting

woeful vault
languid swan
#

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? 🤔