-
Check for FClassProperty:
First, determine if the property is actually a FClassProperty rather than a FObjectProperty. This is often the case if the property is defined using TSubclassOf<UScenarioObjectBase>. Here's how you can adjust your code:
FClassProperty* ClassPropField = CastField<FClassProperty>(ClassProp);
if (ClassPropField)
{
UClass* MetaClass = ClassPropField->MetaClass; // This should give you UScenarioObject
}
The MetaClass in FClassProperty represents the type restriction for the classes that can be assigned to this property. If MetaClass is UScenarioObject, then this is the subclass you're looking for.
-
Retrieve Meta-data from the Property:
Unreal Engine allows you to specify meta-data for properties, such as AllowedClasses or ClassRestrictions, which can help you determine the specific subclass. You can access this meta-data as follows:
FString AllowedClasses = ClassProp->GetMetaData(TEXT("AllowedClasses"));
if (!AllowedClasses.IsEmpty())
{
UClass* DesiredClass = FindObject<UClass>(ANY_PACKAGE, *AllowedClasses);
// DesiredClass should be UScenarioObject
}
Make sure that your property is declared with the meta-data specifying AllowedClasses:
UPROPERTY(EditAnywhere, meta = (AllowedClasses = "UScenarioObject"))
UObject* Storage;
-
Inspect the Connected Pin's Type:
If the pin is connected to another pin, you can try to get the class from the connected pin's type:
if (Pin->LinkedTo.Num() > 0)
{
UEdGraphPin* ConnectedPin = Pin->LinkedTo[0];
UClass* ConnectedPinClass = Cast<UClass>(ConnectedPin->PinType.PinSubCategoryObject.Get());
if (ConnectedPinClass)
{
// ConnectedPinClass should be UScenarioObject
}
}
-
Use the Property's Default Value:
If the property has a default value set to an instance of UScenarioObject, you can retrieve it:
UObject* DefaultObject = nullptr;
if (ClassProp->HasDefaultValue())
{
DefaultObject = ClassProp->ContainerPtrToValuePtr<UObject>(ClassProp->GetOwnerStruct()->GetDefaultObject());
if (DefaultObject)
{
UClass* DefaultClass = DefaultObject->GetClass();
// DefaultClass should be UScenarioObject
}
}
-
Examine the Struct's Default Object:
You can also attempt to retrieve the class from the default instance of the struct:
UObject* StructDefaultObject = InnerStruct->GetDefaultObject();
if (StructDefaultObject)
{
FProperty* StorageProp = InnerStruct->FindPropertyByName(FName("Storage"));
UObject* StorageValue = StorageProp->ContainerPtrToValuePtr<UObject>(StructDefaultObject);
if (StorageValue)
{
UClass* StorageClass = StorageValue->GetClass();
// StorageClass should be UScenarioObject
}
}