Hey, I had a few questions regarding the future plans for Aspects. I hope it was okay to include them all in this thread.
Are there any plans to allow multiple aspects in the same query with overlapping components?
Aspects can include a lot of components which makes it easy to run into situations where multiple aspects both include the same component type in the same job. This results in errors at runtime.
Now, this might be a code smell and an indication of a code architecture problem, however, it is quite easy to run into even with the new TransformAspect. Specifically, the TransformAspect has a private RefRW field that it uses internally. Unlike the other fields, this one has no setter. This means that the job using the TransformAspect has no way to write to this component from another aspect or by directly using the ParentTransform in the job. This wouldn’t be a problem if aspects could have overlapping components.
Will SystemAPI.QueryBuilder get support for adding Aspects?
This would be useful for the rare times that you need to use IJobChunk and manually provide the query. We can get around this by using EntityQueryDesc and IAspect.RequiredComponents, but this isn’t burst compatible and requires digging through the aspect codegen to even know it exists.
Will we be able to use IAspect.Lookup inside of IJobEntity?
Transform.Lookup seems to work fine, but user-created aspects throw an error when you try to add it as a field to the job (SGJE0009: MySystem.MyJob contains non-value type field lookup.). This makes it impossible to lookup aspects on arbitrary entities inside of an IJobEntity.
Can we get IAspect.Lookup.HasAspect() and IAspect.Lookup.TryGetAspect()?
The codegen for IAspect.Lookup provides an indexing operator to lookup the aspect for a specific entity. Can we also get methods to check if an entity has an aspect or try-get it?
Hi Scott!
We’ve fixed 1 and 2 for our next release (sometime in late January I believe) and both 3 and 4 are currently being fixed/added. I cannot guarantee 3 and 4 will make it to our next release however.
Let me know if you have any further questions on these!
For 1, what does that mean exactly?
a) Multiple aspects can be included in a query even if they have an overlapping optional component.
b) Multiple aspects can be included in a query even if they have an overlapping required component.
c) An aspect containing a component can be included in a query with the raw component (e.g. LocalTransform + TransformAspect).
d) All of the above but also for EnabledRefRO/EnabledRefRW fields.
e) Everything!
a) yes, if one is optional and the other is required, the component becomes required.
b) yes. yes EntityQueryBuilder.WithAspect() will not add 2 of the same component type.
c) yes. Just make sure to call WithAspect() after any WithAll() on your EntityQueryBuilder as WithAll() will add duplicate component type but not WithAspect().
For instance:
var queryBad = new EntityQueryBuilder(Allocator.Temp).WithAspect<TransformAspect>().WithAll<LocalTransform>().Build();
var queryGood = new EntityQueryBuilder(Allocator.Temp).WithAll<LocalTransform>().WithAspect<TransformAspect>().Build();
d) yes, DynamicBuffer and SharedComponent as well
e) also yes
I dont think there is anything to it. You just go void Execute(ref MyAspect it) { }. Of course you use ref or in depending on wheter you want it to be readonly or not.