-
-
Notifications
You must be signed in to change notification settings - Fork 543
Open
Labels
bugSomething isn't workingSomething isn't working
Description
When an entity does not have a name assigned and is reusing an id of a previously destroyed entity, serializing and deserializng it with world.to_json()
creates a copy of it with a different id instead of overwriting the existing entity.
Example code:
#include "flecs.h"
#include <cstdio>
int main()
{
flecs::world world;
auto e1 = world.entity().add(flecs::Prefab);
printf("e1 id: %u\n", e1.id());
// e1 id: 540
e1.destruct();
auto e2 = world.entity().add(flecs::Prefab);
printf("e2 id: %u\n", e2.id());
// e2 id: 540
auto json = world.to_json();
printf("world.to_json(): %s\n", json.c_str());
// world.to_json(): {"results":[{"name":"#540", "id":540, "tags":["flecs.core.Prefab"]}]}
world.from_json(json);
json = world.to_json();
printf("world.to_json(): %s\n", json.c_str());
// world.to_json(): {"results":[{"name":"#540", "id":540, "tags":["flecs.core.Prefab"]}, {"name":"#541", "id":541, "tags":["flecs.core.Prefab"]}]}
world.from_json(json);
json = world.to_json();
printf("world.to_json(): %s\n", json.c_str());
// world.to_json(): {"results":[{"name":"#540", "id":540, "tags":["flecs.core.Prefab"]}, {"name":"#541", "id":541, "tags":["flecs.core.Prefab"]}, {"name":"#542", "id":542, "tags":["flecs.core.Prefab"]}]}
return 0;
}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working