x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: Not Selected
Tags:
more ▼

asked Mar 11 '15 at 05:26 AM in C++ Programming

avatar image

tjcollins47
16 3 4 4

avatar image cancel Mar 11 '15 at 05:32 AM

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.

avatar image tjcollins47 Mar 11 '15 at 05:40 AM

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?

avatar image cancel Mar 11 '15 at 06:22 AM

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++.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question