How do you make a Actor Class list for weapons...For a RTS UE4 4.26

Ok I have been trying to figure this out for two months and have not been able to fully figure out how to approach it for I am still new in Blueprint Coding (in fact coding period) and not sure how to go about this. From what I understand I would have to make the weapon actor, then (This is where I get suck) In the Base Unit BP I am not sure if I need to make the weapon a Child Actor, or if I just make a reference to it in a Function which calls upon the Weapon Actor Class to be able to make the Weapon accessible and if possible be able to choose the weapon for the Child Units based off the Main Unit BP. My question is how do I make if be able to be selected from adown down list, which will spawn the weapon I have chosen to the unit Socket, so when it comes to the Customize I plan to make A player can choose what weapon his unit can care. I hope I was clear in explaining this. Thank you for Reading.

If I understood correctly, you could do the following:

Let’s say you have a widget where the player can choose a weapon for his unit. You could either use a map (not recommended if game scales up) or use a simple data table with the structure “Display Name of the Weapon; Corresponding BP Class of the Weapon”. Use the DT in the widget and if the player makes a selection, you look up the corresponding BP Class and spawn it in the world (at location 0-0-0) while setting its owner to the player.
This will trigger event “Begin Play” in the Weapon Base, here you can cast/interface to the player (as it is the owner) and there you can run “Attach Actor to Component”.

I hope this is answering your question :slight_smile:

Thank you for this this has solved a bit of my problem. Now just trying to get my Variants to be visible.

1 Like

Ok Made Data Tables for this but, There only appear as Drop Down Menus in the Blueprint Coding

but Don’t appear in the Class Defaults. IS there a Way to Make the Items in the Data Table appear as a drop down menu in Class Defaults?

Solved my own question! Turns out all you have to do is what is in the picture! God Bless you and Good Luck on your game projects everyone! BTW here is the post where I learned it, it is the very last post!:

I am glad you’ve found out how it actually works now, good luck to you as well!

Just a short optional side-note: Depending on how big your Data Table gets, it might cause a slight lag to search through the entire data table every time you need to get access to the struct. I don’t know how you have obtained the value for “UnitMeleeWea”, but you might want to consider doing the following:

  • On Begin Play, use the node “Data Table get Row Names”, then use a “For Each” Node out of the names and create an array of structs based on the data table.
  • When selecting the weapon in the widget, link it directly to the entire struct and then you can save this struct (this data table row) as a separate variable and do stuff with it.

=> Yes, it requires you to deal with the entire struct every time compared to a struct with only two entries. So if your data table has few rows, but many columns, this approach might not be better.

I just wanted to give you some extra information because tiny things like these tend to upscale pretty heavily and ruin the game in the long-run.

1 Like