I’m so confused about how to spawn blueprint from C++. I researched it but I couldn’t. I want to make select weapon system. Player will be able to select desired weapon and will play the game. How can I make this? Btw, is Child Actor Component for this problem?
The question doesn’t make much sense as C++ and blueprints are a way of specifying functionality.
What you are asking is how to spawn an actor and it doesn’t matter to the spawner if the spawned actor is implemented in C++, blueprint or a mix of the two.
You probably want to look at Actor Component which is a method of attaching one actor (weapon) to another (the player).
NOTE: You must have a base class from C++ that your blueprint children are based on for this feature.
.h File
.cpp File
For a detailed breakdown:
The UPROPERTY meta tags will expose the drop-down menu and accessibility from the Blueprint and will constrain valid classes to only those that derive from YourBaseClassFromC++.
TSubclassOf<> is the special data type that gets class values.
GetWorld()->SpawnActor() is the function usually used for spawning any actor.
The key part: SpawnableClass->GetAuthoritativeClass() will attempt to get the most-derived valid class of the SpawnableClass value passed in (i.e., will reference a Blueprint class if it was used as the value).
I worked fine for me, but i still have a problem: my spawning actor has a variable who is exposed to the spawner, but i don’t know how define it, can you help?
Something like this.