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"

Can I Spawn a BP from CPP?

Hi! So I've been trying to spawn in another CPP actor using my CPP actor manager. It works perfectly but the thing is that I do not specify many aspects of the actor at runtime in the CPP because I like to configure the settings in blueprint before using it. I would like to spawn in the blueprint instance of this actor.

How would I do that in CPP? Thanks a ton.

Product Version: UE 4.19
more ▼

asked Apr 07 '18 at 04:43 AM in C++ Programming

avatar image

2 1 3 5

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

1 answer: sort voted first

Ofcorse, first you need to realize that blueprint is a class same as C++ class.... so yes that means every blueprint as any other class has it's own UClass which you can do SpawnActor, it's also importent to understand that same as you extend class C++, blueprint also extends class including C++ once. Go see "Class Viewer" in Windows->Devlopment Tools->Class Viewer and search your blueprint there and you will be able to see class relation tree of your blueprint, it should open your eyes. Only limitation is you can't use blueprint-made object directly as type in C++, as compiler don't know how to interact with virtual classes and objects like blueprints. you need to use most common C++ class related to blueprint insted.

There 2 ways to get UClass of blueprint:

  1. Most easiest one is getting UClass by setting it in property in property editor, like blueprints defaults for example. So depending on your designm in C++ make UPROPERTY(EditAnywhere) of type UClass* or TSubclassOf<ASomeClass> somewhere that code that gonna spawn can access, like your AGameMode for example and then make a blueprint and set property you made, now call SpawnActor using that property as class input. You can extend AWorldSettings to add property ot World Settings of a level, you can then get WorldSettings variables like a described here: https://answers.unrealengine.com/questions/280382/how-do-you-access-world-settings-variables-in-blue.html

  2. 2nd option is to FClassFinder which you can see example of use here: https://answers.unrealengine.com/questions/546442/c-reference-to-widget-component-without-editor.html Limitation here is that you can do that only in class constructor

1 option is most safest since referencing assets direly in C++ may cause error in packaging, aspecially if C++ code is only thing referencing to asset, then it is not packaged and cause error in packaged game.

more ▼

answered Apr 08 '18 at 08:44 AM

avatar image

37.3k 936 172 1116

(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