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"

Using c++ actors from a plugin

Hello!

I'm working on a project with some friends and we want to create a tool to help our game designers to tweak all game feel (and 3C) related variables. We want the tool to be used in editor mode but also during the play mode (PIE). The changes made during the play mode must be applied on the object even if we stop the play mode.

The current work :

  • I created an empty c++ project, called ActorLinking, to make things easier. I created a dummy actor, called TheActor. This actor is a part of the project.

  • Then I created a small plugin, called ThePlugin, to add a button in the editor.

  • When I click on this button, I retrieve the dummy actor in the scene from the editor world or the engine world.

The problem :

  • I get a linker error when I try to use any functions of this actor (See image)

  • List item

The project file : (.uproject)

 {
     "FileVersion": 3,
     "EngineAssociation": "4.21",
     "Category": "",
     "Description": "",
   "Modules": [
     {
       "Name": "ActorLinking",
       "Type": "Runtime",
       "LoadingPhase": "Default",
       "AdditionalDependencies": [
         "Engine"
       ]
     }
   ]
 }

The actor header :

 #pragma once
 
 #include "CoreMinimal.h"
 #include "GameFramework/Actor.h"
 #include "TheActor.generated.h"
 
 UCLASS()
 class ACTORLINKING_API ATheActor : public AActor
 {
     GENERATED_BODY()
     
 public:    
     ATheActor();
 
     UFUNCTION()
     void MoveActor();
 
 protected:
     virtual void BeginPlay() override;
 
 public:    
     virtual void Tick(float DeltaTime) override;
 };

The actor implementation : (TheActor.cpp)

 #include "TheActor.h"
 
 ATheActor::ATheActor() {
     PrimaryActorTick.bCanEverTick = true;
 }
 
 void ATheActor::BeginPlay() {
     Super::BeginPlay();
 }
 
 void ATheActor::MoveActor() {
     UE_LOG(LogTemp, Warning, TEXT("MoveActor"));
 }
 
 void ATheActor::Tick(float DeltaTime) {
     Super::Tick(DeltaTime);
 }

And now the code of the plugin : (.uplugin)

 {
  [...]
  "Modules": [
   {
    "Name": "ThePlugin",
    "Type": "Editor",
    "LoadingPhase": "Default",
   }
  ]
 }

The build file (ThePlugin.Build.cs) :

 using UnrealBuildTool;
 
 public class ThePlugin : ModuleRules
 {
     public ThePlugin(ReadOnlyTargetRules Target) : base(Target)
     {
         PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
         
         PublicIncludePaths.AddRange (new string[] {});
         PrivateIncludePaths.AddRange(new string[] {});
             
         PublicDependencyModuleNames.AddRange (new string[] {"Core", "ActorLinking" });
         PrivateDependencyModuleNames.AddRange(
             new string[]
             {
                 "Projects",
                 "InputCore",
                 "UnrealEd",
                 "LevelEditor",
                 "CoreUObject",
                 "Engine",
                 "Slate",
                 "SlateCore",
                 "ActorLinking" // The module of the project
             }
             );
         
         DynamicallyLoadedModuleNames.AddRange(new string[]{});
     }
 }

And finally the code causing the linker error : (ThePlugin.cpp)

 void FThePluginModule::PluginButtonClicked()
 {
     [...]
     ATheActor* p_actor = nullptr;
 
     /* Getting the actor */
 
     p_actor ->MoveActor(); // MoveActor undefined reference
 
     [...]
 }

I'm new to Unreal Engine so it makes me think I'm doing it wrong. I'm trying to figure out why it doesn't work. It seems to work with propertyies but not with functions. I'm unable to find appropriate ressources that's why I'm posting here. Thank you for your help!

Product Version: UE 4.21
Tags:
error.jpg (36.1 kB)
more ▼

asked Dec 07 '18 at 01:19 PM in C++ Programming

avatar image

Aredhele
1 1 2

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

1 answer: sort voted first

Hello,

you also need to fill the "PublicIncludePaths" ( and "PrivateIncludePaths" if required) in the "ThePlugin.Build.cs" file

exemple :

 PublicIncludePaths.AddRange( new string[] { "ActorLinking/Public" });

be sure tu put the correct path depending of your actor header file location

edit: with additional comment of the final answer :

You need to have it in the following syntax :

 #include "ModuleName/Path/TheActor.h"

so in your exemple that could be

 #include "ActorLinking/Public/TheActor.h"
more ▼

answered Dec 07 '18 at 02:05 PM

avatar image

Firefly74
1.2k 9 15 29

avatar image Aredhele Dec 07 '18 at 02:30 PM

Hey,

Thank you for your time! I filled the public and private include path with the right path but there is still the linker error

avatar image Firefly74 Dec 07 '18 at 02:51 PM

do you also have the correct include in "ThePlugin.cpp" ?

avatar image Aredhele Dec 07 '18 at 04:25 PM

For now, I have #include "TheActor.h"

avatar image Firefly74 Dec 07 '18 at 04:35 PM

You need to have it in the folowing syntax :

 #include "ModuleName/Path/TheActor.h"


so in your exemple that could be

 #include "ActorLinking/Public/TheActor.h"


avatar image Aredhele 4 days ago

Hi, I tried with "ActorLinking/Public/TheActor.h" but it doesn't work :/ I will check all from the beginning

avatar image Aredhele 4 days ago

So everything was okay with the right include paths.

And... after having refreshed the visual studio solution, cleaned up the solution, and rebuilt everything, no more linker error :) Thank you for your help!

(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