diff --git a/src/common/variant_utils.h b/src/common/variant_utils.h index c3607735..1b47faef 100644 --- a/src/common/variant_utils.h +++ b/src/common/variant_utils.h @@ -56,6 +56,12 @@ namespace VariantUtils /// @param p_type the variant type /// @return the default Variant value of the specified type Variant make_default(Variant::Type p_type); + + /// Cast to a desired type. + /// @param p_value the value to be cast + /// @param T the cast type + /// @return the value cast to the specified type + template T cast_to(const Variant& p_value) { return T(p_value); } } #endif // ORCHESTRATOR_VARIANT_UTILS_H diff --git a/src/script/nodes/data/compose.cpp b/src/script/nodes/data/compose.cpp index e1551e9c..7c59ba7c 100644 --- a/src/script/nodes/data/compose.cpp +++ b/src/script/nodes/data/compose.cpp @@ -138,12 +138,19 @@ class OScriptNodeComposeFromInstance : public OScriptNodeInstance switch (_target_type) { case Variant::BOOL: + p_context.set_output(0, VariantUtils::cast_to(p_context.get_input(0))); + break; case Variant::INT: + p_context.set_output(0, VariantUtils::cast_to(p_context.get_input(0))); + break; case Variant::FLOAT: + p_context.set_output(0, VariantUtils::cast_to(p_context.get_input(0))); + break; case Variant::STRING: + p_context.set_output(0, VariantUtils::cast_to(p_context.get_input(0))); + break; case Variant::STRING_NAME: - // Perform optimization, no need to use the format solution - p_context.set_output(0, p_context.get_input(0)); + p_context.set_output(0, VariantUtils::cast_to(p_context.get_input(0))); break; default: {