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"

Widget appearing after the player interacts with an object

I'm trying to make a simple crafting system. Basically when you interact with an anvil a widget pops up. When you are done you click Cancel and the widget disappears.
How can I do this? I was thinking about adding the widget from the anvil's C++ class, but I don't know if it's even possible.

Note: I tried to create a main widget with the anvil widget as a component and setting the visibility of said widget component on tick event after checking a boolean variable from the player class, but it didn't work. I mead it did show up when the player interacted with an anvil and disappeared afterwards, but it was impossible to interact with it.

Product Version: UE 4.16
more ▼

asked Aug 09 '17 at 11:56 AM in C++ Programming

avatar image

94 21 24 28

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

1 answer: sort voted first

I guess it was impossible to interact with it because it was creating the widget every tick!
Where did you set up the interaction?
Here's how I'd do it, but keep in mind that I'm not too experienced and that this is mostly pseudocode:

  • Player tries to interact

  • GetPC()->GetHUD() and cast to your HUD->GetYourWidget() and YourWidget->SetVisibility(ESlateVisibility::Visible)

  • When he clicks "Cancel":


Note that you have to create your widget before you want to interact with it, what you can do is create the widget in your HUD/MainWidget on BeginPlay(), AddToViewport() and SetVisibility(ESlateVisibility::Hidden). Then save that widget in a reference variable because you need to access it through your PlayerController.

If you want to show some code or explain your code structure, I can give you more specific information!

more ▼

answered Aug 09 '17 at 07:20 PM

avatar image

176 12 19 191

avatar image J0K3R_12QQ Aug 09 '17 at 07:48 PM

Oh My GOD I'm a MORON! Ignore my question. The problem was, that I was adding the main widget to viewport on ReceiveDrawHUD. Now I do this on BeginPlay and everything works.

Thank you for your answer and sorry for taking your valuable time.

PS: Is changing the visibility on tick is a very bad thing?

avatar image blueshifted Aug 09 '17 at 08:26 PM

I guess it's not very efficient, but as I said, I'm not very experienced :)

(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