MACRO

MACRO

#Overview

name: MACRO

This variable is created as a Console Variable (cvar).

It is referenced in 14 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of MACRO is to define and handle macros within the Unreal Engine 5 codebase. Macros are reusable code snippets that can be expanded by the preprocessor, allowing for more efficient and maintainable code.

This variable is used across multiple Unreal Engine subsystems and modules, including:

  1. PCG (Procedural Content Generation) plugin
  2. Animation Blueprint Editor
  3. Kismet (Blueprint) system
  4. UnrealEd (Unreal Editor)
  5. Core engine functionality

The value of this variable is not set directly, as it is used in various contexts:

  1. As a preprocessor definition in PCGMetadataAttributeTraits.h
  2. As an enumeration value in the NodeSectionID namespace
  3. As a string identifier in multiple locations within the Blueprint editor

MACRO interacts with other variables and systems, particularly in the context of Blueprint editing and code generation. It’s often used alongside other NodeSectionID values like FUNCTION, VARIABLE, and DELEGATE.

Developers should be aware that:

  1. MACRO is used to define sections in the Blueprint editor UI
  2. It’s part of the Blueprint system’s extensibility, allowing for the creation and management of macro graphs
  3. In some contexts, it’s used as a deprecated command identifier

Best practices when using this variable include:

  1. Ensuring proper categorization of Blueprint elements, especially when dealing with macros
  2. Being cautious when modifying MACRO-related code, as it may affect multiple parts of the engine
  3. When creating new Blueprint functionality, consider whether it should be categorized as a macro
  4. Avoid using deprecated MACRO commands in the editor console

When working with MACRO in the context of Blueprint editing, developers should familiarize themselves with the Blueprint editor’s architecture and the role of macros in Blueprint scripting.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/PCG/Source/PCG/Public/Metadata/PCGMetadataAttributeTraits.h:33

Scope: file

Source code excerpt:


// Convenient macro to avoid duplicating a lot of code with all our supported types.
#define PCG_FOREACH_SUPPORTEDTYPES(MACRO) \
	MACRO(int32)           \
	MACRO(int64)           \
	MACRO(float)           \
	MACRO(double)          \
	MACRO(FVector2D)       \
	MACRO(FVector)         \

#Loc: <Workspace>/Engine/Source/Editor/AnimationBlueprintEditor/Private/AnimationBlueprintEditor.cpp:1964

Scope (from outer to inner):

file
function     bool FAnimationBlueprintEditor::IsSectionVisible

Source code excerpt:

	case NodeSectionID::INTERFACE:
		return true;
	case NodeSectionID::MACRO:
		return AnimBlueprintSettings->bAllowMacros;
	case NodeSectionID::VARIABLE:
		return true;
	case NodeSectionID::COMPONENT:
		return false;
	case NodeSectionID::DELEGATE:

#Loc: <Workspace>/Engine/Source/Editor/Kismet/Private/SMyBlueprint.cpp:653

Scope (from outer to inner):

file
function     void SMyBlueprint::Construct

Source code excerpt:

	ExpandedSections.Add(NodeSectionID::VARIABLE, true);
	ExpandedSections.Add(NodeSectionID::FUNCTION, true);
	ExpandedSections.Add(NodeSectionID::MACRO, true);
	ExpandedSections.Add(NodeSectionID::DELEGATE, true);
	ExpandedSections.Add(NodeSectionID::GRAPH, true);
	ExpandedSections.Add(NodeSectionID::ANIMGRAPH, true);
	ExpandedSections.Add(NodeSectionID::ANIMLAYER, true);
	ExpandedSections.Add(NodeSectionID::LOCAL_VARIABLE, true);

#Loc: <Workspace>/Engine/Source/Editor/Kismet/Private/SMyBlueprint.cpp:735

Scope (from outer to inner):

file
function     void SMyBlueprint::OnCategoryNameCommitted

