Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Casting an object instance to be the type stored in rttr::type #368

Open
killereks opened this issue Dec 9, 2023 · 0 comments
Open

Casting an object instance to be the type stored in rttr::type #368

killereks opened this issue Dec 9, 2023 · 0 comments

Comments

@killereks
Copy link

I have this piece of code, I need to automatically be able to modify values of their components. My components all derive from Component class, e.g. MeshComponent : Component, TransformComponent : Component.

I found that when casting component to (MeshComponent*) and then doing set_value works, but how would I automatically convert this to the correct type? I have tried using var.convert(type); but that just returns 0, is it because type is not a pointer?

for (Component* component : selectedEntity->GetAllComponents()) {
        const rttr::type type = rttr::type::get_by_name(component->GetName());
        
        rttr::variant var = component;
        
        for (rttr::property& prop : type.get_properties()) {
	        if (prop.get_type() == rttr::type::get<int>()) {
		        int value = prop.get_value(var).to_int();
		        ImGui::InputInt(prop.get_name().c_str(), &value);
		        bool success = prop.set_value(var, value);
	        }
        }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant