Blueprint - adding component by class while runtime

is there any way to add custom actor component to blueprint by class? Blueprint allows me only nodes with predefined class. I would need it for my weapon modular system(not visual), but It seems I have to make too many blueprints or God blueprint.

Example: A lot of guns - one gun BP and datatable with all information(visuals, classes of actor components, …) .

Five and more guns with same BP, but with different firing system(semi, auto, laser type, charge, …).

Thank you for every answer.

This was asked in the forums a couple of days ago:

I doubt it’s possible in BPs currently (perhaps someone can prove me wrong, though!). I believe your best bet would be to create a God BP (as you called it) and have it create components on the fly via a giant switch of sorts.

I also looked as soft class / object references but nothing comes to mind :expressionless:

I also considered toying with the idea of creating a BP Component Dispenser for this very purpose - one that has all the components pre-added and places them in a Name | Component map at Begin Play.

You can then fetch one just by name + modify its default struct. As soon as the component is re-parented from the Dispenser to the target actor, the Dispenser replaces it internally so the map is always ready and orderly.

This should minimise the spaghetti code to bare minimum and finding the desired elements in a map is super efficient.

Maybe this might help

1 Like

‘Add Component by Class’

1 Like