How can I make Actor appear and disappear using a UMG button

I’ve tried to set it up so that when you press a UMG button on screen, an actor will appear or disappear. I got the button appearing but i realized you can’t reference an actor unless it’s in the world blueprints. How would I make it so I can reference an actor in the button’s blueprint?

The issue is not how to reference one but rather how to get the correct actor and this really depends on your use case.

Do you just have one type of actor of which all should disappear when clicking this button? Or just in a radius around your character? Well in this case you can do a “Get All Actors from Class” which will present you an array. For the distance check well just do a for each loop and check the distance between your character and the actor location and look if it’s within the range and if so hide / remove it.

Should only one specific actor disappear? Well you can just create a variable in your character which you access from UMG. If it’s valid you enable the button and if not (so there’s nothing to point to) it’s being disabled. When you click it you hide it. Like that you can reference the actor once your character overlaps with some trigger volume which also allows you to reference different actors once you are at different positions without any additional work.

If you have a different usecase or need a bit more explanation on how to set this up just comment with your exact usecase or issue :wink:

Cheers

well as a base example, i want it so when you press the cone button, the cone mesh appears and hides the sofa mesh: http://i.imgur.com/ZyCJU0Z.png

when you press the sofa button, it hides the cone and shows the sofa mesh:

This is my first venture into blueprints or any kind of scripting so i’m easily confused by some of the terms haha

So basically not even hiding but changing a mesh? Because that would work exactly like you describe.

What’s the final result you strafe for? Place a mesh at a specific place clicking a room together or something like that? Because there are still 3-5 ways to legitimately do this and the best one really depends on what you want to achieve in the end.

Sorry haha ill try to clarify more, this is to be a product selector essentially, using HTML5 so you can rotate around a range of objects and have a good look at them. There is no movement apart from the camera orbiting the center and all the objects appear and disappear in the center where the camera is orbiting. if just changing the mesh will work for that then that’s all good haha there will only ever be one object in the middle of the screen at one time. Hopefully that explains a bit better haha thanks for the replys.

Yea that’ll do :slight_smile:

So yea I would suggest just having one actor in your scene and only changing the mesh. That’s fairly straight forward via “Set Mesh” once you got the actor and then the mesh component.

Since it’s supposed to only ever be one single object why not just make this a pawn which won’t move and set it as player character? That way you can add a camera to it on a spring arm, just modify that one fairly easily and you have easy access to it from your player controller and because of that from your UI as well with a fairly minimalistic setup :wink:

alright sweet, yeah it sounds like making it a player character attached to the character blueprint and changing the mesh there will be the best option haha is there any chance you could show me how i would go about changing the mesh? as i said, I am pretty new at this and I am not sure how i would do that haha thanks

Oh no you misunderstood me. Just create a new BP based off a pawn instead of character. Character comes with a whole lot of functions and presets you don’t really want while a pawn is just a posessable thing without a lot too it.

In there you can just add a mesh component as root, a spring arm and a camera linked to that springarm. The springarm basically keeps the camera in the same distance to the object (which you can obviously modify) which results in a nice round movement around your mesh.

And a pawn can be a player character inside of your gamemode (which determines which classes are used when entering a level). :wink:

Hmm well i tried making a new pawn like you said but now it has caused more problems then having my modified 3rd person camera controller that i was using haha now it starts at the wrong angle and spawns in two sofa’s. can i just use the controller i had set up before?

Also with swapping the mesh out, i’m still unclear as to how i would reference the mesh change with “set static mesh”?

Good point. Totally forgot that. I usually use a pawn for stuff like this because I code the camera myself most of the time as this default one doesn’t suit my needs. Yea in that case a character might be better after all… at least for now.

As for setting a static mesh. You need to add a static mesh component in the components tab in the top left corner. Then you can just get that one as variable and call “Set Static Mesh” from it via the context menu like this:

I’m pretty sure im still doing this wrong. where do i add the static mesh component to? tried doing it like this and it didnt seem to work:

http://i.imgur.com/yYitEPr.png

http://i.imgur.com/yYitEPr.png

i made a component in the UMG widget named the same as the one in the character blueprint and tried to reference it but it wont connect up and i don’t think im doing it right at all haha

So how do i make it so it swaps the model when the button is clicked then? sorry i keep getting confused haha

Why is the target a widget?

You just have to pull out a wire from your static mesh component and search for “Set Static Mesh”.

EDIT: Ah. I just answered before your edit^^

You should just create a function in your character BP which is called something like “Set mesh”. In there you just have one input a “static mesh” and set the mesh to that one.

In your UMG you simply call that function and select the mesh you want.

You simply provide the mesh you want to the function to set the mesh to something different. You call that function from inside of your UMG and boom. New mesh.

i think i almost have it now, i made two functions with contained blueprints to change the mesh into either of the two and then dragged them into the Widget blueprint and connected them to the button clicks. Now it also asks for a Target so im not sure what to plug into that slot:

http://i.imgur.com/z1zHC5n.png

http://i.imgur.com/z1zHC5n.png

Just create one function which takes one additional input: The mesh itself. Like that you only have to create one function ever and every new mesh you include in your project can just get it’s own button, you select it in your UMG graph and you’re done.

And the target is obviously your character. When you create the widget you need to pass on a reference to it of your character. You can easily do that by creating a new variable with the type of your character, make it editable and select the “Expose on spawn” checkbox. When you spawn it a new pin will appear taking your character as input.

Hmm but im still unsure what to put in the function area. I know it’s a bit much to ask, but would you mind taking a screen shot of what the function area and the widget part should look like? if you did i would be eternally grateful and can stop bothering you with walking me through these baby steps haha