Entt: How can I create an Instance of the Reflected Type using the Name?

Created on 8 Jun 2019  路  2Comments  路  Source: skypjack/entt

Say I have a PositionComponent and I use the Following Methods mentioned in the wiki to regsiter and resolve the entt_type from the name, like So:

//Register PositonComponent by name
entt::meta_factory<PositionComponent> factory = entt::reflect<PositionComponent>("PositionComponent");
//Reslove PositionComponent by Name.
        entt::meta_type type = entt::resolve("PositionComponent");

How do I create a normal C++ Object of PositionComponent from the name alone? I'm storing the Component names in a JSON by Entities and deserializing it to create the Entities at Runtime and I don't know the Real Type of the Components.

And Is there is a Gitter or DIscord for Entt? Or should I use the Issues?

question

All 2 comments

Sure, here is the direct link to the gitter channel.


Is your goal to read a component from json and create it directly into the registry? This is definitely possible.
You can attach fake member functions to meta types. In particular, you can attach a function that accepts a registry, an entity and an any object, then assigns the component to the entity. Otherwise you can create a fake member that works directly with a json representation. And so on, there are several approaches to achieve it.
To generate components for the first case, remember that meta types have a construct member function to create objects (returned as meta any instances). You can look at the test suite for some examples of use.

Welcome on gitter. :wink:
I'm closing this issue, we can continue to discuss it directly in the channel. :+1:
If you feel like you want to reopen this for some reasons, feel free to do it.

Was this page helpful?
0 / 5 - 0 ratings