Understanding C++ scripting in Unreal
Before getting started, we need to answer some questions that people usually ask about C++ scripting. This will help to clarify the pros and cons of using C++, the reasons to use C++, and the difference between UE C++ scripting and C++ programming.
What is the difference between C++ and Blueprint?
Both C++ and Blueprint are scripting languages that can accomplish the same tasks, but one might be better suited than the other under certain circumstances. The main difference between them is that C++ is a programming language that allows you to write general-purpose, text-based code, whereas Blueprint is a visual scripting system for UE.
For UE projects, game studios usually use both C++ and Blueprint to develop commercial-level games. C++ is usually used for advanced techniques, complex algorithms, and big-scale logic code. If you can script with C++, you will have more chances to work on a professional team.
One of the most important advantages of using C++ is performance. C++ allows you to write low-level operational code. It also provides control over the core system that is not accessible to Blueprint. In addition, the final C++ code will eventually be optimized and compiled to be machine-friendly binary native code. On the other hand, Blueprint scripts are interpreted and executed by a middle layer, which means more execution time.
C++ code and files can be well-organized based on an entire project’s mechanics. It is easy to globally search, locate, and access code blocks to edit, maintain, and troubleshoot. In the meantime, it is also easier to read and understand a big chunk of code that implements complex algorithms and logic. Blueprint, on the other hand, is a context-sensitive scripting environment. Blueprint graphs are relatively independent. When a graph needs to solve complex logic, the nodes and the connection lines create messy spaghetti that can hardly be understood and maintained.
C++ also has some shortcomings. One example is that it may cause critical errors that may crash an entire system. That is usually caused by the developer’s mistakes. Since Blueprint is a protected layer, it is safer, and hence, the chances of the system crashing are fewer.
In conclusion, the choice between C++ and Blueprint should be made based on specific development requirements and conditions, considering the pros and cons of each approach.
When do you use C++?
Both C++ and Blueprint can handle game development processes without a problem. There is no exact rule that regulates when to use C++ or Blueprint. It mainly depends on your experience and the actual needs of different games. You make your own decision based on how much you know about the two scripting systems.
Before you start working on something, you can ask yourself this question: “Where does it make sense to use C++, and where does it make sense to use Blueprints?” We recommend basing your answer on the following aspects and trade-offs:
- Performance
- Logic and algorithm complexity
- Accessibility to a system’s core functions
- The developer’s experience
If you want higher performance and deal with advanced game logic and system processes, and you are capable of coding and solving complex problems, you should go for C++.
What is the difference between C++ programming and C++ scripting?
You may be confused about the difference between C++ programming and C++ scripting. We want to clarify the meanings of these two terms.
C++ programming means using the C++ programming language to write code for any purpose; it doesn’t have to be just for UE projects. C++ scripting, in this book, is a specific dialect of the C++ programming language supported by the UE. It takes advantage of the power of C++ syntax and also works with UE’s Application Programming Interfaces (APIs), which allow developers to create and extend the engine’s functionalities for their games and the development environment’s context, such as objects, graphics, audio, and network communication.
Now that we have a basic overview of C++ and have learned why and when to use C++ for Unreal game developments, let’s dive deeper into C++ scripting by creating a sample project.