I am trying to do something that should be extremely simple, but haven’t been able to figure out how to do it yet. There are lots of questions on this subject in here, but little to no clear answers.
I want to be able to assign a Blueprint in the Details panel of some c++ class I’ve created, and then spawn that blueprint in the code.
I already know how to spawn an Actor with its default parameters, but I don’t know how to spawn a blueprint.
For example, let’s say I’ve created a “Homing Missile” blueprint with its own set of visuals and components. I’d like to assign it as the “projectile” blueprint of a “Weapon” actor I’ve created. When the weapon fires, it would spawn whatever projectile I’ve assigned to it. (Just to be clear, I’m not looking for an explanation of how I could do this specific case. I just want to know how to spawn a Blueprint)
Blueprint is class and in UE4 reflection system it’s equile to C++ classes. All classes registered in reflection system has UClass object generated and from those object classes are identified in entire engine (including SpawnActor if you didnt notice yet ;]). So all you need to do is UClass* varable or
TSubclassOf<AClassNameHere>
it’s the same as UClass* (it converts via operator override) but in editor it will limit class selection to classes children of parent class that you input in template. This saves work from doing checking and casting.