diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/Generator.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/Generator.cpp
index d3c61320d0bd8d1f57fd03531edf1f79df5754f2..0b5a021d1c795af736d6c4861e720d1420c949a6 100644
--- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/Generator.cpp
+++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/Generator.cpp
@@ -598,12 +598,22 @@ namespace armarx::aron::codegenerator::cpp
     CppBlockPtr Generator::resolveMaybeEqualsBlock(const CppBlockPtr& block_if_data, const std::string& accessor, const std::string& otherInstanceAccessor) const
     {
         const auto& type = getType();
-        if (type.getMaybe() == type::Maybe::OPTIONAL || type.getMaybe() == type::Maybe::RAW_PTR || type.getMaybe() == type::Maybe::SHARED_PTR || type.getMaybe() == type::Maybe::UNIQUE_PTR)
+        if (type.getMaybe() == type::Maybe::RAW_PTR || type.getMaybe() == type::Maybe::SHARED_PTR || type.getMaybe() == type::Maybe::UNIQUE_PTR)
+        {
+            CppBlockPtr b = std::make_shared<CppBlock>();
+            b->addLine("if (not (static_cast<bool>(" + accessor + ") == static_cast<bool>(" + otherInstanceAccessor + "))) // check if both contain data");
+            b->addLineAsBlock("return false;");
+            b->addLine("if (static_cast<bool>(" + accessor + ") && static_cast<bool>(" + otherInstanceAccessor + "))");
+            b->addBlock(block_if_data);
+            return b;
+        }
+        
+        if (type.getMaybe() == type::Maybe::OPTIONAL)
         {
             CppBlockPtr b = std::make_shared<CppBlock>();
-            b->addLine("if (not ((bool) " + accessor + " == (bool) " + otherInstanceAccessor + ")) // check if both contain data");
+            b->addLine("if (not ( " + accessor + ".has_value() == " + otherInstanceAccessor + ".has_value())) // check if both contain data");
             b->addLineAsBlock("return false;");
-            b->addLine("if ((bool) " + accessor + " && (bool) " + otherInstanceAccessor + ")");
+            b->addLine("if ( " + accessor + ".has_value() && " + otherInstanceAccessor + ".has_value())");
             b->addBlock(block_if_data);
             return b;
         }