Adding an Actor class to plugin?

This might be a ridiculous question, but…

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.

How should I be doing this?

Thanks!

Yeah you have to add them through VS so it can generated the ‘Generated Headers’ but buggered if I can remember how…

See if this helps:

here is a way to do it:

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()

};

TestActor.cpp


#include "MyPluginPCH.h"
#include "TestActor.h"

ATestActor::ATestActor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{

}

PS : No class constructor in the header needed

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 have added the errors in //

Am I missing something here?

thanks again!

In the test I made there all the files are in private folder

Make sure your plugin Build.cs have these included



PrivateDependencyModuleNames.AddRange(
			new string] {
                                "Core",
				"CoreUObject",
				"Engine",
                                "InputCore",
				"UnrealEd"
			}


1 Like

and this too


 PrivateIncludePaths.Add("TestPlugin/Private");

Ah I didn’t have them in the Private folder. Many thanks! Works great. :slight_smile:

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 :slight_smile:

1 Like
  1. Open Editor, in file search for create C++ class.
  2. Choose parent class.
  3. From there, you should choose your file path, where you can pick run-time plugin.
2 Likes

you are right about it. :ok_hand:

2 Likes