x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Thanks again.

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 doingalt text

Product Version: UE 4.21
Tags:
screenshot-51.png (977.9 kB)
more ▼

asked Dec 08 '18 at 04:13 PM in Blueprint Scripting

avatar image

PerCat
39 1 3 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

alt text

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.

alt text

Then, just call these events on the appropriate Input Action.

alt text

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.

alt text

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.

alt text

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.

image0.png (40.1 kB)
image3.png (4.6 kB)
image4.png (58.8 kB)
image5.png (295.8 kB)
image6.png (25.9 kB)
more ▼

answered Dec 09 '18 at 02:27 AM

avatar image

GhostofCookie
6 1 2

avatar image PerCat Dec 09 '18 at 07:58 AM

Wow! Thanks! This one actually worked without spitting an error. I am having a couple problems with it though. It's only incrementing or decrimenting once, it's only changing after the building is already placed and I can flip flop through the first one and the default while it is placed.

Thanks for your help thus far and here's how I have it all set up. If it's any help I have a ghost mesh for buildings before they get placed and a way for everything to follow the cursor and spawn.

alt textalt text

avatar image GhostofCookie Dec 09 '18 at 08:49 AM

Could be any number of things, but let's see if were can narrow it down.

Firstly, is your MaxIndex set to the number of child house classes (I.e.the length of the house array (which might actually be better to use come to think of it))? Secondly, is Forest Wood House BP the parent blueprint of the houses you want to cycle through? If it isn't, then any house toy spawn that isn't a child blueprint won't have this logic, and therefore won't cycle.

Thirdly, is it the house actor that follows your cursor, or is it just some mesh that is a placeholder for where the house actor will spawn? If it's the former, and the current mesh of the actor is set to be the ghost mesh, then it shoukd theoretically be cycling before placement (assuming this is what you want to do). If however it is the latter, then it gets a bit tricker, as the ghost mesh would have no relation to the house blueprint, and would therefore not cycle itself to match the next or previous house.

These are the only causes I can think of with the information provided. Hopefully one these points is what's causing the problem? If not, would you be willing to show a bit more code so that I can help you resolve this?

avatar image PerCat Dec 09 '18 at 08:14 PM

