# How to make a C++ event callable from within the editor?

**URL:** <https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [July 31, 2016, 2:01pm UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327 "2016-07-31T14:01:43Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [July 31, 2016, 2:01pm UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/1 "2016-07-31T14:01:43Z")

</div>

Custom events that you create in Blueprint can be exposed to the details panel of an actor to run some logic. I want to do a similar thing for a C++ defined event but I’m having trouble figuring out how to do so?

The blueprint equivalent:  
 ![4ec3665172e9739503815a324f7f783ab857d32b.jpeg](https://d1ap1mz92jnks1.cloudfront.net/images/transparent.png)  
 ![2acb9ce91c259b601eae706226cea6896d8ecb59.jpeg](https://d1ap1mz92jnks1.cloudfront.net/images/transparent.png)

All I really want is a couple of buttons in the details panel for one of my actors, when I press one it’ll generated a load of instances meshes, and when I press another it’ll do something else. Any ideas?

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [July 31, 2016, 2:47pm UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/2 "2016-07-31T14:47:04Z")

</div>

It looks like the only other way to do this using C++ is using details panel customization, which is an absolute headache because there’s zero documentation or examples…

---

<div class="post-metadata">

**Author:** ![Ali\_Akbar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ali_akbar/32/1008648_2.png) [@Ali\_Akbar](https://forums.unrealengine.com/u/Ali_Akbar)\
**Post date:** [July 31, 2016, 2:50pm UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/3 "2016-07-31T14:50:41Z")

</div>

@TheJamsh You need to create a Customization class in the editor module of your game

Create an editor module using the following steps:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

---

<div class="post-metadata">

**Author:** ![Ali\_Akbar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ali_akbar/32/1008648_2.png) [@Ali\_Akbar](https://forums.unrealengine.com/u/Ali_Akbar)\
**Post date:** [July 31, 2016, 3:40pm UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/4 "2016-07-31T15:40:36Z")

</div>

[![](https://i.imgur.com/ebKvh6U.jpg) ](https://i.imgur.com/ebKvh6U.jpg)

I’ve created a customization to add a button to all static mesh actors

Here’s the code:

[![](https://i.imgur.com/j3oCrwm.png) ](https://i.imgur.com/j3oCrwm.png)

**MyActorCustomization.h**

```auto

#pragma once

#include "IDetailCustomization.h"
#include "IPropertyChangeListener.h"

DECLARE_LOG_CATEGORY_EXTERN(LogMyActorCustomization, Log, All);

class MYGAMEEDITOR_API FMyActorCustomization : public IDetailCustomization {
public:
	// IDetailCustomization interface
	virtual void CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) override;
	// End of IDetailCustomization interface

	static TSharedRef<IDetailCustomization> MakeInstance();

	static FReply ExecuteCommand(IDetailLayoutBuilder* DetailBuilder);
};

```

**MyActorCustomization.cpp**

```auto

#include "MyGameEditorPrivatePCH.h"
#include "MyActorCustomization.h"
#include "PropertyEditing.h"
#include "IDetailsView.h"

#define LOCTEXT_NAMESPACE "DungeonArchitectEditorModule" 
DEFINE_LOG_CATEGORY(LogMyActorCustomization)

template<typename T>
T* GetBuilderObject(IDetailLayoutBuilder* DetailBuilder) {
	TArray<TWeakObjectPtr<UObject>> OutObjects;
	DetailBuilder->GetObjectsBeingCustomized(OutObjects);
	T* Obj = nullptr;
	if (OutObjects.Num() > 0) {
		Obj = Cast<T>(OutObjects[0].Get());
	}
	return Obj;
}

//////////////// FMyActorCustomization ////////////////////
void FMyActorCustomization::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder)
{
	IDetailCategoryBuilder& Category = DetailBuilder.EditCategory("My Category");
	FText Caption = FText::FromString("My Custom Button");
	Category.AddCustomRow(Caption)
		.ValueContent()
		
			SNew(SButton)
			.Text(Caption)
			.OnClicked(FOnClicked::CreateStatic(&FMyActorCustomization::ExecuteCommand, &DetailBuilder))
		];
}

TSharedRef<IDetailCustomization> FMyActorCustomization::MakeInstance()
{
	return MakeShareable(new FMyActorCustomization);
}

FReply FMyActorCustomization::ExecuteCommand(IDetailLayoutBuilder* DetailBuilder)
{
	AStaticMeshActor* StaticMesh = GetBuilderObject<AStaticMeshActor>(DetailBuilder);
	if (StaticMesh) {
		UE_LOG(LogMyActorCustomization, Log, TEXT("Running custom code"));
		// TODO: Add your button logic here

	}
	return FReply::Handled();
}

#undef LOCTEXT_NAMESPACE

```

**MyGameEditor.h**

```auto

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Engine.h"
#include "ModuleManager.h"
#include "UnrealEd.h"

DECLARE_LOG_CATEGORY_EXTERN(MyGameEditor, All, All)

class FMyGameEditorModule : public IModuleInterface
{
public:
	virtual void StartupModule() override;
	virtual void ShutdownModule() override;

};

```

**MyGameEditor.cpp**

```auto

// Fill out your copyright notice in the Description page of Project Settings.
#include "MyGameEditorPrivatePCH.h"
#include "MyGameEditor.h"
#include "ModuleManager.h"
#include "MyActorCustomization.h"
#include "PropertyEditorModule.h"

IMPLEMENT_GAME_MODULE(FMyGameEditorModule, MyGameEditor);

DEFINE_LOG_CATEGORY(MyGameEditor)

#define LOCTEXT_NAMESPACE "MyGameEditor"

void FMyGameEditorModule::StartupModule()
{
	UE_LOG(MyGameEditor, Warning, TEXT("MyGameEditor: Log Started"));

	// Register the details customization
	FPropertyEditorModule& PropertyEditorModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
	// Leave out the suffix "A" when specifying the name of your actor in the first param
	PropertyEditorModule.RegisterCustomClassLayout("StaticMeshActor", FOnGetDetailCustomizationInstance::CreateStatic(&FMyActorCustomization::MakeInstance));
}

void FMyGameEditorModule::ShutdownModule()
{
	UE_LOG(MyGameEditor, Warning, TEXT("MyGameEditor: Log Ended"));
}

#undef LOCTEXT_NAMESPACE

```

**MyGameEditorPrivatePCH.h**

```auto

#include "CoreUObject.h"

// You should place include statements to your module's private header files here. You only need to
// add includes for headers that are used in most of your module's source files though.
#include "Engine.h"
#include "UnrealEd.h"

```

**MyGameEditor.Build.cs**

```auto

// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;

public class MyGameEditor : ModuleRules
{
	public MyGameEditor(TargetInfo Target)
	{
		
        PublicIncludePaths.AddRange(
            new string]{
                "MyGameEditor/Public"
            });
 
        PrivateIncludePaths.AddRange(
            new string] {
			"MyGameEditor/Private"
		});
        
        PublicDependencyModuleNames.AddRange(
            new string]
            {
                    "Core",
                    "CoreUObject",
                    "Engine",
                    "EditorStyle",
                    "UnrealEd",
                    "PropertyEditor",
                    "MyGame"
            }
        );

        // Uncomment if you are using Slate UI
        PrivateDependencyModuleNames.AddRange(new string] { "Slate", "SlateCore" });
    }
}

```

**MyGame.Target.cs**

```auto

// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;
using System.Collections.Generic;

public class MyGameTarget : TargetRules
{
	public MyGameTarget(TargetInfo Target)
	{
		Type = TargetType.Game;
	}

	//
	// TargetRules interface.
	//

	public override void SetupBinaries(
		TargetInfo Target,
		ref List<UEBuildBinaryConfiguration> OutBuildBinaryConfigurations,
		ref List<string> OutExtraModuleNames
		)
	{
		OutExtraModuleNames.AddRange( new string] { "MyGame" } );
        if (UEBuildConfiguration.bBuildEditor)
        {
            OutExtraModuleNames.Add("MyGameEditor");
        }
    }
}

```

**MyGameEditor.Target.cs**

```auto

// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;
using System.Collections.Generic;

public class MyGameEditorTarget : TargetRules
{
	public MyGameEditorTarget(TargetInfo Target)
	{
		Type = TargetType.Editor;
	}

	//
	// TargetRules interface.
	//

	public override void SetupBinaries(
		TargetInfo Target,
		ref List<UEBuildBinaryConfiguration> OutBuildBinaryConfigurations,
		ref List<string> OutExtraModuleNames
		)
	{
		OutExtraModuleNames.AddRange( new string] { "MyGameEditor" } );
	}
}

```

**MyGame.uproject**

```auto

{
	"FileVersion": 3,
	"EngineAssociation": "4.12",
	"Category": "",
	"Description": "",
	"Modules": 
		{
			"Name": "MyGame",
			"Type": "Runtime",
			"LoadingPhase": "Default"
		},
		{
			"Name": "MyGameEditor",
			"Type": "Editor",
            "LoadingPhase": "PostEngineInit"
		}
	],
	"Plugins": 
		{
			"Name": "Substance",
			"Enabled": true,
			"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/offers/2f6439c2f9584f49809d9b13b16c2ba4"
		}
	]
}

```

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [July 31, 2016, 4:09pm UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/5 "2016-07-31T16:09:42Z")

</div>

Thanks for the example code Ali - I started work on the editor module but it was a minefield… hopefully this will get it working.

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [July 31, 2016, 4:19pm UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/6 "2016-07-31T16:19:04Z")

</div>

Just to add for the devs reading this (coming from google search), if you make a multicast event then customization of Details Panel isn’t needed; they show up on parent blueprint like this:

```auto

//...
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FHSM_ExitState, uint8, StateID, FName, StateName);

```

[![](http://i1234.photobucket.com/albums/ff408/BrUnOXaVIeR/BpEvent_zpsvwtlg8jb.jpg) ](http://i1234.photobucket.com/albums/ff408/BrUnOXaVIeR/BpEvent_zpsvwtlg8jb.jpg)

---

<div class="post-metadata">

**Author:** ![kamrann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kamrann](https://forums.unrealengine.com/u/kamrann)\
**Post date:** [July 31, 2016, 4:21pm UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/7 "2016-07-31T16:21:47Z")

</div>

I was just thinking about this the other day actually. The details customizations are great and really flexible, but it’s also a total pain to create one when you just want to do something simple. I was thinking that this particular case - adding a button to execute a function - should really have a UFUNCTION metadata to make this super easy to do. I’ll have a look into how feasible it might be for a PR. Problem is the property code is a monster and I’m not sure where would be the right place to insert this.

---

<div class="post-metadata">

**Author:** ![kamrann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kamrann](https://forums.unrealengine.com/u/kamrann)\
**Post date:** [July 31, 2016, 4:23pm UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/8 "2016-07-31T16:23:31Z")

</div>

[MENTION=434]BrUnO XaVIeR[/MENTION]: I think @TheJamsh is talking about a button to run code at the point it’s clicked in-editor, not for binding a function to execute at runtime.

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [July 31, 2016, 4:28pm UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/9 "2016-07-31T16:28:20Z")

</div>

> [@kamrann;573622](#):
>
> [MENTION=434]BrUnO XaVIeR[/MENTION]: I think @TheJamsh is talking about a button to run code at the point it’s clicked in-editor, not for binding a function to execute at runtime.

Yes, I just added that because the OP title; ppl looking for blueprint delegates will drop here because title.

---

<div class="post-metadata">

**Author:** ![Ali\_Akbar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ali_akbar/32/1008648_2.png) [@Ali\_Akbar](https://forums.unrealengine.com/u/Ali_Akbar)\
**Post date:** [July 31, 2016, 4:44pm UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/10 "2016-07-31T16:44:52Z")

</div>

> [@TheJamsh;573618](#):
>
> Thanks for the example code Ali - I started work on the editor module but it was a minefield… hopefully this will get it working.

You’re welcome 😉

I’m thinking of creating a plugin that, when installed, would help extend the editor in various ways without writing C++. You would specify the mapping from some UI (e.g. target actor type and a blueprint that needs to be executed when pressed), adding a button to the toolbar etc

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [July 31, 2016, 5:18pm UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/11 "2016-07-31T17:18:44Z")

</div>

AHHHH IT’S WORKING. What a absolute nightmare that was… Now to make the good stuff happen.  
@Ali so I’ve got functions hooked up to buttons, I guess it’s relatively easy to add properties here as well that I can tweak? Currently the variables in that category are part of my custom World Settings class.

 ![EditoModule.JPG](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/2/d2352d0b0757774b1179008dd11502d793ff3965.jpeg)

Kind of a shame the Foliage Tool doesn’t work all that well for things like this… oh well.

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [July 31, 2016, 6:43pm UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/12 "2016-07-31T18:43:54Z")

</div>

Alright not all finish yet. I now can’t package the game because of the old HACD\_64.dll linker error.

Something tells me the build.cs files aren’t setup correctly…

EDIT: Figured it out, had ‘UnrealEd’ as a dependency in the Uproject file. Fixed now.

---

<div class="post-metadata">

**Author:** ![Ali\_Akbar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ali_akbar/32/1008648_2.png) [@Ali\_Akbar](https://forums.unrealengine.com/u/Ali_Akbar)\
**Post date:** [August 1, 2016, 11:54am UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/13 "2016-08-01T11:54:42Z")

</div>

> [@TheJamsh;573641](#):
>
> @Ali so I’ve got functions hooked up to buttons, I guess it’s relatively easy to add properties here as well that I can tweak? Currently the variables in that category are part of my custom World Settings class. .

You can add custom property rows like this in the CustomizeDetails function:

```auto

	TSharedPtr<IPropertyHandle> PropertyHandle = DetailBuilder.GetProperty("bStaticMeshReplicateMovement");
	Category.AddCustomRow(Caption)
	.WholeRowContent()
		
			SNew(SProperty, PropertyHandle)
		];

```

The property handle you search for has to be a UPROPERTY and should be a member of the class you are customizing

You can also add properties of external UObjects like this (provided you somehow get a reference of it in the CustomizeDetails function)

```auto

Category.AddExternalProperty(...)

```

---

<div class="post-metadata">

**Author:** ![FridayIsTheBest](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FridayIsTheBest](https://forums.unrealengine.com/u/FridayIsTheBest)\
**Post date:** [December 16, 2019, 11:04am UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/14 "2019-12-16T11:04:56Z")

</div>

Adding editor button which will execute some C++ function is now as simple as it should be.  
Just add:

```auto

UFUNCTION(BlueprintCallable, CallInEditor)

```

macro above your function, recompile and button will be there.

Once again: Sorry for necro-ing old thread, but it’s easier to find this than actual answer.

---

<div class="post-metadata">

**Author:** ![VinnyBlood](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VinnyBlood](https://forums.unrealengine.com/u/VinnyBlood)\
**Post date:** [December 28, 2021, 5:36am UTC](https://forums.unrealengine.com/t/how-to-make-a-c-event-callable-from-within-the-editor/70327/15 "2021-12-28T05:36:20Z")

</div>

There’s: UFUNCTION(BlueprintCallable, CallInEditor)
