蓝图并没有为每一个类型的数组都提供排序方法,尤其是自定义的Actor,但是,我们可以利用蓝图中的接口,通过C++对蓝图数组进行排序。
首先,创建一个排序接口,ISort,
// sort function for BP in UE4 by haisongliang
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "Sort.generated.h"
// This class does not need to be modified.
UINTERFACE(MinimalAPI, BlueprintType)
class USort : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class MYFUNCTIONLIBRARY_API ISort
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category = "System|Sort")
bool smallerThan(const UObject* A);
};
然后,在函数库(或者其他C++模块)中实现排序方法,
UCLASS()
class MYFUNCTIONLIBRARY_API UMyFunctionLibrar