x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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!

Product Version: UE 4.15
Tags:
more ▼

asked Apr 27 '17 at 08:45 PM in C++ Programming

avatar image

GospodinNoob
1 1 2

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

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 https://docs.unrealengine.com/latest/INT/Programming/Plugins/

more ▼

answered Apr 28 '17 at 10:56 AM

avatar image

Benergy
801 21 4 27

(comments are locked)
10|2000 characters needed characters left

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

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

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

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

Также хорошее руководство 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();
 
 };
 






more ▼

answered Jan 11 '19 at 11:09 PM

avatar image

Proggi
3 1 1

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question