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 spawn in a Blueprint class made in the editor using c++?

I am trying to spawn in blueprint class (a model imported from outside the unreal engine) in c++. This model is stored as a blueprint class which i can drop into the world inside the editor. It might just be a simple/stupid question, but since it was made inside the editor, i don't know how i would use this inside the c++ class i which i want to spawn the models from.

However, i now need to spawn X amount of them in a somewhat random location which just seems easiest by using a c++ class, but if it is easier doing this using a blueprint, I'm open for suggestions.

So my question is, what is the best way going about spawning my model blueprint class, or how do i get hold of this blueprint class in my c++ class?

Product Version: UE 4.15
Tags:
more ▼

asked Mar 03 '17 at 02:57 PM in C++ Programming

avatar image

BlueGenocide
3 1 3

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

2 answers: sort voted first

Here is a way that lets you set the class in editor with nice filters, and prevents any paths from beeing involved in C++ (which is always a bit dirty):

Derive the Blueprint-Class that you want to spawn on a c++ class (might just be empty, doesn't matter).

Add this to the class that spawns the objects:

 UPROPERTY(EditAnywhere)
 TSubClassOf<YourCppBaseClass> ClassToSpawn;

Since it is UPROPERTY(EditAnywhere), you can now find an instance of the object, that will spawn your class and edit the "ClassToSpawn" Property. There will be a drop-down-menu, where you can select the class that you want to spawn. Only Classes (Blueprint and C++) that derive from "YourCppBaseClass" will be shown.

In Code, you can then just spawn stuff like so:

 YourCppBaseClass* instance = NewObject<YourCppBaseClass>(this, ClassToSpawn);

Or, if your class is an actor, you would of course use "SpawnActor"

more ▼

answered Mar 03 '17 at 06:27 PM

avatar image

pulp_user
1.3k 46 29 59

avatar image BlueGenocide Mar 05 '17 at 01:29 PM

Sorry for the late reply, but how would i derive the class to C++ file? would that just be making an empty c++ file and then linking it too this blueprint class?

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

Hi,

 static ConstructorHelpers::FObjectFinder<YourObjectType> YourVaraibleName(TEXT("PathToObject"));
 YourObjectType* Var = YourVaraibleName.Object;

You can get the path by clicking on yourn Blueprint Class and select "Copy Reference"

You will have to modify some " ' " to get it working and remove the "Blueprint"!

ex:

 ConstructorHelpers::FObjectFinder<USoundCue> CueTarget(TEXT("SoundCue'/Game/Audio/ExplosionOnShip/explosions_onship_Cue.explosions_onship_Cue'"));


Edit: My code works in the constructor. I don't know if you can use it in any function.

Edit2:

I think you are searching something like this

 UClass* var = StaticLoadClass(YourClassType::StaticClass(), nullptr, TEXT("Path"));


more ▼

answered Mar 03 '17 at 03:46 PM

avatar image

42EspoiR
293 11 8 20

avatar image pulp_user Mar 03 '17 at 06:28 PM

I would not recommend this, since having direct paths in cpp is always a bit dirty. Also you would have to recompile every time you change the class. I added an answer, that is cleaner and easier to use.

(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