Add VariantType::GetScriptingType for easier type information access

This commit is contained in:
2026-06-03 10:57:51 +02:00
parent 89a1f00c57
commit 422300adbd
7 changed files with 15 additions and 12 deletions
+5 -8
View File
@@ -205,10 +205,9 @@ bool BehaviorKnowledge::Set(const StringAnsiView& path, const Variant& value)
bool BehaviorKnowledge::HasGoal(ScriptingTypeHandle type) const
{
for (int32 i = 0; i < Goals.Count(); i++)
for (const Variant& goal : Goals)
{
const ScriptingTypeHandle goalType = Scripting::FindScriptingType(Goals[i].Type.GetTypeName());
if (goalType == type)
if (goal.Type.GetScriptingType() == type)
return true;
}
return false;
@@ -218,8 +217,7 @@ const Variant& BehaviorKnowledge::GetGoal(ScriptingTypeHandle type) const
{
for (const Variant& goal : Goals)
{
const ScriptingTypeHandle goalType = Scripting::FindScriptingType(goal.Type.GetTypeName());
if (goalType == type)
if (goal.Type.GetScriptingType() == type)
return goal;
}
return Variant::Null;
@@ -242,10 +240,9 @@ void BehaviorKnowledge::RemoveGoal(ScriptingTypeHandle type)
{
for (int32 i = 0; i < Goals.Count(); i++)
{
const ScriptingTypeHandle goalType = Scripting::FindScriptingType(Goals[i].Type.GetTypeName());
if (goalType == type)
if (Goals[i].Type.GetScriptingType() == type)
{
Goals.RemoveAt(i);
Goals.RemoveAtKeepOrder(i);
break;
}
}
@@ -339,7 +339,7 @@ void VisualScriptExecutor::ProcessGroupTools(Box* box, Node* node, Value& value)
obj = Value::Null;
#else
const ScriptingTypeHandle type = Scripting::FindScriptingType(StringAnsiView(typeNameAnsi.Get(), typeName.Length()));
const ScriptingTypeHandle objType = Scripting::FindScriptingType(obj.Type.GetTypeName());
const ScriptingTypeHandle objType = obj.Type.GetScriptingType();
if (!type || !objType || !objType.IsSubclassOf(type))
obj = Value::Null;
#endif
+5
View File
@@ -362,6 +362,11 @@ const char* VariantType::GetTypeName() const
return InBuiltTypesTypeNames[Type];
}
ScriptingTypeHandle VariantType::GetScriptingType() const
{
return Scripting::FindScriptingType(GetTypeName());
}
VariantType VariantType::GetElementType() const
{
if (Type == Array)
+1
View File
@@ -151,6 +151,7 @@ public:
void SetTypeName(const ScriptingType& type);
void SetTypeName(const MClass& klass);
const char* GetTypeName() const;
ScriptingTypeHandle GetScriptingType() const;
VariantType GetElementType() const;
// Drops custom type name into the name allocated by the scripting module to reduce memory allocations when referencing types.
void Inline();
+1 -1
View File
@@ -85,7 +85,7 @@ struct CommandData
else if (value.Type.Type == VariantType::Structure)
{
// Prettify structure printing
ScriptingTypeHandle resultType = Scripting::FindScriptingType(value.Type.GetTypeName());
ScriptingTypeHandle resultType = value.Type.GetScriptingType();
if (resultType)
{
Array<void*> fields;
+1 -1
View File
@@ -64,7 +64,7 @@ Actor* Prefab::GetDefaultInstance()
// Skip if not loaded
if (!IsLoaded())
{
LOG(Warning, "Cannot instantiate object from not loaded prefab asset.");
LOG(Warning, "Cannot instantiate object from not loaded prefab asset ({}, {})", GetPath(), GetID());
return nullptr;
}
+1 -1
View File
@@ -766,7 +766,7 @@ void VisjectExecutor::ProcessGroupPacking(Box* box, Node* node, Value& value)
structureValue = Variant::Cast(structureValue, typeVariantType);
}
structureValue.InvertInline(); // Extract any Float3/Int32 into Structure type from inlined format
const ScriptingTypeHandle structureValueTypeHandle = Scripting::FindScriptingType(structureValue.Type.GetTypeName());
const ScriptingTypeHandle structureValueTypeHandle = structureValue.Type.GetScriptingType();
if (structureValue.Type.Type != VariantType::Structure || typeHandle != structureValueTypeHandle)
{
OnError(node, box, String::Format(TEXT("Cannot unpack value of type {0} to structure of type {1}"), structureValue.Type, typeName));