I am working on a Slate Graph, I can drop a Texture as i like and get the node, now I like to Drop a selection of Objects(Textures on this case), to simplify the work of selection. How it can be possible?
I am Using the class SAssetDropTarget with the delegates .OnAssetDropped and .OnIsAssetAcceptableForDrop, trying so many things who doesnt work, now I will log wath happens when I try to drop an selection.
OnIsAssetAcceptableForDrop sounds like compatibility check event, it should return to true to let asset drop. Did you do that?
I check the event, only works if the drag is individual, not work and dont release never if is a selection of assets
I try to figure out with Logs wath happens when I have selected some assets on the Content Browser and I try to Drop on the Graph,do nothing, OnIsAssetAcceptableForDrop is never called. I think is a limitation on the class, I think I need to implement new functions based on DragAnDrop.h
I resolved as I Think preliminary; on SAssetDropTarget an internal function only was processed if only drops one UObject I Modify by my needs.
For me Works good, if I found a bug I will release here the fix.
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "SAssetDropTargetArray.h"
#include "AssetData.h"
#include "DragAndDrop/AssetDragDropOp.h"
#include "DragAndDrop/ActorDragDropOp.h"
#include "AssetSelection.h"
#define LOCTEXT_NAMESPACE "EditorWidgets"
void SAssetDropTargetArray::Construct(const FArguments& InArgs)
{
OnAssetDropped = InArgs._OnAssetDropped;
OnIsAssetAcceptableForDrop = InArgs._OnIsAssetAcceptableForDrop;
SDropTarget::Construct(
SDropTarget::FArguments()
.OnDrop(this, &SAssetDropTargetArray::OnDropped)
[
InArgs._Content.Widget
]);
}
FReply SAssetDropTargetArray::OnDropped(TSharedPtr<FDragDropOperation> DragDropOperation)
{
bool bUnused;
TArray<UObject*> Objects = GetDroppedObject(DragDropOperation, bUnused);
for (UObject* Object :Objects)
{
OnAssetDropped.ExecuteIfBound(Object);
}
return FReply::Handled();
}
bool SAssetDropTargetArray::OnAllowDrop(TSharedPtr<FDragDropOperation> DragDropOperation) const
{
bool bUnused = false;
TArray<UObject*> Objects = GetDroppedObject(DragDropOperation, bUnused);
for (UObject* Object : Objects)
{
// Check and see if its valid to drop this object
if (OnIsAssetAcceptableForDrop.IsBound())
{
return OnIsAssetAcceptableForDrop.Execute(Object);
}
else
{
// If no delegate is bound assume its always valid to drop this object
return true;
}
}
return false;
}
bool SAssetDropTargetArray::OnIsRecognized(TSharedPtr<FDragDropOperation> DragDropOperation) const
{
bool bRecognizedEvent = false;
TArray<UObject*> Object = GetDroppedObject(DragDropOperation, bRecognizedEvent);
return bRecognizedEvent;
}
TArray<UObject*> SAssetDropTargetArray::GetDroppedObject(TSharedPtr<FDragDropOperation> DragDropOperation, bool& bOutRecognizedEvent) const
{
bOutRecognizedEvent = false;
TArray<UObject*> DropppedArray;
// Asset being dragged from content browser
if (DragDropOperation->IsOfType<FAssetDragDropOp>())
{
bOutRecognizedEvent = true;
TSharedPtr<FAssetDragDropOp> DragDropOp = StaticCastSharedPtr<FAssetDragDropOp>(DragDropOperation);
const TArray<FAssetData>& DroppedAssets = DragDropOp->GetAssets();
if (DroppedAssets.Num() < 1)
{
return DropppedArray;
}
for (FAssetData AssetData : DroppedAssets)
{
DropppedArray.Add(AssetData.GetAsset());
}
}
// Asset being dragged from some external source
else if (DragDropOperation->IsOfType<FExternalDragOperation>())
{
TArray<FAssetData> DroppedAssetData = AssetUtil::ExtractAssetDataFromDrag(DragDropOperation);
if (DroppedAssetData.Num() < 1)
{
return DropppedArray;
}
for (FAssetData DroppedAsset : DroppedAssetData)
{
bOutRecognizedEvent = true;
DropppedArray.Add(DroppedAsset.GetAsset());
}
}
// Actor being dragged?
else if (DragDropOperation->IsOfType<FActorDragDropOp>())
{
bOutRecognizedEvent = true;
TSharedPtr<FActorDragDropOp> ActorDragDrop = StaticCastSharedPtr<FActorDragDropOp>(DragDropOperation);
if (ActorDragDrop->Actors.Num() < 1)
{
return DropppedArray;
}
for (TWeakObjectPtr<AActor> ActorDD : ActorDragDrop->Actors)
{
DropppedArray.Add(ActorDD.Get());
}
}
return DropppedArray;
}
#undef LOCTEXT_NAMESPACE