How do I reuse C++ scripts between projects?
Coming from a decade in Unity I am finding this the most confusing thing of all so far. If I write a C++ class in ProjectA then it seems that code can only ever be used in ProjectA. What am I missing here?
UE4 has no "Import C++" option that I can see... VS2017 has an "Add existing" option which only seems to copy in a link to the file as the file is not copied over to the project and in VS I actually see 2 copies of the .h and the .cpp if I tell UE4 to create the class for me again.
I am writing utility classes that I intend to use in all future projects and yet UE4 seems to say "Nope. Start from scratch and rewrite all code every time". Surely this must be wrong... so what am I missing here? :(
Also, please note that I also can't go into the original project and select an Actor or Pawn that the code may be on to generate some sort of package from it since my code is not derived from any of the classes that allows it to be placed in the scene. Plain, non-subclassed classes which are then subclassed by my other classes, all making use of FString and other UE4 classes... not visible in the editor at all, no way to move it into another project...
Can it be that an engine as powerful as UE4 lacks this simple ability to let you reuse code between projects??? :O
Please advise. Thanks.
asked Jan 27 '19 at 11:38 PM in Using UE4
Provided the class files (.h and .cpp) that you're copying don't rely on other, un-copied classes from the original project, you should be able to copy what you need over and get things working with little effort.
Off the top of my head, I can think of just a handful of short steps you'll need to take to adapt your code from ProjectA to make it work with ProjectB:
For a better explanation of why these steps are needed, have a look at this Managing Game Code article in the UE4 official docs. The latter half of that document is probably of more relevance in your case.
Hopefully this sheds some light on the subject and helps move you forward!
answered Jan 28 '19 at 05:05 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here