Mixing Blueprint and C++

Many times the question has been asked, which to use Blueprint or C++, and always people say that it is best to use both at the same time.
So, how is this done? I have a game which I started making as a Blueprint third person template, so now if I have to use C++ how do I do so?

“Have to” is a strong word. If you are running into performance issues with your blueprint solution, then absolutely start identifying systems / sections of your current blueprint that you could migrate over to a UObject/AActor/Component/Whatever.

For example, if I have a “Wall Climbing” blueprint that allows my character to climb surfaces, it’s potentially pretty expensive. It’s probably doing some raycasts, managing a state machine, driving animations, etc. It’s also very independent in that it doesn’t really care what character is trying to climb what wall, it’s generic. It’s just a system that allows a certain behavior. That’s actually the perfect match for a Component. You could create a new Component (“WallClimbingComponent”), implement your functionality, and then just add that component to any characters you want. You have the same functionality, without the overhead a blueprint may entail.

Does that make sense? Basically, feel free to author whatever in Blueprints if that’s what you’re comfortable with. Once you have a system done, maybe consider moving it to C++ if you feel it’s pretty stable and you aren’t changing it much.

I think the most correct answer is “whatever works best for your team”. Everyone has different workflows and skills on a team which will require different things.

That being said, the way we do it is, we build core frameworks in C++ and then build Blueprints for the LDs to use. For example, we created a spawn point. I wrote the whole thing in C++ and exposed all the properties that were needed to spawn various amounts of enemies and types. Then I created a BP that inherits from the C++ class for our LDs to use when they are putting levels together. Now, they can just drop that in a level and tell it what they want to spawn and how many.

We have done the same thing for our pawns as well but that is a bit more complicated.

The reason we did this is because I (as the primary developer) find C++ easier to maintain when there is a lot of stuff going on, esp when it comes to math. So I write everything in C++ and expose what needs to be exposed via the Blueprints. This allows our LD or Artists to add what they want via Blueprints and the core functionality stays in C++.

Another way to look at the way we did it is all of the functionality is in C++ and the UI layer of all of the objects is in BPs. That is a firm rule we stick to. I don’t do any UI dev in C++, the workflow is simply too slow and I like the feel of doing it in BPs as well. Obviously things like spawn points are not UI, this is in addition to that.

As an indie dev studio we have found that making things as modular as possible and empowering non-programmers to add functionality is very important to the dev cycle. This workflow allows that while keeping a programmers workflow smooth.

Don’t add C++ because you think you need C++. Remember that a lot of people giving advice in the forums may be in a very different situation from you. The needs of a large AAA studio are different from the needs of a mid-size contract shot, which are different from the needs of a small indie team, which is different from the needs of a 1-3 person studio. There is no one-size-fits-all “best”.

For us, we do almost always create a C++ class and then descend our Blueprints from that custom class instead of from engine classes. That gives us the ability to move complicated, slow, or troublesome blueprints into code without having to deal with reparenting the blueprint. But, we’re a contract programming shop. All of our programmers know multiple languages and most have been doing text-based OO languages for a decade or more. For us, we’re not going outside of our comfort zone when we use C++. Also, we do mostly mobile work, and a lot of times, we’re pushing pretty hard on the limits of what current mobile devices are capable of. For us, it can be really helpful to get processor intensive stuff out of BP and into C++.

But, if you don’t already know C++, don’t force yourself to use it because you think it’s the “right” way, or the “serious” way, or because somebody told you it’s “best”. If you’re comfortable with Blueprint, there’s no reason not to use Blueprint, at least until and unless you have a problem that can’t be solved with BP. There’s a very good chance you never will such a problem. Epic isn’t pushing Blueprint as a gateway drug to C++… they fully intend it to be a first class citizen capable of doing full, complete, professional games.

Guys, Im a complete begginer at this, as such have understood very little. I was following the youtube videos and making something using what I learnt, and have come upon the videos based on programming. So, as I am solo and don’t have any team, am just working on learning UE4. So, my quetions isn’t should I use C++ or not, nor when to use C++ or stuff like that.
It is pretty simple, I have a game made from a BP template and want to use C++ as if I had started from a C++ template. Do I have to start over or is it possible to add code to my existing project?
Also, if I start using a C++ template, how do I use Blueprints?
A good example would be in the first answer, all I want to know is “How to add the component, and where exactly do I make it(somewhere else, visual studio, new project etc.)”.

You do not have to start over. From the File menu just select “Add Code to Project”. You must have Visual Studio installed (Xcode if you’re on a Mac). There’s no difference between a C++, Blueprint or mixed project, they’re just different templates. A C++ template will have the starter code as C++ (with some Blueprint). The Blueprint template will have all starter code in Blueprint. You can add code to a project at any time.

If you are doing math intensive things, I suggest you make those in C++ as math nodes in BPs take up a lot of room, and are harder to read than standard C++ math. Math should also be fairly easy to migrate to C++. I am working on a game that generates a random world (like minecraft). It is also quite slow, so I will be migrating to C++ (I haven’t yet, feel free to answer my question on my profile). I also will want to take advantage of multi-threading, I don’t want the frame rate to drop as soon as it generates a new section of the game.

If you are doing something like math in C++, and already have an example, it should be pretty much copy-paste for most of the time without the need of too much C++ knowledge.