How to create instance of Blueprint in C++

Apologies if this has been answered elsewhere or if I am misunderstanding something. I just started using UE4. I tried searching for many hours regarding this question, but I could not find an answer that made sense with my setup.

Ok, so I am playing around with trying to simulate robots with UE4. These robots have 3 DOF, and 4 rigid body components. I have Static Meshes for the 4 rigid bodies and have managed to create a Blueprint with the correct rigid bodies and joints. When I change the blueprint to put the robot at a certain configuration, it does so correctly.

So, it was easier to do the modeling in Blueprint scripting, but now I want to be able to spawn 2 robots in a level and have them each do different things. For instance, let’s say I want them to alternate between two configurations every 30 ticks, where each robot has a different gait table with different alternating joint configurations.

My question is this: How can I use the blueprint I have created in my C++ code? I want to work primarily in C++. I saw that there is a function to spawn an actor in the world. Is there such a function to spawn an instance of a blueprint, then be able to modify its properties/call functions in the C++ code? I tried creating the robot with C++ code, but was unable to replicate the blueprint version. Do I need to implement the functions I need in the blueprint and them call them from C++? Basically, if I could convert the Blueprint to C++ code, my problem would be solved. I was curious if there were any workarounds or if there is something I am misunderstanding.

Thank you in advance for any help.

I would recommend creating a new base AActor UClass in C++ for Blueprints to inherit from which defines (virtually, with BlueprintImplementableEvent) all of the functions that need to be called from C++, and then reparenting the Blueprint to the new UClass (you can do this from a menu in the Blueprint editor).

Calling purely Blueprint functions and modifying purely Blueprint properties is possible from C++, but cumbersome and error-prone.

Thanks for your quick reply! Ok, just want to make sure I am understanding you. Are you saying that I should create a new class in C++ that inherits from AActor, say MyRobotActor, and then change the parent class of the Blueprint to MyRobotActor)? Should I define all the UStaticMeshes and ConstraintComponents as UPROPERTY as well?

Yes, that’s what you should do. No, you don’t need to define the static mesh and constraint components in C++ unless you plan to access them in C++.