CPP
50
FLECS system builder bug
Guest on 19th May 2022 09:25:45 AM
//.h
struct CompA
{
float value;
};
struct CompB
{
float value;
};
struct Spawner
{
flecs::entity Prefab;
};
struct SuperCompA
{
float Value;
};
UCLASS()
class ECSGAMEPLAY_API UFLECS_Test : public UFlecsModuleBase
{
GENERATED_BODY()
virtual void Initialize(flecs::world& world) override;
};
//.cpp
void Spawn(flecs::iter& It)
{
auto world = It.world();
auto spawner = It.term<Spawner>(1);
for (auto i : It)
{
world.entity()
.is_a(spawner->Prefab)
.set<SuperCompA>({3.f});
It.entity(i).destruct();
}
}
void GameUpdate(flecs::iter& It)
{
}
void UFLECS_Test::Initialize(flecs::world& world)
{
world.component<CompA>();
world.component<CompB>();
world.component<Spawner>();
world.component<SuperCompA>();
world.entity("Game")
.set<CompA>({})
.set<CompB>({});
auto spaceshipPrefab = world.prefab()
.set<SuperCompA>({});
world.entity().set<Spawner>(
{spaceshipPrefab});
world.system<Spawner>()
.iter(Spawn);
world.system<>()
.term<CompB>().subj("Game")
.term<SuperCompA>().super()
.iter(GameUpdate);
}