My UnrealEdEngine Plugin Progress: Need Help With Displaying and Input

Dear Friends At Epic,

I’ve made substantial progress with my goals of making an UnrealEdEngine plugin to add some additional tools to the editor.

Below is my code and the result:

// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.

//Unreal Editor Fun With Rama

#include "VictoryGame.h"

UVictoryEdEngine::UVictoryEdEngine(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	
	
}

void UVictoryEdEngine::NoteSelectionChange()
{
	if(!GetSelectedActors()) return;
	AActor* SelectedActor = Cast(GetSelectedActors()->GetTop(AActor::StaticClass()));
	if(!SelectedActor) return;
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
UE_LOG(Victory, Warning, TEXT("New Selected Actor %s"), *SelectedActor->GetName() );
UE_LOG(Victory, Warning, TEXT("New Selected Actor Location %s"), *SelectedActor->GetActorLocation().ToString() );
/*
//whats going on in editor land?
for ( TObjectIterator It; It; ++It )
{
	UE_LOG(Victory, Warning, TEXT("EditorLand: %s"), *It->GetName() );
}
*/

//Determine Active Viewport to GetWorld from
for(int32 Itr = 0; Itr < LevelViewportClients.Num(); Itr++ )
{
	if(!LevelViewportClients[Itr]->IsLevelEditorClient()) continue;
	if(!LevelViewportClients[Itr]->IsVisible()) continue;
	UE_LOG(Victory, Warning, TEXT("This one is visible %d"), Itr );
	
	DrawDebugString(
		LevelViewportClients[Itr]->GetWorld(),
		FVector(0,0,64), 
		SelectedActor->GetName(), 
		SelectedActor, 
		FColor(255,0,255),
		2
	);
	
}

//or try GWorld
DrawDebugPoint(
	GWorld,
	SelectedActor->GetActorLocation(), 
	7, 
	FColor(255,0,255),
	false,
	2
);

}

#Displaying

I dont know how to subclass LevelEditorViewport because there’s no config option to do so, would I just use a class redirect?

I can successfully identify the active viewport as you see in my code and log,

but when I get the world of the Viewport and try to send debug strings and draw points to this World nothing shows up int he editor display.

I am trying to display stuff within the viewport in the Pre-PIE world

What is the best way to do this?

Input

Within EditorViewport and LevelEditorViewport I see plenty of functions related to input

But again, since I cannot figure out how to subclass LevelEditorViewport so that all the editor viewports use it, I cannot write custom code related to user input

What is the best way to get keyboard and mouse input from within the Editor Pre-PIE world?

Thanks!

Rama

For your displaying question can you check if your debug strings and points display if you enable the Stats checkbox for the viewport (underneath Realtime in the down arrow drop down in the top left of the viewport).

As for your input issues the thing for you to look in to is creating an FEdMode subclass and then you’ll need to register and activate it with the FEditorModeTools class returned by GEditorModeTools(). The editor mode has the various InputKey, Axis, etc. functions and will receive the call before the viewport itself does. If the mode handles the input (returns true) then the viewport doesn’t get the input.

Dear Marc,

Woohoo!

I was hoping to hear from you!

Yes I always had the sense I wanted to / needed to create my own editor mode.

But I did not have the key info about GEditorModeTools(), thanks!


DrawDebug

DrawBug commands still did not work for me after enabling Stats.

my pic and code below :slight_smile:


How would user activate an Editor Mode?

So basically the conclusion is that as a rocket user I can make an ed mode and use that to capture input

And I’ve extended UnrealEngine to be able to trigger the ed mode myself.

Buuuut

How would a user press a key to activate an editor mode, since I cannot capture input from just extending UnrealEdEngine?


At the moment the only way I know to interact with the user from within UnrealEdEngine is to capture selection events.


#Regarding DrawDebug

