Skip to content

Instantly share code, notes, and snippets.

@eman41
Last active May 15, 2019 04:59
Show Gist options
  • Save eman41/051391a5c3bf85ccbcfc976dbc2a4f9e to your computer and use it in GitHub Desktop.
Save eman41/051391a5c3bf85ccbcfc976dbc2a4f9e to your computer and use it in GitHub Desktop.
This is an Unreal Editor header for creating a simple templated details customization to reduce boilerplate.
#pragma once
#include "CoreMinimal.h"
#include "IDetailCustomization.h"
#include "DetailLayoutBuilder.h"
template<typename CustomizedType, typename DetailsClass>
class FGenericDetails : public IDetailCustomization
{
public:
static TSharedRef<IDetailCustomization> MakeInstance();
virtual void CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) override;
virtual void LayoutCustomDetails(IDetailLayoutBuilder& DetailBuilder)
{
};
protected:
TWeakObjectPtr<CustomizedType> Selected;
};
template <typename CustomizedType, typename DetailsClass>
void FGenericDetails<CustomizedType, DetailsClass>::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder)
{
const TArray< TWeakObjectPtr<UObject> >& SelectedObjects = DetailBuilder.GetSelectedObjects();
for( int32 ObjectIndex = 0; !Selected.IsValid() && ObjectIndex < SelectedObjects.Num(); ++ObjectIndex )
{
const TWeakObjectPtr<UObject>& CurrentObject = SelectedObjects[ObjectIndex];
if ( CurrentObject.IsValid() )
{
Selected = Cast<CustomizedType>(CurrentObject.Get());
}
}
if(Selected.IsValid())
{
LayoutCustomDetails(DetailBuilder);
}
}
template <typename CustomizedType, typename DetailsClass>
TSharedRef<IDetailCustomization> FGenericDetails<CustomizedType, DetailsClass>::MakeInstance()
{
return MakeShareable(new DetailsClass);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment