#Working with manual entity prefab
1 messages ยท Page 1 of 1 (latest)
This is the specification of my character archetype:
Character Archetype:
Prefab // Prefab component from Unity.Entities
EnityTag // A shared component with value is either "Hero" or "Enemy"
CharacterIdComponent
LocalTransform
MovementSpeedComponent
DirectionComponent
HpComponent
AttackPowerComponent
AttackSpeedComponent
And this is the query:
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var options
= EntityQueryOptions.IncludePrefab
| EntityQueryOptions.IncludeDisabledEntities
| EntityQueryOptions.IgnoreComponentEnabledState
;
_query = QueryBuilder().WithOptions(options).WithAll<Prefab, EntityTag>().Build();
_query.SetSharedComponentFilter(EntityKind.Hero.AsTag()); // Set the shared EntityTag component
if (_query.IsEmpty)
{
UnityEngine.Debug.Log("Empty Query");
return;
}
var prefab = _query.GetSingletonEntity();
state.EntityManager.Instantiate(prefab);
}
The result is always Empty Query. I don't understand why is that. What should I do to get the prefab I want?
how do you even create your prefab?
Add the Prefab tag to the entity and you will have a prefab.
EntityManager.AddComponent<Unity.Entities.Prefab>(entity);
I just follow the recently updated Unity ECS samples
your entity doesn't match the query
well, that's what I'm asking here: why it doesn't match? ๐
QueryBuilder().WithOptions(options).WithAll<Prefab, EntityTag>().Build();
Btw, I think you should use SystemAPI instead
or it is already?
I'm using SystemAPI
using static Unity.Entities.SystemAPI;
ah
I couldn't figure why method is here out of nowhere ๐
hmm
try to explicitly specify SystemAPI
also, try removing disabled component
and just leave it as Prefab
this is not necessary tbh
did you check codegened part?
Prefab is automatically disabled, this is Unity mechanism
is it properly generated?
huh, I never noticed
Well, I know what I'm doing. But to assure you, I did use SystemAPI.QueryBuilder() too
I pass these options into the query builder, I expect they should be respected
var options
= EntityQueryOptions.IncludePrefab
| EntityQueryOptions.IncludeDisabledEntities
| EntityQueryOptions.IgnoreComponentEnabledState
;
did you check query without shared filter?
hmm
Mind showing generated code?
I feel like codegen gets borked if you use variables to specify options
hmm how to see that?
in rider you just ctrl + click on type declaration
it'll suggest other documents that declare this partial type
too bad I don't have rider
you can find it in explorer too
lemme remember the folder
C:\Users\username\AppData\Local\Temp\SourceGeneratedDocuments\D97F33D625EC816606B84DCC\
but I feel like VS should be able to inspect other declarations somehow
maybe you can just try doing this._somegeneratedquery and use VS somehow to get where it was declared?
can ILSpy work?
no, it's code, not assembly
oh, if you mean building it
and then inspecting, then yeah, but I wouldn't suggest it ๐
surely VS should support inspecting generated code
well the assembly is in the Project/Library/ScriptAssemblies folder in case you don't know
what should I look for then?
suppose I have the generated code
just how generated code looks
because generated code is what will run
not what you actually wrote
I do know about source generator ๐
what I mean is what should I look for in the generated code?
what do you want to see?
oh I see the options aren't passed into the query
wow thanks!
btw, my underlying code makes the prefab disabled, not Unity
just found this bug ๐
yeah, that seemed strange
runtime prefab creation is not really good idea in general, any specific idea you avoid baking?
well I'm free to do whatever I want atm
yes you are free to not use provided workflows and struggle for no reason.
that beeing said i do create a prefab myself too. dont know why its not working for you.
@desert pine have just helped me, the problem is the query options must be inline!
If I define a variable, it won't be passed into the query builder
next time inspect the query in the System debugger. that should have shown you whats wrong
hmm how to do that then?
do you mean this?
it doesn't show EntityQueryOptions though
if codegen failed for your query you wouldnt see one in here
that's right
btw I'm be more mindful about the generated code