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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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?

Product Version: Not Selected
Tags:
more ▼

asked Mar 04 '15 at 12:37 PM in Blueprint Scripting

avatar image

CactusFantastico
80 10 21 25

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

1 answer: sort voted first

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 ;)

Cheers

more ▼

answered Mar 04 '15 at 12:45 PM

avatar image

Erasio
5.9k 291 86 293

avatar image CactusFantastico Mar 04 '15 at 12:56 PM

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: http://i.imgur.com/SsDKgb4.png

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

avatar image Erasio Mar 04 '15 at 01:00 PM

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.

avatar image CactusFantastico Mar 04 '15 at 01:04 PM

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.

avatar image Erasio Mar 04 '15 at 02:05 PM

Yea that'll do :)

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 ;)

avatar image CactusFantastico Mar 04 '15 at 02:17 PM

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

avatar image Erasio Mar 04 '15 at 02:27 PM

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). ;)

avatar image CactusFantastico Mar 04 '15 at 03:00 PM

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"?

avatar image Erasio Mar 04 '15 at 03:16 PM

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:

alt text

setstaticmesh.png (68.8 kB)
avatar image CactusFantastico Mar 04 '15 at 04:38 PM

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: alt text 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

avatar image Erasio Mar 04 '15 at 04:44 PM

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.

avatar image CactusFantastico Mar 04 '15 at 04:47 PM

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

avatar image Erasio Mar 04 '15 at 04:49 PM

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.

avatar image CactusFantastico Mar 04 '15 at 04:57 PM

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: alt text

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

avatar image Erasio Mar 04 '15 at 05:08 PM

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.

avatar image CactusFantastico Mar 05 '15 at 09:13 AM

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

(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