Source code excerpt:

			{
				// Do not allow renaming of any graph actions outside of the following
				if(Actions[i]->GetSectionID() == NodeSectionID::FUNCTION || Actions[i]->GetSectionID() == NodeSectionID::MACRO || Actions[i]->GetSectionID() == NodeSectionID::ANIMLAYER)
				{
					FEdGraphSchemaAction_K2Graph* GraphAction = (FEdGraphSchemaAction_K2Graph*)Actions[i].Get();

					// Don't allow changing the category of a graph who's parent is not the current Blueprint
					if(GraphAction && !FBlueprintEditorUtils::IsPaletteActionReadOnly(Actions[i], BlueprintEditorPtr.Pin()) && FBlueprintEditorUtils::FindBlueprintForGraph(GraphAction->EdGraph) == GetBlueprintObj())
					{

#Loc: <Workspace>/Engine/Source/Editor/Kismet/Private/SMyBlueprint.cpp:813

Scope (from outer to inner):

file
function     FText SMyBlueprint::OnGetSectionTitle

Source code excerpt:

		SeparatorTitle = NSLOCTEXT("GraphActionNode", "OverridableFunctions", "Overridable Functions");
		break;
	case NodeSectionID::MACRO:
		SeparatorTitle = NSLOCTEXT("GraphActionNode", "Macros", "Macros");
		break;
	case NodeSectionID::INTERFACE:
		SeparatorTitle = NSLOCTEXT("GraphActionNode", "Interfaces", "Interfaces");
		break;
	case NodeSectionID::DELEGATE:

#Loc: <Workspace>/Engine/Source/Editor/Kismet/Private/SMyBlueprint.cpp:903

Scope (from outer to inner):

file
function     TSharedRef<SWidget> SMyBlueprint::OnGetSectionWidget

Source code excerpt:


		break;
	case NodeSectionID::MACRO:
		AddNewText = LOCTEXT("AddNewMacro", "Macro");
		MetaDataTag = TEXT("AddNewMacro");
		break;
	case NodeSectionID::DELEGATE:
		AddNewText = LOCTEXT("AddNewDelegate", "Event Dispatcher");
		MetaDataTag = TEXT("AddNewDelegate");

#Loc: <Workspace>/Engine/Source/Editor/Kismet/Private/SMyBlueprint.cpp:959

Scope (from outer to inner):

file
function     FReply SMyBlueprint::OnAddButtonClickedOnSection

Source code excerpt:

		CommandList->ExecuteAction(FBlueprintEditorCommands::Get().AddNewFunction.ToSharedRef());
		break;
	case NodeSectionID::MACRO:
		CommandList->ExecuteAction(FBlueprintEditorCommands::Get().AddNewMacroDeclaration.ToSharedRef());
		break;
	case NodeSectionID::DELEGATE:
		CommandList->ExecuteAction(FBlueprintEditorCommands::Get().AddNewDelegate.ToSharedRef());
		break;
	case NodeSectionID::GRAPH:

#Loc: <Workspace>/Engine/Source/Editor/Kismet/Private/SMyBlueprint.cpp:994

Scope (from outer to inner):

file
function     bool SMyBlueprint::CanAddNewElementToSection

Source code excerpt:

		case NodeSectionID::FUNCTION:
			return CurrentBlueprint->SupportsFunctions();
		case NodeSectionID::MACRO:
			return CurrentBlueprint->SupportsMacros();
		case NodeSectionID::DELEGATE:
			return CurrentBlueprint->SupportsDelegates();
		case NodeSectionID::GRAPH:
			return CurrentBlueprint->SupportsEventGraphs();
		case NodeSectionID::ANIMLAYER:

#Loc: <Workspace>/Engine/Source/Editor/Kismet/Private/SMyBlueprint.cpp:1579

Scope (from outer to inner):

file
function     void SMyBlueprint::CollectAllActions

Source code excerpt:

			FText MacroCategory = GetGraphCategory(Graph);

			TSharedPtr<FEdGraphSchemaAction_K2Graph> NewMacroAction = MakeShareable(new FEdGraphSchemaAction_K2Graph(EEdGraphSchemaAction_K2Graph::Macro, MacroCategory, DisplayInfo.PlainName, DisplayInfo.Tooltip, 1, NodeSectionID::MACRO));
			NewMacroAction->FuncName = MacroName;
			NewMacroAction->EdGraph = Graph;

			const FString UserCategoryName = FEditorCategoryUtils::GetCategoryDisplayString(MacroCategory.ToString());
			SortList.AddAction(UserCategoryName, NewMacroAction);

#Loc: <Workspace>/Engine/Source/Editor/Kismet/Private/SMyBlueprint.cpp:1813

Scope (from outer to inner):

file
function     void SMyBlueprint::CollectStaticSections

Source code excerpt:

			StaticSectionIDs.Add(NodeSectionID::ANIMLAYER);
		}
		if (!bIsEditor || (BlueprintEditor->NewDocument_IsVisibleForType(FBlueprintEditor::CGT_NewMacroGraph) && BlueprintEditor->IsSectionVisible(NodeSectionID::MACRO)))
		{
			StaticSectionIDs.Add(NodeSectionID::MACRO);
		}
		if (!bIsEditor || (BlueprintEditor->NewDocument_IsVisibleForType(FBlueprintEditor::CGT_NewFunctionGraph) && BlueprintEditor->IsSectionVisible(NodeSectionID::FUNCTION)))
		{
			StaticSectionIDs.Add(NodeSectionID::FUNCTION);
		}
		if (!bIsEditor || (BlueprintEditor->NewDocument_IsVisibleForType(FBlueprintEditor::CGT_NewVariable) && BlueprintEditor->IsSectionVisible(NodeSectionID::VARIABLE)))

#Loc: <Workspace>/Engine/Source/Editor/Kismet/Private/SMyBlueprint.cpp:3287

Scope: file

Source code excerpt:

					break;
				}
			case NodeSectionID::MACRO:
				{
					TransactionTitle = LOCTEXT( "BulkRemoveMacros", "Bulk Remove Macros" );
					break;
				}
			default:
				{

#Loc: <Workspace>/Engine/Source/Editor/Kismet/Public/BlueprintEditor.h:115

Scope (from outer to inner):

file
namespace    NodeSectionID

Source code excerpt:

		FUNCTION_OVERRIDABLE,	// Overridable functions
		INTERFACE,				// Interface
		MACRO,					// Macros
		VARIABLE,				// Variables
		COMPONENT,				// Components
		DELEGATE,				// Delegate/Event
		USER_ENUM,				// User defined enums
		LOCAL_VARIABLE,			// Local variables
		USER_STRUCT,			// User defined structs

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/EditorServer.cpp:309

Scope (from outer to inner):

file
function     bool UEditorEngine::SafeExec

Source code excerpt:

	const TCHAR* const FullStr = InStr;

	if( FParse::Command(&Str,TEXT("MACRO")) || FParse::Command(&Str,TEXT("EXEC")) )//oldver (exec)
	{
		FMessageDialog::Open( EAppMsgType::Ok, FText::Format(NSLOCTEXT("UnrealEd", "Error_TriedToExecDeprecatedCmd", "Tried to execute deprecated command: {0}"),FText::FromString(FullStr)) );
	}
	else if( FParse::Command( &Str, TEXT( "EXECFILE" ) ) )
	{
		// Executes a file that contains a list of commands

#Loc: <Workspace>/Engine/Source/Runtime/Core/Public/Misc/LargeWorldCoordinates.h:20

Scope: file

Source code excerpt:

// Necessary to convince the MSVC preprocessor to play ball with variadic args - https://stackoverflow.com/questions/5134523/msvc-doesnt-expand-va-args-correctly
#define FORCE_EXPAND(X) X
#define UE_LWC_MACRO_SELECT(PAD1, PAD2, PAD3, PAD4, MACRO, ...)	MACRO
#define UE_DECLARE_LWC_TYPE_SELECT(...)							FORCE_EXPAND(UE_LWC_MACRO_SELECT(__VA_ARGS__, UE_DECLARE_LWC_TYPE_EX, UE_DECLARE_LWC_TYPE_3, UE_DECLARE_LWC_TYPE_2, UE_DECLARE_LWC_TYPE_1 ))

// Args - TYPE, DIMENSION, [UE_TYPENAME], [COMPONENT_TYPE]. e.g. Vector, 3, FVector, double		// LWC_TODO: Remove COMPONENT_TYPE
#define UE_DECLARE_LWC_TYPE(...)								FORCE_EXPAND(UE_DECLARE_LWC_TYPE_SELECT(__VA_ARGS__)(__VA_ARGS__))

// Use to make any narrowing casts searchable in code when it is updated to work with a 64 bit count/range