Write a plugin with c++ class and function

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!

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

// 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 .

В интернете полно уроков на русском как видео, так и текстовых, например,на хабре, по 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();

};