I have a plugin that I am working on, and I need to add a new class to it. The ‘add code to project’ feature from the UE editor will not let me, as I am restricted to adding to the Source folder.
If I manually create a new .cpp, when I refresh the visual studio project it vanishes.
1-Close Visual Studio
2-Go to your plugin classes folder
3-Add 2 empty files TestActor.h and TestActor.cpp
4-Then , "Generate Visual Studio Project
5-Open Visual Studio , then the files created
TestActor.h
#pragma once
#include "GameFramework/Actor.h"
#include "TestActor.generated.h"
UCLASS()
class ATestActor : public AActor
{
GENERATED_UCLASS_BODY()
};
Hi, thanks for getting back to me. I used your code, and make the files, but it still will not compile.
TestActor.cpp
#include "m2uPluginPrivatePCH.h" //cannot find this file, it is linked in every cpp in the plugin. It is in the 'Private' folder though, is this why?
#include "TestActor.h"
ATestActor::ATestActor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) //ObjectInitializer is not a type name.
{
}
TestActor.h
#pragma once
#include "GameFramework/Actor.h"
#include "TestActor.generated.h" //cannot open file
UCLASS() //Type name is not allowed.
class ATestActor : public AActor
{
GENERATED_UCLASS_BODY() // expected a ')'
};
I think a more appropriate answer would be: open Unreal Editor, go to File → New C++ Class, choose the base class and hit Next, and change the module (the dropdown just right of the class name) to your plugin.
I suppose the plugin must reside in the project folder for this to work though (not in the engine folder).
@antithing add new C++ class from editor level… pick base class (actor, object, component, etc), click next. Then you have a module dropdown next to its name… pick module that is your plugin. it will be generated appropriately