void UVictoryEdEngine::NoteSelectionChange()
{
	if(!GetSelectedActors()) return;
	AActor* SelectedActor = Cast(GetSelectedActors()->GetTop(AActor::StaticClass()));
	if(!SelectedActor) return;
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
	UE_LOG(Victory, Warning, TEXT("New Selected Actor %s"), *SelectedActor->GetName() );
	UE_LOG(Victory, Warning, TEXT("New Selected Actor Location %s"), *SelectedActor->GetActorLocation().ToString() );
	/*
	//whats going on in editor land?
	for ( TObjectIterator It; It; ++It )
	{
		UE_LOG(Victory, Warning, TEXT("EditorLand: %s"), *It->GetName() );
	}
	*/
	
	//Determine Active Viewport to GetWorld from
	for(int32 Itr = 0; Itr < LevelViewportClients.Num(); Itr++ )
	{
		if(!LevelViewportClients[Itr]->IsLevelEditorClient()) continue;
		if(!LevelViewportClients[Itr]->IsVisible()) continue;
		UE_LOG(Victory, Warning, TEXT("This one is visible %d"), Itr );
		
		DrawDebugString(
			LevelViewportClients[Itr]->GetWorld(),
			FVector(0,0,64), 
			SelectedActor->GetName(), 
			SelectedActor, 
			FColor(255,0,255),
			2
		);
		
		//UpdateSingleViewportClient(LevelViewportClients[Itr], true, true );
		
	}

	//or use GCurrentLevelEditingViewportClient
	DrawDebugPoint(
		GCurrentLevelEditingViewportClient->GetWorld(),
		SelectedActor->GetActorLocation(), 
		7, 
		FColor(255,0,255),
		false,
		2
	);
	
	//or try GWorld
	DrawDebugPoint(
		GWorld,
		SelectedActor->GetActorLocation(), 
		7, 
		FColor(255,0,255),
		false,
		2
	);
	
	//UpdateSingleViewportClient(GCurrentLevelEditingViewportClient, true, true );
}

Looking closer atthe drawing stuff, DrawDebugString/Point are using the PlayerController’s HUD and no such thing will exist in the Editor World. You may be able to call GetDebugCanvas() on the Viewport and write to that but you won’t get any of the duration management as those are members of the HUD that then write to its Canvas. You would need to build your own output management system that writes out to the Canvas each frame. I’m also not certain whether that function is exposed in such a way that you will be able to link to it.

I’ll let Matt see if he can help you out on the EdMode activation portion of your question.

I dont know if a sceneview is within my reach from UnrealEdEngine,

I tried the following:

GCurrentLevelEditingViewportClient->GetViewportClient()->SceneViewport->GetDebugCanvas()

got stuck here:

GetViewportClient()-

because that function was part of a cursor location struct not something I could reach from GCurrentLevelEditingViewportClient directly :slight_smile:

the other places I could get DebugCanvas were unrealclient and gameengine, neither of which I figured would be useful :slight_smile:

Definitely seems that extending EdMode and using DrawHUD will be my best bet, I have separate question on my attempts to do that here:

https://rocket.unrealengine.com/questions/13137/how-can-i-extend-fedmode-or-fgeometryedmode.html

Thanks for the help Marc!

#Happy Holidays!

Rama

#Got a Compile

Well I got this to compile, will let you know if I get further with it, thanks for the idea Marc!

//FViewport* GetActiveViewport(); //EditorEngine.h
FCanvas* UVictoryEdEngine::GetCurViewportDebugCanvas()
{
	return GetActiveViewport()->GetDebugCanvas();
}

#UnrealEdEngine told me to ask you for help

Well,

that debug canvas is always null… so I"m out of ideas :slight_smile:

(yes I did have realtime turned on)

//GET A DEBUG CANVAS
	if(GetCurViewportDebugCanvas())
	{
		UE_LOG(Victory, Warning, TEXT("WooHOO GOT A VALID CANVAS"));
	}
	else
	{
		UE_LOG(Victory, Warning, TEXT("Ask Epic for Help"));
	}

The debug canvas is only available during draw calls because otherwise it is unsafe to use. You should just use DrawHUD if you are using an editor mode. I responded to your other question about setting up an editor mode as well.

Thanks Matt and Marc!

:slight_smile:

Rama

As a follow up to the help of you Marc Audy, and you Matt,

as well as help from Wraiyth (forum name),

I have finally got this whole process working!

I did indeed implement my own editor mode as suggested by Matt.

The code for how I did this is here

https://rocket.unrealengine.com/questions/13176/how-to-properly-initialize-register-a-custom-edito.html

Pic of the results for your entertainment

#Thanks Again!

Thanks for the help!

Rama

Just wanted Marc Audy and Matt to see my thank you picture above

If someone wants this post to be checked off, please forward Marc and Matt this post so they get my picture

hee hee!

#:heart:

Rama