# Write a plugin with c++ class and function

**URL:** <https://forums.unrealengine.com/t/write-a-plugin-with-c-class-and-function/392095>\
**Category:** Plugins\
**Tags:** Class, UE4-15, unreal-engine, Plugins, CPP, question\
**Created:** [April 27, 2017, 8:45pm UTC](https://forums.unrealengine.com/t/write-a-plugin-with-c-class-and-function/392095 "2017-04-27T20:45:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GospodinNoob](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GospodinNoob](https://forums.unrealengine.com/u/GospodinNoob)\
**Post date:** [April 27, 2017, 8:45pm UTC](https://forums.unrealengine.com/t/write-a-plugin-with-c-class-and-function/392095/1 "2017-04-27T20:45:19Z")

</div>

Firstly sorry for my einglsh, i am not a native speaker)

It’s a strange question, but can sombody give an empty project example with plugin with class with function (int GetInt() which returns 5 for example). And with an actor which call this function.

In fact, i can’t write a code myself. I can create a plugin and write function, but when i try t use it, i get a lot or errors. If somebody can create this example project it will be very cool, becouse i can’t find any examples or tutorials on current engine version.

Thanks for help!

---

<div class="post-metadata">

**Author:** ![Benergy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Benergy](https://forums.unrealengine.com/u/Benergy)\
**Post date:** [April 28, 2017, 10:56am UTC](https://forums.unrealengine.com/t/write-a-plugin-with-c-class-and-function/392095/2 "2017-04-28T10:56:44Z")

</div>

Have you had a look at the BlankPlugin that comes with the UE source code? It’s under /Engine/Plugins/Developer/BlankPlugin. You can copy the uplugin file and the folders “Source” and “Resource” (no need to copy the others, they are created automatically) to a new plugin folder. Then you can rename every occurance of “BlankPlugin” to your plugin’s name and then add you class in the cpp/h files under Source.

You can find some general information about plugin creation and the uplugin file and the meaning of its parameters under [Plugins | Unreal Engine Documentation](https://docs.unrealengine.com/latest/INT/Programming/Plugins/)

---

<div class="post-metadata">

**Author:** ![Proggi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Proggi](https://forums.unrealengine.com/u/Proggi)\
**Post date:** [January 11, 2019, 11:09pm UTC](https://forums.unrealengine.com/t/write-a-plugin-with-c-class-and-function/392095/3 "2019-01-11T23:09:11Z")

</div>

// For moderator: I wrote answer in rus because this guy dont speak eng good, hope u`ll send my answer.

То,что тебе нужно называется не плагин, а класс.

Советую почитать для начала уроки по с++.

Для того что тебе нужно - раздел “Указатели”, но лучше читай все.

Также хорошее руководство [Programming with C++ | Unreal Engine Documentation](https://docs.unrealengine.com/en-us/Programming) .

В интернете полно уроков на русском как видео, так и текстовых, например,на хабре, по c++ в ue4.

Если это сложно, то разберись с blueprint-ами, там не нужно знать программирование,только логика, уроков еще больше чем по с++.

По твоей задаче я создал 2 класса: NewActor и NewFunctionActor, можно создать класс с функцией но в ue4 все объекты на сцене - Actor. Достаточно перенести на сцену NewActor и при запуске в окне Output Log ты увидишь “LogTemp: Warning: Returned value: 5”

**NewActor.Cpp**

```
#include "NewActor.h"

// Sets default values
ANewActor::ANewActor()
{
 	// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void ANewActor::BeginPlay()
{
	Super::BeginPlay();
	int Value = funcPointer->NewFunction();
	UE_LOG(LogTemp, Warning, TEXT("Returned value: %d"), Value);
	
}

```

**NewActor.h**

```
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "NewFunctionActor.h"
#include "NewActor.generated.h"

UCLASS()
class FUNCTIONEXAMPLE_API ANewActor : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ANewActor();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	UPROPERTY()
	ANewFunctionActor* funcPointer;

};

```

**NewFunctionActor.cpp**

```
#include "NewFunctionActor.h"

// Sets default values
ANewFunctionActor::ANewFunctionActor()
{
 	// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void ANewFunctionActor::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void ANewFunctionActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

int ANewFunctionActor::NewFunction()
{
	return 5;
}

```

**NewFunctionActor.h**

```
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "NewFunctionActor.generated.h"

UCLASS()
class FUNCTIONEXAMPLE_API ANewFunctionActor : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ANewFunctionActor();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UFUNCTION()
	int NewFunction();

};
```
