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"

How do I create a reference to a Widget within another widget blueprint?

Hello! First of all: I have recently gotten into blueprint scripting which means I am not very experienced, so please have that in mind =) I will try to make my self as clear as possible!

Okey, here is the deal

A while ago, I started creating a sort of cookie-clicker clone on Scratch.mit.edu as a way of learning to script, but I abandoned it because the quality was too bad. However, I decided that I wanted to try and create it using blueprints in Unreal 4. I started using widgets as it makes it easy to create a setup of buttons and images which is just what I need for the project.

Here is the two widgets I have made:

alt text ↑↑↑↑↑↑↑↑↑↑↑↑

The one above is my main widget! Whenever i click the earth, a variable within the "Main Widget blueprint" adds "1" to itself, and the number is displayed under the earth (as you see)

When clicking the "Shop" button down in the left corner, another widget appears:

alt text ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

This is the shop widget! When I click one of the two items in the middle, it adds to floats within the "Shop Widget Blueprint"

However: I have problems with reopening the Shop after closing it!

The first thing I tried to do, was for it to remove the widget itself from the game, but that lead to the Float-values being erased, which I really didn't want, so I made it so that when I clicked "Exit Shop", the widget just moves out of view! ... but then it is seamlessly impossible to get the "Shop" button in the "Main widget" to make the shop appear again without having to completely recreate the widget!

Why?...

...because I cant create a reference to the "Shop widget" in the "Main widget Blueprint"

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ alt text

Here is also a picture of how I spawn the widgets when the game start! I choose this setup because my float-values kept getting deleted when simply "re-creating" widgets

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ alt text

I have tried many different methods of making this system work, but I always run into the Float values being reset, or being unable to creating a reference to the widgets...

What am I doing wrong? Is there a much simpler way to do this? ...And should I really use widgets do do this?... I don't know! (Don't be afraid of making me feel like an idiot, that is probably what I need right now) ;) ;)

Product Version: UE 4.9
Tags:
mainwidget.png (93.7 kB)
shop widget.png (196.0 kB)
howdoi.png (78.2 kB)
levelblueprint.png (263.8 kB)
more ▼

asked May 20 '16 at 11:06 PM in Blueprint Scripting

avatar image

Doktor Plekter
1 1 1 1

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

1 answer: sort voted first

You not aware that you making reference, what do you think outputs from "Create Widget" that blue pin? Refrence of just created widget, set it varable before adding to viewport and reuse as much as you want. On creation use "IsValid" on that that varable to see if widget been already created if not, create, if yes dont create and just use what is in varable. Same goes with actors, Spawn Actor outputs actor reference so you can control it, keep it in varable insted of using heavy "Get All Actors of Class" all the time

more ▼

answered May 21 '16 at 02:19 AM

avatar image

Shadowriver
37.1k 935 172 1116

(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