Max Index is set correct, is an array with 3 elements and is a parent. Placeholder mesh (transparent ghost mesh is what cycles I can manually set the display mesh for it in each bp. And sure!

alt textalt text

avatar image GhostofCookie Dec 09 '18 at 09:51 PM

Okay, so the reason your building is cycling through only after placement is that that is the nature of the blueprint. In your Building_Ghost you create a house actor and then destroy it, so the logic is essentially unreachable because the house has been destroyed.

Re-reading your initial question, I find that I'm still unclear as to whether or not you want the buildings to cycle while they are in "ghost" mode, or if you do want them to cycle only after they are placed.

If you're wanting the ghost mesh to cycle as well, then you may have to do one of 2 things:

  • Send the Create Building (Message) every time you cycle the variants, or

  • Instead of destroying the house actor that is spawned in Building_Ghost, simply hide the actor mesh, and add some logic somewhere in the ghost to refresh the mesh of the ghost if the spawned actor reference changes.

If you're not wanting the mesh to cycle after it is placed, then you'd simply need to move the variant logic from the house Blueprint to the ghost blueprint.

You mentioned that you were only flip-flopping between the default and first array element houses? The reason for this could be that your default house blueprint has a CurrentIndex of 0, and so does the first house actor in the array, so my suggestion would be to perhaps increase the CurrentIndex of each house in the array to avoid any of them having the same CurrentIndex value.

avatar image PerCat Dec 09 '18 at 10:38 PM

Sorry I'd like them to only cycle in ghost mode. No I couldn't put the code into the ghostbp cause I need to change the variants for each separate building.

I tried create building with the ghost bp as the reference to no luck.

Accessed none error when it tries to destroy actor so the create building node just spawns a new building every time i hit the key to cycle through.

avatar image GhostofCookie Dec 09 '18 at 11:31 PM

Ah, I see. The same logic should still be applicable to the ghost, you just need to pass the values for current index and Houses to the ghost so that it can cycle through them:

alt text

answer2.png (209.9 kB)
avatar image PerCat Dec 10 '18 at 01:02 AM

What is the "house mesh" and the "ghost mesh" you are using for this cause no matter what I can't seem to get the spawn actor to link up with the set static mesh.

alt textalt text

avatar image GhostofCookie Dec 10 '18 at 01:49 AM

Oh sorry! I forgot to use your same custom event and names. House mesh is equivalent to your Display Mesh from the spawned actor (forgot to name it the same as yours), the ghost mesh was just a placeholder for testing if the static meshes do change on the ghost blueprint. Essentially, for the Create Building event, nothing really changes for what you already have, all you need to add is the CurrentIndex and HousesArray variables so that you can use them for the NextHouse and PrevHouse events.

Also, this was for your ghost blueprint. The variant swapping logic should be transferred from the House to the ghost, and the house simply passes the index and array information to the ghost. link text

avatar image PerCat Dec 10 '18 at 02:40 AM

Well here's how both my ghost and my forestwoodhousebp parent look.

alt textalt text My only real issue with this setup is I was trying to avoid using the ghost bp for this code cause wouldn't I have to add something like this for every parent array for every building? Like stores, farms, mines etc..?

Thanks so far, been tremendous.

avatar image GhostofCookie Dec 10 '18 at 03:22 AM

Okay, so your house blueprint no longer needs the variant logic, since you don't want it to cycle through houses once it is placed.

So instead, in the house blueprint, all we have are the variables CurrentIndex and Houses (as well as whatever you had prior to this answer). This is where you set the values for those variables.

In the Building_Ghost is where the variant logic will all go (this includes binding the events). Instead of replacing everything you already had, this is simply added on top of what you already have in the Ghost blueprint.

alt text

The above "Create Building" event is the interface event you had previously implemented. There's simply some added logic on top of this. So now we can get the CurrentIndex and Houses variables from the spawned house.

What the NextHouse and PrevHouse events do is almost exactly the same as what they did earlier, except this time they run an 'Interface Call' (not a message, though that would technically still work) to Create Building, which will again create the next or previous house variant, set the appropriate variables as you had done before, and destroy the actor again.

Your 'On Spawn' function would just need a simple addition of the variables to be set (except the array, which cannot be passed by reference through the custom node for some reason).

alt text

*This image is missing a few of the boolean variables you had set in your previous image. I will stress that you should keep the work you've already done, and add the appropriate nodes on top of the work you've already done.

capture.png (188.5 kB)
capture1.png (87.1 kB)
avatar image GhostofCookie Dec 10 '18 at 03:30 AM

In answer to your last issue, you can theoretically use this logic for any building type. I've used the name "House" since that was the original query. This could be renamed to 'Buildings' to be more generic. By putting this in the ghost, you remove the need to copy-paste the variant swapping into every different building parent blueprint. All you would need in the building parent is the variables (and I'm assuming you have a master building type which is generic, so you'd would theoretically only have to add these variables to the master building blueprint, and then simply set the variables correctly in each blueprint).

Another way you could handle the various buildings, although this would require another question thread, could be through using data tables with rows that contain the array of meshes you wish to use per building type (the rows would be named after whatever building you are constructing). So instead of creating 50 blueprints, you could have a generic blueprint that handles the logic for constructing the buildings in stages, and simply get values from a data table.

avatar image PerCat Dec 10 '18 at 02:50 PM

Hmm. I'm super new and didn't even know that was a thing def have to look into it.

But on the ghost mesh if I add the set current index it doesn't allow me to scroll through +- 1 Is would you happen to know how to fix this?

Also is there a way I could just make an actor array and an index in the building master then reference those in the ghost bps code so I could then change the array's actors and index independent of the ghost bp, but for like every mesh. I was fucking with it for a bit but my Ihud stops me from spawning anything when I add another input for "BP_Display_Mesh_Arrays" and hook it all up.

avatar image PerCat Dec 11 '18 at 06:58 AM

I tried to hook I up like you said but now none of the variant switching will work and all my destroy actor nodes have an accessed none error.

alt textalt textalt textalt text

avatar image GhostofCookie Dec 11 '18 at 07:24 PM

The reason your variant switching isn't working currently is that you have to events that spawn the houses: One is called CreateBuilding (which is an interface event), and the other is a custom event that you've named 'CustomEvent'. Now, from these pictures, you don't seem to ever call CustomEvent, which is where you set your building array and current index. I'm not quite sure why you have these two events, as they are mostly the exact same. But, if you want the variant switching to work again, then on the 'Variant_Next_Event' and 'Variant_Pevious_Event', at the end of these, instead of sending a message to 'Create Building', you can call 'CustomEvent'.

The reason the variant switching doesn't appear to be working is that when you call the variant next or previous events, they send a message to the CreateBuilding event, which spawns a house with a CurrentIndex of 0, and then sets the CurrentIndex to 0 again.

avatar image PerCat Dec 12 '18 at 05:46 AM

Okay, so I set it up to call to custom event and the variant switch isn't working still. I'm not really sure what you mean when you say it sets the index back to 0, cause the setters on the switch events are before it spawns it and then for the other one even if I remove it, it doesn't work.

But even then the "0" element on the variant array has meshes bound to it on the button I use to initially spawn my house and so if it gets set to 0 I should see the mesh still which isn't appearing. Maybe if there's some weird interaction between the parent mesh and the children it's referencing for some reason?

Cause the building_actor_variants variable is an array of "building_master" so then I add the actors into it per bp's parent house/store etc. Maybe I also set that up incorrectly?

Thanks for your help thus far been great

alt textalt textalt text

screenshot-65.png (94.9 kB)
screenshot-66.png (89.4 kB)
screenshot-67.png (93.3 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question