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"

Create c++ class for existing blueprint

Hello,

I have created a pure blueprint actor and added some logic in blueprint there. However now I realized that would be better of implementing this logic in c++. How can I create a c++ class for an existing blueprint? I tried to create the class as a new c++ actor with the same name, but it complains that the class with this name already exists.

Product Version: Not Selected
Tags:
more ▼

asked Apr 27 '15 at 05:07 PM in Blueprint Scripting

avatar image

Oleg Sinyavskiy
71 2 3 60

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

3 answers: sort voted first

Accidentally I found exactly what I wanted that works beautifully without any workarounds:

  • Create a C++ class you want to be a parent for the existing blueprint

  • Open a pure blueprint you have

  • Click File->Reparent Blueprint and choose the C++ class you created

more ▼

answered Apr 30 '15 at 11:13 PM

avatar image

Oleg Sinyavskiy
71 2 3 60

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

Hello, Oleg

Please note, that when a game is being developed in Unreal Engine 4, Blueprints are mostly used by designers. This means, that at the moment of Blueprint creation, necessary classes have already been developed by programmers. With this, both groups can effectively focus on their tasks.

Thus, the required functionality isn’t possible. Due to engine designers’ intent, you should actually do the opposite and create blueprint after implementing required functionality in C++ class, since it will be more productive.

Hope this helped!

more ▼

answered Apr 28 '15 at 11:20 AM

avatar image

Gleb.Bulgakov
1.8k 76 19 143

avatar image Oleg Sinyavskiy Apr 28 '15 at 04:34 PM

Thank you for your answer! I'm a novice and I somehow missed this advice in the documentation. At this point I don't want to loose created blueprint code and my level where I placed dozen of objects of this class. What is the best strategy to transfer what I have to a recommended C++ and Blueprint pair of classes? E.g. I can create different C++ class with attached blueprint, copypaste bluprint code to it. Can I mass-replace object of certain class to another class? Is this a recommended way to do it?

avatar image Oleg Sinyavskiy Apr 30 '15 at 11:15 PM

Hi Gleb, It appeared to be a way to do exactly what I wanted - see my answer with blueprint reparenting

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

After reading some docs I found a workaround. In my case I had a lot of boxes with Cube static mesh I placed in the level so I wanted to preserve their placement. Also I wanted to preserve the blueprint code I wrote. Lets say the name of the blueprint-only class is "BPOnly".

  • Create a new C++ actor and Blueprint for it (e.g. following this tutorial). In my case I create an actor and then added static mesh component "Cube" in the edit. Lets call this class "CPPAndBP".

  • Remove all event mocks in the new blueprint of "CPPAndBP" such as Begin play and tick

  • Copy-paste blueprint code from your old blueprint "BPOnly" to the new one "CPPAndBP" (select all with Ctrl+A, Ctrl+C then Ctrl+V)

  • If you have variables in the "BPOnly" blueprint, the new one wont compile. So you need to recreate variables in the "CPPAndBP" blueprint. I found the fastest is to select the pin with variable, drag it to empty place and then select "Promote to Variable"

  • Now go to your main level tab. Select the "CPPAndBP".

  • In the level editor select the instances of "BPOnly" that you want to replace. You can quickly select multiple objects in the World Outliner (e.g. select objects in the folder or via menu "Select"-> "Select All BPOnly")

  • Make sure that the new class "CPPAndBP" is still selected in the Content Browser. Right click on the particular instance of the old object in the Editor (not in the Outliner).

  • There should be a menu item Replace Selected Actors with "CPPAndBP". Click it, it should do the trick.

In my case I preserved all the positions and sizes of Cube static meshes through the process and associated Blueprint. But now I can augment instances with cpp logic!

In order to not get to this situation based on Gleb's answer I never create pure Blueprint classes anymore but always start with C++. So far I don't see a downside of this decision (except maybe longer compilation time).

more ▼

answered Apr 29 '15 at 09:37 PM

avatar image

Oleg Sinyavskiy
71 2 3 60

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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