# Using a plugin in C++ code

**URL:** <https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602>\
**Category:** Plugins\
**Tags:** unreal-engine, Plugins, CPP, question\
**Created:** [March 20, 2014, 10:16pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602 "2014-03-20T22:16:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![fszczemton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fszczemton](https://forums.unrealengine.com/u/fszczemton)\
**Post date:** [March 20, 2014, 10:16pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/1 "2014-03-20T22:16:08Z")

</div>

Hi,

I want to use a plugin which is available in the engine source tree. Exactly that is:  
_Engine/Plugins/Runtime/CustomMeshComponent_  
How can I do that?

More details:

In a fresh project the UCustomMeshComponent class is not visible for the compiler. Do I have to include a specific file?  
I tried with some combinations like “runtime/CustomMeshComponent.h” but it doesn’t work.

I also copy-pasted the CustomMeshComponent folder into my project’s plugins folder, however during compilation got errors that such a plugin is already registered, so it should be accessible to me straight away I guess.

---

<div class="post-metadata">

**Author:** ![fszczemton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fszczemton](https://forums.unrealengine.com/u/fszczemton)\
**Post date:** [March 23, 2014, 3:07pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/2 "2014-03-23T15:07:16Z")

</div>

Ok, solved this:

In MyProject.build.cs I added the following lines:

```
PrivateDependencyModuleNames.AddRange(new string[] { "CustomMeshComponent" });
PrivateIncludePathModuleNames.AddRange(new string[] { "CustomMeshComponent" });

```

And then in the file which wanted to use this custom mesh component it was enough to include it like that:

```
#include "CustomMeshComponent.h"
```

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 23, 2014, 5:34pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/3 "2014-03-23T17:34:56Z")

</div>

Thank you for sharing your solution!

#❤

Rama

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [March 23, 2014, 7:29pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/4 "2014-03-23T19:29:29Z")

</div>

fszczemton,

Your solution works, but keep in mind that the plug-in is now no longer really a plug-in: it became a hard dependency that is statically linked to your project, which means that your project is coupled to the plug-in and won’t work if the plug-in is missing.

We generally discourage the adding of hard dependencies to plug-ins, because for plug-ins to be truly pluggable, the application consuming those plug-ins shouldn’t have to know about what those plug-ins are. If the app needs to know which plug-ins exist, then what’s the point of having plug-ins? 🙂

That being said, if you want to go this path anyway, you may want to consider making it a somewhat less tight coupling by using DynamicallyLoadedModuleNames in combination with PrivateIncludePathModuleNames instead. This will then allow you to do a LoadModule() in your code and fail gracefully in case the plug-in is missing.

If you do not need access to any of the implementation details of the plug-in, but you simply want to load the plug-in as part of loading your game or your game’s Editor, then it is sufficient to ~~add the plug-in as a dependency to your game’s Engine.ini~~ mark the plug-in as enabled in the .uplugin file.

---

<div class="post-metadata">

**Author:** ![fszczemton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fszczemton](https://forums.unrealengine.com/u/fszczemton)\
**Post date:** [March 24, 2014, 8:54pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/5 "2014-03-24T20:54:23Z")

</div>

Thanks for the explanation. I wasn’t aware of the other possibilities and it’s really helpful of you to explain it more precisely - that will definitely be useful in the future 🙂 E.g. having that mesh plugin as a hard dependency rules-out HTML5 and that should be handled well.

I think in my case having a hard dependency would actually make sense, because I wanted to use the plugin to generate terrain geometry, which is crucial, however to have more control I’ll eventually implement my own code based on the CustomMeshComponent as example.

I am also wondering - is it possible for the plugin to be missing? I’m the person who has the local installation of engine and would package the game, so it’s hard to imagine such a situation for me.

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [March 24, 2014, 9:14pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/6 "2014-03-24T21:14:12Z")

</div>

Once you statically link to the plugin’s module you have a hard dependency and the module must be present, or otherwise the game will fail to load. You could also create a so called monolithic binary, in which case all dependencies would be compiled and linked into a single huge executable. There would be no DLLs in that case (except for third party dependencies maybe).

That being said, I’m not 100% sure to what extent we already support monolithic linking of plugin modules. I remember that a couple months ago there were still problems with that approach. You may want to start a separate AnswerHub thread if you’re interested in more details.

Another thing to be aware of when hard linking to plugin modules is that you effectively stop using the module as a plugin - it becomes a library instead. This may have subtle undesired side effects. For example, what happens if the plug-in gets updated and its API changes? You would have to recompile your own project, or else it will crash on start or have other undefined behavior.

---

<div class="post-metadata">

**Author:** ![fszczemton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fszczemton](https://forums.unrealengine.com/u/fszczemton)\
**Post date:** [March 25, 2014, 8:18pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/7 "2014-03-25T20:18:18Z")

</div>

Thanks a lot for all the details, really interesting stuff. I definitely don’t want to make anything fancy with the build system. And yes, somehow I forgot that a plugin, being a plugin, can change its API without notice and cause problems.  
I’ll have to roll-out my own custom mesh code which will be quite educating I guess.

---

<div class="post-metadata">

**Author:** ![Kinsmen\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kinsmen\_1](https://forums.unrealengine.com/u/Kinsmen_1)\
**Post date:** [September 21, 2014, 12:47am UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/8 "2014-09-21T00:47:33Z")

</div>

"then it is sufficient to add the plug-in as a dependency to your game’s Engine.ini "

I did this and it was still not enough.

```
[Plugins]
EnabledPlugins=CustomMeshComponent

```

Was this not enough? Did I not put this code in the right location?

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [September 21, 2014, 4:53pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/9 "2014-09-21T16:53:00Z")

</div>

You are right, this has recently changed. Whether plug-ins are enabled or disabled is now saved in the .uplugin file itself, no longer in the project’s Engine.ini file.

In the .uplugin file, add the following setting:

```
"EnabledByDefault" : true

```

Take a look at existing plug-ins for other settings that may have changed.

---

<div class="post-metadata">

**Author:** ![Kinsmen\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kinsmen\_1](https://forums.unrealengine.com/u/Kinsmen_1)\
**Post date:** [September 21, 2014, 7:29pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/10 "2014-09-21T19:29:05Z")

</div>

Ok, I’ve noticed that “EnabldByDefault” : True is already written in the source.

So, I am out of ideas as to why I am having this problem.

I cant use #include CustomMeshComponent.h … the editor cant see it.

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [September 25, 2014, 7:29pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/11 "2014-09-25T19:29:37Z")

</div>

“the editor can’t see it” - what exactly do you mean by that?

Where in the Editor are you trying to use the new class? If it’s in a blueprint, did you mark the class as BlueprintSpawnable?

```
meta=(BlueprintSpawnableComponent)

```

---

<div class="post-metadata">

**Author:** ![Kinsmen\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kinsmen\_1](https://forums.unrealengine.com/u/Kinsmen_1)\
**Post date:** [September 25, 2014, 8:18pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/12 "2014-09-25T20:18:39Z")

</div>

Sorry.

I am trying to use the plugin to create a custom mesh in c++. However, when I write

```
 #include CustomMeshComponent.h

```

I get a red squiggly line and an error stating that the compiler cannot find the file.

---

<div class="post-metadata">

**Author:** ![rajkosto](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rajkosto](https://forums.unrealengine.com/u/rajkosto)\
**Post date:** [September 25, 2014, 8:23pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/13 "2014-09-25T20:23:53Z")

</div>

You need to add CustomMeshComponent to your private or public dependencies in your module’s build.cs file as the first answer indicates.

---

<div class="post-metadata">

**Author:** ![Kinsmen\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kinsmen\_1](https://forums.unrealengine.com/u/Kinsmen_1)\
**Post date:** [September 25, 2014, 8:57pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/14 "2014-09-25T20:57:45Z")

</div>

Ok, I thought that creates a hard dependency, which isnt desired.

> Another thing to be aware of when hard linking to plugin modules is that you effectively stop using the module as a plugin - it becomes a library instead. This may have subtle undesired side effects. For example, what happens if the plug-in gets updated and its API changes? You would have to recompile your own project, or else it will crash on start or have other undefined behavior.

---

<div class="post-metadata">

**Author:** ![Kinsmen\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kinsmen\_1](https://forums.unrealengine.com/u/Kinsmen_1)\
**Post date:** [September 25, 2014, 8:59pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/15 "2014-09-25T20:59:06Z")

</div>

Are you saying there isnt a way to implement this in C++ without forcing a hard dependency?

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [September 25, 2014, 9:27pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/16 "2014-09-25T21:27:21Z")

</div>

If you want this to be a plug-in, then you should neither #include nor link that module.

It sounds to me like you’re trying to make this a regular library module, not a plug-in. If you need access to this module from another module, then it should not be a plug-in.

---

<div class="post-metadata">

**Author:** ![Kinsmen\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kinsmen\_1](https://forums.unrealengine.com/u/Kinsmen_1)\
**Post date:** [September 25, 2014, 10:23pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/17 "2014-09-25T22:23:55Z")

</div>

is there an example on how to use the module in code as a plug in?

---

<div class="post-metadata">

**Author:** ![Kinsmen\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kinsmen\_1](https://forums.unrealengine.com/u/Kinsmen_1)\
**Post date:** [September 25, 2014, 10:26pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/18 "2014-09-25T22:26:48Z")

</div>

I guess I dont understand how one would use this code- other than from another module. I just want to use it how it was intended to be used.

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [October 17, 2014, 2:36pm UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/19 "2014-10-17T14:36:52Z")

</div>

You do not “use” a plug-in in your code. A plug-in is programmed against an interface that is already provided by your code, and the plug-in registers itself with that. Your code is not aware about what exactly the plug-in is.

We have a number of plug-ins in our code base already. Take a look at the /Engine/Plugins/ directory.

---

<div class="post-metadata">

**Author:** ![Xender](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Xender](https://forums.unrealengine.com/u/Xender)\
**Post date:** [January 31, 2015, 10:19am UTC](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602/20 "2015-01-31T10:19:51Z")

</div>

It not working for me, I add Denepndencies in build.cs, than #include “CustomMeshComponent.h” in my code but it is not recognized.  
Should I copy somethig?

[Next page](https://forums.unrealengine.com/t/using-a-plugin-in-c-code/277602.md?page=2)
