Examples of when to use Blueprints vs C++

Hi, I’ve read that for the base gameplay C++ should be used and then Blueprints to extend the gameplay. Can you mention some practical examples on when C++ should be used and when Blueprints? I don’t really know what can be understood like the base or the extension.

Thanks

I’d recommend checking out one of the beginner UE4 C++ series out there to really get your hands on this and understand it better but I’ll give you a brief example.

In C++ you would edit your ACharacter and add a cool dodge ability for the character. Then in BP you create an instance of your ACharacter class and set it’s values. For example, if you want to tweak the “dodge speed” variable you can play with it in the BP (much faster than changing the C++ value and recompiling). BP’s are also good for adding references. For example, if you want to add a skeletal mesh to your character so they actually look like something you would do that in BP. This way you don’t need to hardcode asset locations in C++. You could change the name of the mesh or move what folder it’s in and the reference won’t break.

Other than all this BP is good for some light scripting in certain scenarios like for GUI and animation. I’d generally stay away from thinking you can build the bulk of your game in BP. Do most of the logic in C++ and use BP to tweak variables and references and such as I described.

so basically it’s doing almost everything in C++ and then setting some parameters with BP?

It’s really a matter of preference. C++ is faster, and it’s also easier to merge in changes. Blueprints is easier to work with in many ways though. I’ve been using C++ for 25 years but the convenience of blueprints finds me writing a lot of code in blueprints these days.

I tend to do like TacoShank noted, build a core in C++ as you can easily access those variables or components from blueprints, but the same does not work in reverse. I then use blueprints for most of the basic logic, and C++ for the more intense operations. It is also possible though to create a game entirely in blueprints though.

To quote the amazing Allar

How much BP vs C++ is used in your project is really subjective. It depends on one’s mastery with C++ (Unreal C++ really). The guidelines such as base class in C++ remains as general guideline, but the more important thing is to start get your hands dirty now with Blueprint first, and over the time you will slowly know how much C++ is needed.

Here’s a simple effect practical example:

That’s how I do it (with some BP scripting where it makes sense) but I also come from a pretty strong programming background. As J.C. Smith, Luos, and Syed pointed out it really does come down to personally preference in the end, at least at the solo hobbyist/indie level. I certainly spent my time learning UE4 with BP only but shifted to C++ over time. For me non-trivial code is much easier to write and read in a text format.

There are some major advantages to text:

  • For example, you can comment and un-comment a piece of code very quickly. The equivalent in BP sees you detaching nodes but often times you can’t have multiple of certain node types. So then you need to delete parts to get your BP to compile and there’s no quick visual separation like in text. It quickly becomes a mess if you are trying to test two different algorithms and you forget to reattach your code the right way or add back in what you needed to take out to get it to compile.
  • Then there’s the fact that if you want your BP to look nice and not be literal spaghetti code you need to put a significant amount of time into moving things around visually and rerouting connections. I often felt like I spent too large of a percentage of my time changing the aesthetic of my BP instead of actually getting work done. Then when you need to add something to your nicely formatted code you worked on cleaning up for a couple minutes you will need to add some large chunk to the middle of it and do all that work over again. It gets old fast. With text Visual Studio automatically formats your C++ to look nice. With text you hit enter and start typing a new line to add a large check of code to the middle. You spend your time solving the problem. Sometimes I have lost my train of though and forgot how I was going to solve a problem because cleaning up BP takes so much fiddling.
  • Obviously version control (which everyone should use) is made a lot easier with C++. Because BP’s are treated as binary files if you ever have multiple people coding on your project you will be limited to one person “checking out” and working on a BP at a time. This is a major problem for collaboration. Text-based languages are a god-send here.
  • Although UE4 is open-source, let’s be honest, most are not going to spend the time to understand how BP is compiled. I’ve had several times where my BP decides to break for no particular reason. I’ve had to do weird things like rename BP variables to get them to work again. When my C++ doesn’t work it’s because it’s my fault not because of bugs in the language.
  • Your text-based code won’t randomly change on you, where as BP’s will decide to break links and do other things without telling you. This is fairly frustrating when it happens.
  • You can copy and paste C++ easily from and to the internet. If you look around you’ll see people posting screenshots to share their BP. They vary in resolution and readability. This to me is a major downside. Of course there are a couple resources to copy paste BP to the web but they don’t seem to be used often.
  • Maybe this is a personal issue but my pointer finger gets murdered from clicking so much when I work exclusively in BP for too long. With text all or most of my fingers are engaged so there is less strain on just one of them.
  • You can open Visual Studio without opening the UE4 editor. This is useful because if you crash your game and the editor crashes when you reopen it you can debug the problem. With pure BP your only real option (if you don’t know C++) is reverting to an old version with version control and possibly losing work.
  • If you are familiar with other text-based programming languages they will help you understand C++ and vice versa. BP is actually quite a different programming experience from traditional languages. I do enjoy it, but transferring logic from BP to text-based languages can be really tough. It’s hard to explain exactly why unless you have a lot of experience working in BP. If you try both BP and another language like C# or C++ out you will see what I mean. You simply think differently in a visual programming language.
  • There are also the famed performance benefits to C++, but really you can nativize BP now so this is mostly a moot point for all but the most computationally expensive code. This is the argument for C++ I find the least compelling.
  • Edit: How could I forget? With BP you need to zoom in and out of your code to be able to read it. The zoom level you need to be at to comfortably read BP’s is high enough that it’s hard to fit much logic on screen. This leads to a lot of panning back and forth to understand what the code is doing. With C++ I can usually fit the entirety of the chunk of code I’m working with (e.g. a function) on screen and read it easily.

For me performance is absolutely not the reason why I prefer to work in C++. You really shouldn’t be worried about performance as a one man hobbyist/indie anyway. I would not use that as the reason why you chose BP over C++. I choose C++ because for me it’s a lot easier to work with and text-based programming works better with my brain. Try out both and see what works better for your brain. However, I do think there are objectively some major advantages for text-based programming as I mentioned above.

Fortnite is making a fortune selling skins and battle passes… I wouldn’t hold my breath waiting for them to shelve it like they did to Paragon lol
Fortnite has potential of generating over a $billion in revenue. Tencent and Disney must be proud.

Thank you for all the awesome answers guys, now I got it a bit clearer ^^