o1-preview-2024-09-12· OpenAI
WildChat-4.8M (AI2)
как мне теперь привести тип ReturnPin к Classtocast? void…
- User
как мне теперь привести тип ReturnPin к Classtocast? void UCustomK2Node::PinConnectionListChanged(UEdGraphPin* Pin) { Super::PinConnectionListChanged(Pin);
if ( Pin->HasAnyConnections() && Pin->Direction == EEdGraphPinDirection::EGPD_Input ) { const auto GetterVarNode = Cast<UK2Node_VariableGet>(Pin->LinkedTo[0]->GetOwningNode()); UBlueprint* const OwningBlueprint = FBlueprintEditorUtils::FindBlueprintForNode(GetterVarNode); const FName VarName = GetterVarNode->VariableReference.GetMemberName(); UClass* const GeneratedClass = OwningBlueprint->GeneratedClass; UObject* const CDO = GeneratedClass->GetDefaultObject(); FProperty* const Property = FindFProperty<FProperty>(GeneratedClass, VarName); if ( !Property ) { return; } FStructProperty* const StructProperty = CastField<FStructProperty>(Property); if ( !StructProperty ) { return; } void* StructData = StructProperty->ContainerPtrToValuePtr<void>(CDO); FPathToScenarioObject* DefaultStructValue = StaticCast<FPathToScenarioObject*>(StructData); if ( DefaultStructValue->Path.IsEmpty() ) { return; } auto ClassToCast = Cast<UScenarioObject>(DefaultStructValue->Path.Last().Storage)->Classes; auto ReturnPin = FindPin(FeaturePinName); }}
- Assistant
To change the type of
ReturnPinto matchClassToCast, you'll need to modify thePinTypeofReturnPin. Here's how you can do it:if (ReturnPin) { // Assuming ClassToCast is of type UClass* // Set the pin category to Object (or Interface, depending on your needs) ReturnPin->PinType.PinCategory = UEdGraphSchema_K2::PC_Object; // Clear any existing sub-categories ReturnPin->PinType.PinSubCategory = NAME_None; // Set the sub-category object to ClassToCast ReturnPin->PinType.PinSubCategoryObject = ClassToCast; // Optionally, adjust the container type if needed (e.g., single, array, set, map) ReturnPin->PinType.ContainerType = EPinContainerType::None; // Adjust as necessary // Notify that the pin type has changed ReturnPin->GetOwningNode()->PinTypeChanged(ReturnPin); // Mark the blueprint as modified so the change is saved UBlueprint* Blueprint = FBlueprintEditorUtils::FindBlueprintForNode(ReturnPin->GetOwningNode()); if (Blueprint) { Blueprint->Modify(); FBlueprintEditorUtils::MarkBlueprintAsModified(Blueprint); } }