informa
/
1 MIN READ
Blogs

UE4Cookery CPP004: Editor actions with CallInEditor

Topic: Editor actions with CallInEditor Source for UE4.23: https://github.com/klauth86/UE4Cookery/tree/main/CPP004

Thanx to Alecann01 on https://answers.unrealengine.com/questions/1000550/dynamically-spawning-actors-in-the-editor.html

It is rather usual task to check something on level or location. For example, you can test some sort of spawning classes or different explosion effects to see if their logic is correct and conformed with some requirements. It is great to check this while running game in Editor, but there is an opportunity for some of this tests to be called in Editor without any need of running game by Play button. That can be very valuable for simple and quick verifications and is connected with UFUNCTION specifier CallInEditor. Another application for this specifier  - auto generating of level content by sequence of spawn and arrange actions. Let's examine it.

We can create new project from template and add new Actor class

 

MyActor.h

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

#pragma once

#include "GameFramework/Actor.h"
#include "MyActor.generated.h"

UCLASS()
class CPP004_API AMyActor : public AActor {
	
	GENERATED_BODY()

protected:

	UPROPERTY(Category = "MyActor: Test1", EditAnywhere)
	AActor* Test1Actor;

	UFUNCTION(Category = "MyActor: Test1", BlueprintCallable, CallInEditor)
	void Test1();
};

 

MyActor.cpp

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


#include "MyActor.h"
#include "Engine/World.h"

void AMyActor::Test1() {
	if (!Test1Actor) return;

	int i = 10;
	while (i-- > 0) {
		auto offset = 400 * (FVector2D::UnitVector + FMath::RandPointInCircle(1));
		auto location = FVector(offset, 0) + GetActorLocation();
		GetWorld()->SpawnActor(Test1Actor->GetClass(), &location, &FRotator::ZeroRotator);
	}
}

 

The main role as mentioned above is played by CallInEditor specifier for Test1 function. To see what's going on let's start Editor and add some instance of UMyActor to new level. When we open Details panel for created instance, we'll see there Editor action called Test1. By clicking on it we can execute CPP code in this function body right in Editor:

 

CallInEditor in action

Latest Jobs

Cryptic Studios

Remote
1.19.23
Senior Producer

Anne Arundel Community College

Arnold, MD, USA
1.30.23
Instructor/Assistant Professor, Game Art

Night School Studio

Los Angeles, CA, USA
1.09.23
Level Designer / Scripter, Games Studio
More Jobs   

CONNECT WITH US

Explore the
Subscribe to
Follow us

Game Developer Job Board

Game Developer Newsletter

@gamedevdotcom

Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Browse
Subscribe to

Game Developer Newsletter

Get daily Game Developer top stories every morning straight into your inbox

Subscribe
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more