Switch actors with keystroke
So I have an rts project I'm working on and I can click a gui button and spawn a static mesh that follows the mouse cursor where I then click to spawn it and it builds over time and I'm trying to figure out how to make it so I can hit a button on the keyboard and the static mesh will switch to a different one.
Like say I have house variant 1 selected and then I hit r and it switches to house variant 2 which will then play it's blueprint command to build when I place it. And then if desired hit r to cycle through or f to cycle previous.
Any help appreciated.
I'm pretty new. All my buildings have their own bps and special commands and such inside each building as well as their own static meshes and such. But they all have parent child relationships
house master>woodHouse>icewoodhouse>icewoodhousevariant1 or iwhv2 > iwhv3
and so if I'd like to have it eventually be one singular command that I put in the global buildings master is there a way to reference ALL buildings with a single code or will this be something I'd have to tweak later for each "category" Like say I click on the house category in the hud itd work for any "template" I select ice, grass, forest etc. and then from there I'd use the keystroke to switch between specific variants
So to reiterate; I already have a way to select buildings, have them follow mouse with a ghost mesh, spawn them and build them. I'm merely looking for a way to be able to switch from one actor to the other without having hundreds of gui buttons on screen.
I have reposted this a bunch now and haven't received any answers that actually work, so pls no salt or toxic in this thread. I'm not trying to spam unreal just need help and can't find a good tutorial anywhere so I'm using the answer hub for it's intended purpose.
If the toxic guy shows up just ignore him pls.
Here's what I have so far, doesn't work and I'm not really sure what I'm doing
I’m assuming that you want to cycle through the classes based on the current index. One problem is that you use that same index to select which array you want to get classes from.
Another problem is that the action events that you want to run will not run in this blueprint, since it has no relation to the player controller at all.
Won’t ever get called, which means that the nodes won’t be reached.
Instead, you could be running the InputAction events in either your player controller or your player character (if you don't want to create this logic in the player controller, then you could just enable input for this blueprint: (see here)). You can create two event dispatchers in the player controller which will handle the next and previous house swapping.
Then, just call these events on the appropriate Input Action.
In your master house blueprint, create two custom events for Next house and Previous house. These can then be bound to the player controller event dispatchers by getting a reference to the player controller.
Now, any child House blueprint you create from this will have this logic built into it, so you only need to write it once. Now, whenever you hit one of the input keys, it will swap between whichever house class is next in the array.
For each child blueprint, simply set the default value of CurrentIndex to the corresponding index it has in the master house’s array. For any new child blueprints you add, you'd have to go into the Master House blueprint and add them to the array.
Follow this question
Once you sign in you will be able to subscribe for any updates here