Hello. I started to learn UE programming and have some fundamental questions. Here is my situation:
I am C++ programmer, so I use C++ classes to implement object’s logic. But for me it is too hard to create components tree from C++ (like meshes or Niagara systems) and align it, so I inherit blueprints from C++ classes and describes graphical part here.
For example, I created my own Pawn, described all movement and other logic in C++, but in blueprint I aligned Camera and Capsule, added skeletal and static meshes and initialized C++ references to use these objects in C++ functions.
The first question - is it a good idea to split object into C++/BP parts?
The second question - I have a problem. I created some blueprint with projectile (C+±based blueprint) and now I am trying to spawn projectiles from Pawn’s C++ code. To get UClass I use StaticLoadObject function (as described in many examples). It works in Editor, but doesn’t work in Packet version. As I understand, release version doesn’t include blueprints.
I read many topics with this problem, tried suggested solutions, but they didn’t help. So, probably I shouldn’t spawn blueprints from C++? What is right way to organize blueprints and classes?
Ok, I read other themes and articles, checked Lyra example and Shooter tutorial (3 - Implementing Projectiles | Unreal Engine 4.27 Documentation).
- As I can see, it is OK to split implementation to C++ and Blueprints.
- I hope I correctly understand their relations - C++ shouldn’t directly use Blueprints (red line on image):
Instead of this C++ class holds TSubclassOf member which is set in it’s blueprint. - I have already seen this solution in other forum themes, but in my project I got error when I tried to run packaged game: “Bad export index …”. After some time I solved this issue by deleting VS project folders, regenerating them, restart and rebuild UE project. Now it works fine - I can play packaged version
It’s definitely possible for C++ to use BPs. A BP is essentially a class derived from the native C++. It’s uncommon, but possible.
The C++ could define a BP function like BP_GetFoo
which returns an AActor*
. It could then call it and do stuff with the Actor pointer. Then in BP you could implement that function however you want to return any actor you want.
Generally I think you don’t want to do it this way, but in some cases it’s definitely useful.
Most of the time I think the C++ should be doing the heavy lifting logic and then just calling the BP when it needs something pretty to happen.
I’m confused about the lines you drew. It looks like your inheritance goes Class2->BP_Class2->BP_Class1. But then you have a black line drawn from BP_Class1->Class1 which doesn’t make any sense.
A BP is going to either inherit from a C++ native class or from another BP that inherits from a native C++ class. BPs don’t (I believe) support multiple inheritance which is what you seem to be showing on the diagram.
I mean, BP_Class1 inherits Class1 and BP_Class2 inherits Class2. Horizontal line means that BP_Class1 saves BP_Class2 into property. This property is used by Class1 to spawn BP_Class2 objects.