Replacing a current Actor at runtime with another actor via HUD

Hey all,

I generally am pretty stubborn and work through the road blocks I hit, but this one has me a bit frazzled at the moment and I think I could really benefit from getting an outside perspective on this. I’ll admit, it’s a bit above my current skill level with blueprinting in some ways, but hey, you’ve got to be ambitious to get where you want to be! Any help/advice given is greatly appreciated!

So here is what I’m trying to accomplish in a nutshell;

I have an actor that I place manually in the level during level design to act as a placeholder for upgrading to another actor if conditions are met (the conditions part is easy enough). Example: TowerBase Actor Class.

Now what I would like to do, is be able to replace that actor at runtime using a HUD interface button with a different actor class (example: TowerUpgrade_1), and have it only effect the tower that had it’s Upgrade HUD button hit. I have the HUD class setup, it’s just currently not setup to replace the current actor with a new one (this is really my main issue) in a viable way for my purposes.

I assigned it an integer to act as its unique identifier, but am struggling to figure out how to access it on the HUD class properly in order for me to only upgrade the one tower & not all of them or a random one. I did this by making a struct with all the needed variables for my TowerBase class. In addition to this, I’m having a bit of trouble figuring out the placement mechanics for that. Specifically, I’m having trouble figuring out how to set the TowerClassToBeUpgraded to variable in my struct through the HUD class as well as the unique ID variable.

I know it’s ultimately due to lack of experience, but I’ve done a ton of searching on the forums to see if I could find any info on similar issues others may have had, but only found one semi relevant post, which did things on a grid based system, which I would like to avoid if possible, as I think it could be done in this method I’m trying to use, and it would be much simpler. But if it turns out that I’m actually over complicating things with this method, I’d gladly switch to the grid based system and give that a shot. Also do note, that I took the time to dissect the content example “Strategy Game” from Epic, but all the relevant mechanics for what I need are done in C++, which I would like to avoid if at all possible.

Again, any/all help on this matter is greatly appreciated! If you have any suggestions for simplifying this route I’m taking in approaching this, please feel free to share!

  • Sinari

To replace an actor with upgraded version you can simply use the ‘Spawn Actor from Class’ node, then hide/destroy the old actor.
If anything in game points to the removed actor, a reference, you’ll have to update all references after the old one is destroyed.

This was my original method of attempting this as it seemed like it would be the most efficient method, but the problem I faced with this method, was how do I grab which tower it’s supposed to replace & actually get it to place exactly where the old one was? Vector trace maybe? But that seems like it would be awful inefficient. Using the ID number variable, it still doesn’t grab the vector data for the current existing tower. Any suggestions on how to approach grabbing the current location of the tower that’s to be upgraded? I’m not sure. I think I scripted myself into a corner so to speak mentally with this at the moment haha.

Thanks for the speedy reply & suggestion!

The HUD should know who the target tower is (on click event the tower itself generates the widget and feeds its reference to HUD) then on press you know which tower is the one being upgraded by the HUD button, grabs its world position and spawn new guy over there.

Aha! You are awesome. I was wondering if it had that functionality built in, but wasn’t positive it did. Thank you thank you, this helps a massive amount! Knowing is half the battle they say :stuck_out_tongue:

I was using a custom HUD class not attached in this method, which was a mistake clearly. Time to rework things and get it working as intended. Cheers good sir!

Alright, so problem solved with 95% of it. Thanks once again. But now I’m having trouble with destroying the old actor through the HUD.

I’m not sure how to get the reference to the current existing Tower actor to destroy it when upgrading to a new one. I can’t directly get a reference to it from the world, nor does using a Casting node to the Tower actor seem to work (cast just fails due to me not being able to get that reference to the actor inside the HUD blueprint or being able to set it in the struct). As you probably can tell, I’m not very versed in HUD’s and their ways of referencing things in their scripting. I feel like a major noob at the moment, heh. I know there is a way to make this happen inside the HUD blueprint, just have run out of theories to try for the moment.

I’ve thought about trying to use a custom function for this on the Tower BP itself, but I’m pretty sure they don’t transfer over to Widget/HUD BP’s, and that might not even allow it to work as intended due to the placement mechanics being tied to the on button clicked event on the HUD itself.

Here’s how I have it setup currently

Edit: Figured it out…and I’m rolling on the floor practically at how stupid I feel. For anyone else out there who might struggle with this, just grab a reference to self in the BP for the actor, and feed it into the make for your specific struct. Herp derp. Easy enough. Then just grab the actor reference from the struct in the HUD BP and feed it into the cast node. Bam.

Yep since you already had the actor to get it’s information over to the HUD then you shouldn’t have any issues there.

For my tower defense toolkit that im working on I actually don’t destroy the parent actor itself I just modify it’s variables, 1 of which is the static mesh for it, but all of it’s details are set through a data table so I can have it have all it’s stats assigned through a single call.

I’m using a struct to do most of it (modifying the structs variables/tower’s variables therefore) to be honest, but there’s times when you don’t want to break and make a struct just to change 1 thing.

Quick question; I’ve yet to experiment with using data tables, but would you suggest this method over the way I’m approaching it? I’d imagine it might be less time consuming in the end possibly in terms of overall workflow in general.

Depends on what you are attempting to do really.

With my method I can add new towers and tower evolutions, tower types, attack types etc just by adding some new fields into my excel spreadsheet as opposed to creating parent and/or child actors for all the different towers. It makes the initial development a bit longer but in the long run makes things much easier to manage. EG.it took me several days of development to get 2 different towers into my game. It took me another 2 hours to get another 20 in there after that.

Also for balancing it makes things a hell of a lot easier when you just have everything in a spreadsheet and can easily tweak values and lets people that aren’t developing see and modify the values easily too without having to jump into different blueprints all the time.

For mine I use data tables for the towers, levels, enemies, upgrades etc. They are all in a single excel spreadsheet on different sheets with a macro in there to spit them out to the CSV files which are directly in the folder so update themselves as soon as a change is detected. It also lets me setup algorithms directly inside excel to fill in and update new fields whenever a field is changed so that you don’t necessarily have to change everything manually. Simplest 1 is the gold value of a killed enemy, I can get it to automatically fill in the field in excel based on the level, hp, enemy type etc and have that as a static value in the data table so that I don’t need to waste processing time to try and calculate it in blueprints, that’s a very simple example though so the code obviously wouldn’t be tough in blueprints but when you are spawning and killing hundreds of guys it all adds up.

Hmm, lots to think about. And thank you for breaking it down for me in that manner, it’s greatly appreciated. I might re-think my approach just for optimization purposes alone.

Cheers good sir! Very much appreciate the input :smiley:

Tomorrow is going to be a very fun day with studying and development I think!

A lot of ways to skin a cat!

There will be plenty of different ways you can achieve what you want but figuring out what works best for you is going to pretty much come down to personal opinion, that’s just the version that works best for my needs as I am essentially creating a tower defense engine and I want people to be able to create their own stuff and since I have a background with web and software then storing information in databases is the way I like to work. Let us know how you go with your methods.