-
Hello, I recently started to play with Flecs and I have a question regarding the creation of entities. I have a "Task" system that is responsible for spawning some enemies. void SpawnEnemies(ecs_iter_t *it)
{
...
ecs_entity_t enemy = ecs_new_w_pair(it->world, EcsIsA, enemyPrefab);
ecs_set(it->world, enemy, Position, {x, y});
....
} When executing, I'm getting the following error From what I understand, it's because the entity is not created directly (because the world is in readonly) and when I'm trying to set the component values, the entity id not considered valid. Is it a correct pattern to create entity and set component values from inside a system ? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This should work, as long as the system is not multi threaded. |
Beta Was this translation helpful? Give feedback.
Thanks for you answer.
I tried to switch the system to immediate and it didn't work.
I tried with
ecs_defer_suspend/resume
and it didn't work.After checking the component id in my system i realized the problem was somewhere else. It was coming from the way I defined the
Position
component. I declared it withECS_COMPONENT_DECLARE(Position)
before my system function. Then I defined it later in my main function usingECS_COMPONENT(world, Position);
Replacing
ECS_COMPONENT(world, Position);
byECS_COMPONENT_DEFINE(world, Position);
fixed the issue.Here was my test