I’ve spent the past couple of weeks diving into UE, wanting to explore and learn more about it.
As a learning challenge, I’ve taken one of my favorite games (RTS Warcraft 3) and I’m recreating from scratch different aspects of it.
I’ve been making great progress so far and I have encountered an interesting dilemma on how to best handle dynamically added ActorComponents to my units at run-time and wanting to change properties before I actually run the game.
e.g - I add a Movement component that allows the unit to move, but it has a property called Speed.
Note: Anyone familiar with RTS games will know of the CommandCard (The area that holds your buttons that you issue commands to units with. e.g - Move, Stop, Hold Position, Attack, Patrol, etc…) I will be focusing on this area.
Let me step back a bit and explain what I’ve done up to this point.
I have a parent class called BP_TestUnit that has an ActorComponent called CommandCard, that itself has an array property called CommandCardItems that can be filled with ActorComponents. (The array holds the components that will appear in your CommandCard. I will be focusing on a specific ActorComponent called Movement)
A child BP of BP_TestUnit called Worker will inherit the CommandCard actor component and fill its array with whatever it wants.
In the example of Worker, he will have a Movement component in this array.
When I run the game, I iterate through through the Array above and dynamically add (in this example for the Worker) the Movement component to it. (Note: The Worker unit only has the CommandCard actor component attached to it)
Question: My Movement actor component has properties (e.g - Speed) that I can’t edit in the editor because I dynamically add the Component in runtime. If I wanted to keep my system the way it is, is their a way to allow me to change the property on the Movement component if it isn’t on the Worker unit?
Note: I’m not blocked as their are multiple ways I can get around this. I see this side-project purely as a learning exercise and I’m exploring to what is in the realm of possible.
I will take a look at making the variables Instance Editable & Expose on Spawn and see if it works for me.
Question: What is that Add New Blueprint? I can’t seem to find it anywhere.
My second plan is nearly identical to yours, I would have a huge list of variables exposed to the User (Like the Warcraft3 object editor), call a function in the AC and pipe the data in.
Adding 5 would by fine in any way but adding 150 would be tiresome, so Add Component by Class would make more sense. But then you cannot expose since each class has different data pins. But then there is inheritance and we actually can:
I would have a huge list of variables exposed to the User (Like the Warcraft3 object editor), call a function in the AC and pipe the data in.
I would then look into how structs work if you haven’t done so already:
Essentially you pack a lot of data types into a wrapper, so all this:
Can become a single variable, which you can then have nested arrays of. So options for storing millions of variables open up.
a huge list of variables
Data Tables also work with structs; and a Data Table can pull data from a spreadsheet / json. It’s easier to operate on 1 million lines in Excel than it is in Unreal’s data table.
I see the Add Component by Class and if I plug in my Movement AC, I do see the exposed attributes!
I will have to look into how to create a new function that inherits from Add Component by Class, like you did with Add ARComponent.
I don’t believe I have tried that before.
I am aware of Structs and you are right, I should be using that instead of a massive list of variables!
It’s probably not the best system as I foresee some potential issues when this system scales up, but this is a great starting place and I’m very happy with it for now!!