Widget Casting issue object inheritance.
So I made a scroll box widget, that widget has a local variable of text. On "Event Construct" a for each loop runs through an array of the local text variable. Then a second widget is created (this widget is a button with text on) the text variable is set (to the array Item) and a child is added to the scroll box object. (This saves me adding and naming the buttons manually and allows me to increase the number of buttons much faster in the future)
This all works fine and displays as it is supposed to, the list box works, the buttons are clickable and they have the correct text on them determined by the items in the array.
This issue I have is I would like each button to do something different when it is pressed, so I can't make one on clicked event otherwise all the buttons would do the same thing. (as each child is made from the same button) So I am trying a solution where by when the button is pressed it casts to the scroll box (in order to access the local variable array), then as a loop goes through the array I can use the index number and a branch system to determine what should happen from that index number. ( If index 0 add health, if index 1 add mana, ETC)
The issue I have is that when I cast to the scroll box it has no object attached and no object I attach to it allows it to cast, I am told either that it doesn't inherit from this object and it is rejected or warned that my cast would always fail. I have looked at similar questions on here and tried things such as "get user widget object" "Get all pawns of class" and so on. None of the solutions on here work for my predicament.
So how do I cast to a blueprint widget, when inside another blue print widget? Or how can I set up each button in a list box to do something different.
asked Sep 26 '18 at 04:13 PM in Blueprint Scripting
I have now solved this issue in a different way. My solution was to create a variable within the Player Controller and then set that variable to the widget I was trying to cast to, I could then access that reference through the player controller and then access the variables within the widget as required.
Follow this question
Once you sign in you will be able to subscribe for any updates here