Tips for Working with Unreal Engine 4, C++, Blueprint, and Virtual Reality 1


Unreal Engine 4 (UE4) is great for Virtual Reality (VR) development because it offers those that does know how to code an alternative with its Blueprint (BP) system. BP offers convenience by giving you nodes that you can call for common tasks. For the majority of people, this is enough to get by. However, there are times where you are doing something very specific and BP may not suit your needs.

In such a scenario, the benefit of C++ would become desirable. Not everything is accessible via BP, but you can access them in C++.

In this post, I want to share some tips about working with the C++ and the BP system and how to use them effectively to help with VR performance.


Blueprint or C++

If you are a software developer and have used UE4 before, you probably have pondered about when you should use BP, C++ or both. What are the pros and cons to each?

Blueprint

The Blueprint system is great for rapid prototyping. It is easy to use and has a ton of support in the UE4 community. There are plenty of documentations. There are many BP templates available for purchase from the marketplace. A good portion of the logic you need are probably available as a BP node.

The BP system is nice to work with, but it does have its disadvantages. When developing for VR, resources and performance are limited, and BP suffers in both areas compare to C++.  However, the consequence is not noticeable unless it involves plenty of computations. For heavy computations, it would save a lot of overhead time between the BP system and C++, if the computations were in C++.

C++

Using C++ can help you squeeze those last few frames from your VR project. By developing the backend of your VR project with C++, you will get a better performance than its blueprint counterpart will. The increase in development time might make it not worth it if your VR project does not have much computations happening. For example, if your VR project is centered around full body position tracking and physics simulations and predictions then C++ is definitely the choice for implementation.

TL;DR

Anything that happens often (every tick) or does computations should be C++. Anything else you can use BP and not see it impact performance by much.

Using Blueprint and C++

Using only BP or C++ for development is not ideal, so that means you should mix BP and C++ together. You can do this in several ways:

  • Write Blueprint callable functions in C++ and then call them in BP editor
    • Similar to C++ API, but for Blueprint and is tailored for the function you need
    • These type of functions are not bound to a specific class, all BP have access to them
    • E.g. calculations for tracking, simulations, etc.
  • Develop critical (expensive or time-consuming) sections of custom object in C++ and then create a BP child of that class
    • E.g. Write all the events that happen every tick in C++ and then in the BP child focus of animations and material designs
    • The Blueprint Callable C++ functions in this case is bound to the specific object
      • The functions is not available to all BP

Another reason to use BP and C++ is to gain access to lower level UE4 API that you cannot access with just BP.

Blueprint Callable Function Example

In this example, there are two identical actor objects. Both of them are of BP Actor class and have the same behavior. The only difference is that one does computation with all BP nodes and the other does computation all in C++.

Block Actor Using BP Computation

Block BP actor using BP computation

BP-based: Do computation 10M times and output the time duration

Manipulate vector function: Do 3M random additions to source vector and return result

BP-based: The time duration for 10M computation function to run

Block Actor Using C++ Computation

Block BP actor using C++ computation

C++ based: Does computation 10M times and output the time

C++ based: The time duration for 10M computation function to run

#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyBlueprintFunctionLibrary.generated.h"

UCLASS()
class VRDEMO_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
public:
	UFUNCTION(BlueprintCallable, Category = "My Math Library")
	static FVector manipulateVector(FVector vector);
};

#include "VRDemo.h"
#include "MyBlueprintFunctionLibrary.h"

FVector
UMyBlueprintFunctionLibrary::manipulateVector(FVector vector) {
        for (int i = 0; i < 1000000; i++) {
	        vector.X += FMath::RandRange(-100, 100);
	        vector.Y += FMath::RandRange(-100, 100);
	        vector.Z += FMath::RandRange(-100, 100);
        }

	return vector;
}

Impact on Virtual Reality

VR is still resource heavy and requires a power machine. There are strict requirements for VR such as 90 frames per seconds (FPS) or more. This is a requirement because it helps in preventing motion sickness. In terms of development, it means you must make efficiency a priority. You are not able to utilize fancy graphics without many clever tricks.

What this mean for you when developing your VR project is that performance is always something to keep in mind. In fact, you should make sure new additions to your project is not causing performance to suffer below the requirements for VR. By understanding how to balance between BP and C++, you can give yourself more room to develop fancier VR user experience (UX).


I hope you found this helpful. If so, share it with others so they can benefit as well.

Is there something else you believe would be a great addition? Are there other relevant topics, you believe I should address? If so, feel free to leave a comment, send me a tweet or send me an email at steven@brightdevelopers.com. I will be glad to hear from what you have to say.

To stay in touch, you can follow me on twitter.


About Steven To

Steven To is a software developer that specializes in mobile development with a background in computer engineering. Beyond his passion for software development, he also has an interest in Virtual Reality, Augmented Reality, Artificial Intelligence, Personal Development, and Personal Finance. If he is not writing software, then he is out learning something new.

One thought on “Tips for Working with Unreal Engine 4, C++, Blueprint, and Virtual Reality

Comments are closed.