Dear Friends at Epic!
This is the Chronicle of my attempts to create an Editor Mode
I hope you find it entertaining at the very least
( I dont know what I am doing cause all of this is undocumented )
Please note I am at no point claiming my code should make sense, and if it doesnt please do correct me
The only thing I can proclaim is that it compiles
#The Summary
I’ve made a basic FEdMode and when I try to register it (not even run it, just register it), the Editor crashes without any useful callstack info.
I am probably missing many things I should be doing, cause all I am doing is assigning the ID for the EdMode before trying to register it.
A sub-question of this thread is, how do I properly make a TSharedRef?
Please see my code below for details
Thanks!
#The FVictoryEdAlignMode.h
#pragma once
#include "UnrealEd.h"
#include "Editor.h"
class FVictoryEdAlignMode : public FEdMode
{
public:
void JoyInit();
public:
FVictoryEdAlignMode();
~FVictoryEdAlignMode();
public:
virtual void Enter() OVERRIDE;
};
#FVictoryEdAlignMode.cpp
// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.
//Victory Alignment Mode
#include "VictoryGame.h"
FVictoryEdAlignMode::FVictoryEdAlignMode(){}
FVictoryEdAlignMode::~FVictoryEdAlignMode(){}
void FVictoryEdAlignMode::JoyInit()
{
ID = FName("VictoryEditorMode");
}
void FVictoryEdAlignMode::Enter()
{
UE_LOG(Victory, Warning, TEXT("Entered Joy Mode!"));
}
Registering the Mode in UnrealEdEngine
I have extended UnrealEdEngine and I run this code when user clicks on an actor.
I have verified that this process works and the code is being run.
void UVictoryEdEngine::NoteSelectionChange()
{
Super::NoteSelectionChange();
//~~~~~~~~~~~~~~~~~
if(!CreatedVictoryEdMode)
{
//Proper way to make a shared ref ???
FVictoryEdAlignMode NewMode = FVictoryEdAlignMode();
//Create VictoryEdMode
TSharedRef VictoryEdMode(&NewMode);
//Init VictoryEdMode
NewMode.JoyInit();
//Register
//GEditorModeTools().RegisterMode(VictoryEdMode);
CreatedVictoryEdMode = true;
}
//Activate
//GEditorModeTools().ActivateMode(FName("VictoryEditorMode"));
}
#TSharedRef ?
What is the proper way to initialize a TSharedRef?
I dont have any .cpp files from any of the ue4 samples to refer to this, as they usually call a function that returns a sharedref.
#Module Startup?
Since I am not using a module to handle the FEdMode, is there anything that I should know about to make the editor mode register happily?
#Super?
Do I need to call any functions in my custom EdMode class like this?
void FVictoryEdAlignMode::Enter()
{
FEdMode::Enter(); //Super?
}
#The Progress
This pictures shows that
-My extended UnrealEdEngine class is working
-The actor click event is occurring, in which the create editor mode code is running
-The custom editor mode does get created
-The custom editor mode does get initialized with its unique ID before being Registered
-I commented out the actual registration part to take this pic since that causes the crash
#Thanks!
Thanks in advance!
Rama