Spawn an Actor from a TArray of TsubClassOfs
I have a TMap of some integer keys and then a TSubclassOf. The TMap will be randomly populated with about 6 subclasses of 'TaskBase' meaning they all are different classes with the same parent. After being populated, they will then be selected in random order and then their individual functions will need to be accessed.
In order to do so, I must be able to spawn an instance of the TSubclassOf. How do I get the type of the specific TSubclassOf and how do I utilize it in the basic GetWorld()->SpawnActor(...) function?
asked May 18 '19 at 03:38 AM in C++ Programming
I wrote the following code to automatically spawn appropriately high climbable/ vaultable walls and lights from a JSON file.
You should have similar implementation for a TMap. SoftClassPtr and SubClassOf are similar.
Here is the implementation. Do read the notes.
Hope this helps.
Edit 1: I should add just in case,
If you want even more control, instead of mentioning class in template, you can just get class with one line of code. But it might be a bad idea because if that class is not included in your calling class, you will have a hard time catching the errors.
Hope this helps moar.
Follow this question
Once you sign in you will be able to subscribe for any updates here