How can I access child widgets in the C++ parent of this Widget Blueprint - unreal-engine4

Here is a screenshot of the Blueprint editor for my CharacterSelectMenuWidget blueprint. This Blueprint's parent is a C++ class that extends a UUSerWidget.
Blueprint Editor Screenshot
The TeamSelectorWidget and RoleSelectorWidget are both Blueprints of type BinaryOptionSelectorWidget. That Blueprint's parent is a C++ class called UBinaryOptionSelectorWidget. I want to grab a reference to the TeamSelectorWidget and the RoleSelectorWidget that are children widgets of this blueprint's canvas inside the C++ class. I've tried the following, but this does not work
UBinaryOptionSelectorWidget TeamSelectWidget = Cast<UBinaryOptionSelectorWidget>(GetWidgetFromName(FName("TeamSelectorWidget")));
I may have the class casting wrong, though I'd expect to see some sort of error message if that were true. I can't use the Visual Studio debugger to evaluate the expression and debug that way, because it complains about the constructor for FName() (is that a known issue).
If anyone has an idea of how to access these variables, please let me know.

Related

UE4 UUserWidget is always changed after restarting UE4 or compile at blueprint editor

MyHUD.h
UCLASS()
class FPS_API AMyHUD : public AHUD
{
GENERATED_BODY()
UPROPERTY(EditDefaultsOnly, Category = Gameplay)
class UUserWidget* DefaultWidget;
...
}
I make Blueprint BP_MyHUD extends MyHUD and Widget Blueprint. The problem is, the DefaultWidget in BP_MyHUD is set None after i restart UE4 program or compile using button in toolbar at Blueprint editor. How can i fix the value of DefaultWidget in BP_MyHUD?
By default variables are set to "Private" and thus can't be modified in derived classes.
Try putting this UPROPERTY after you say public: (you could also use protected:)
UCLASS()
class FPS_API AMyHUD : public AHUD
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, Category = Gameplay)
class UUserWidget* DefaultWidget;
...
}
Also I am unsure of the EditDefaultsOnly specifier when it comes to blueprints. My understanding was without
BlueprintReadWrite
You could not edit the variables in blueprints. But if you've been using this with success with other variables it is likely not the problem.
A bit late to the party, but here's the answer:
It's not possible.
Non-BindWidget pointers with EditDefaultsOnly indeed generate a selector in the Details panel, but this selector is not meant to select a widget inside our component's archetype. It's meant to select a widget outside an instance of our component (it also need to be public and maybe a BlueprintReadWrite too). In this case, the value you put in the selector indeed stay across builds.
Sadly, this error-inducing selector appearing anyway means that two things aren't quite working properly around this behaviour :
At the moment UE clears the selector when you're building, it should really display a warning/error explaining why
You shouldn't really be able to put EditAnywhere/EditDefaultsOnly on a non-BindWidget property, only a EditInstanceOnly... yet there's no warning/error either =(
(credits to #Bohdon Sayre from BenUI's discord community for helping me on this one)

The argument type 'Context' can't be assigned to the parameter type 'BuildContext'. For Loop and Button

I am trying to create a button within a for loop as the loop is connected to the main dart. Everything else is running fine but then I try to put in the raisebutton I seem to get these errors depending on the dart package I am using stating:
package:path/path.dart Context context Type: Context
The system path context.
This differs from a context created with new Context in that its Context.current is always the current working directory, rather than being set once when the context is created.
or
dart:js JsObject get context
The JavaScript global object, usually window.
I don't know if what I am doing is right or not, please help.
Here is part of my main dart where the for loop is suppose to go inside as the for loop is within a different dart file
I'm not sure why you are instantiating MyMenu so often or why you are passing MyMenu instance variables into a MyMenu instance method. You may want to look at a better way to structure your code.
But to answer your question, you have no access to the current BuildContext within your MyMenu class. Quickest remedy: pass the BuildContext as a parameter to buildMenuItemsList.
buildMenuItemsList(Section section, BuildContext context) { ... }
MyMenu().buildMenuItemsList(MyMenu().getSections()[index], context),

Vala GTK3 find child by name

Using Vala 0.30, how do you find a GTK child widget by name?
The main code calls a function to set up the application layout:
text.application_layout ();
The function creates the window and layout boxes.
class Example : Gtk.Window
{
public void application_layout ()
I want unrelated code to place content in some of the boxes. In C + GTK I could define the window as a global variable and any code could find a child box then add content. I cannot find a working equivalent in Vala.
Jen suggested using Container.get_children(). I will experiment with that. In the previous C code, the get_children approach produced thousands of children when a grid was populated.
Some Web pages show Vala classes with public strings. Vala will not compile the examples of a class when the public variable is a GTK widget. I also tried a dozen variations that work in other languages and fail in Vala.
Finally I found a way to have a public GTK widget that can be found by other code. The following compiles. All the online examples are slightly different and fail to compile in the current Vala.
class Example : Gtk.Window
{
public Grid example_grid = new Grid ();
public void application_layout ()
If this is the only option, I will have to make many items public public.
I will still have the problem of finding the last child in a variable length set of children, something like the last label added to a box or the last row added to a grid. I would like to label items in a long list with a name like last then find it direct instead of reading through a thousand children every time.
Another update. The following grid definition works from within the class. It works from other methods of the class when called within the class.
class Example : Gtk.Window
{
public Grid example_grid;
this.directory_grid = new Grid ();
My main code has var example = new Example(); and passes the example object to other code that needs user interface elements. The other code can then access example.example_grid or a method that updates example.grid. This means changing the other code to accept the example object.
I found then lost a page showing how you can access the main window object without having the object passed to the function. If I can find that again, it would let me access example.example_grid without having to change the code to pass the example object. This is getting close to a solution.

GWT Deferred binding failed for custom class: No class matching "..." in urn:import:

I am developing a couple of custom widgets that I would like to be able to use with UiBinder. Unfortunately I keep wasting my life away with chasing down the following error:
No class matching "..." in urn:import:...
This seems to be the catch-all exception that is thrown any time there is any error in the class that prevents the GWT compiler from processing it. This includes anything in the class's entire dependency tree.
To save myself and anyone of you who is running into the same issue some time and pain, let's compile a list here of the most unexpected and hard to find causes for this. I'll start with my latest one, which has made me decide to post this here.
I was using a CellList thusly:
private static RelationshipViewerUiBinder uiBinder = GWT.create(RelationshipViewerUiBinder.class);
#UiField(provided=true)
CellList<String> prioritisedDisplay;
public RelationshipViewer() {
prioritisedDisplay = new CellList<>(new TextCell());
initWidget(uiBinder.createAndBindUi(this));
}
note the Java 7 style <> on the CellList. Despite my IDE's protestations to the contrary, it turns out you DO need to explicitly say CellList< String> in that new call, or it wont compile and all you get is the above mentioned error. Thanks by the way, the existance of this question prompted me to scrutinise my code and probably saved me a couple of hours! This fixed it:
private static RelationshipViewerUiBinder uiBinder = GWT.create(RelationshipViewerUiBinder.class);
#UiField(provided=true)
CellList<String> prioritisedDisplay;
public RelationshipViewer() {
prioritisedDisplay = new CellList<String>(new TextCell());
initWidget(uiBinder.createAndBindUi(this));
}
I had written a component that used the GWT JSON functionality, but hadn't imported com.google.gwt.json.JSON into the module.
Thanks to your message here, this was only 2 hours down the drain...
I wrote a helper-class that this widget uses somewhere deep inside its dependency tree.
For this helper-class, I told Eclipse to auto-generate the hashCode() and equals(...) functions. The class contained a field of type double, for which Eclipse generates code that uses Double.doubleToLongBits().
Turns out GWT does not implement this method on its version of Double. But of course, neither does Eclipse detect this as a possible compile-error, nor does it cause any issues in Dev Mode if I use the widget inside the GWT-App's Java code rather than inside UiBinder.
3 hours down the drain... Great... Yay for helpful error messages.
UPDATE:
As of GWT 2.5.0 (RC1) GWT now supports Double.doubleToLongBits() rendering this particular error obsolete, but the general error mechanism of a missing JRE emulation remains and will probably manifest itself in a similarly unhelpful way.
I was trying to use a GwtQuery DragAndDropCellTree in a UiBinder .ui.xml, which was impossible as DragAndDropCellTree has no zero-arg constructor.
See more details

Static methods & inheritance in Coffeescript

I've been reading up a bit about coffeescript's inheritance model and I have the feeling I'm on the fringes of an ideological debate which I really don't understand. So, I would be perfectly happy to find out that I'm just doing things in the wrong way.
Basically what I am doing is writing a set of widgets which, among other things, need to handle events on their DOM elements. I thought a good way to go about this would be to have a class method which would be called once, to delegate all the events which the widget might need. The base widget class might have some simple click handlers, while the subclass might add to that some mouseover handlers or extra click handlers.
However, it appears that I'm not supposed to try and do the equivalent of calling super() inside a static method. There is a workaround which exists, (this.__super__.constructor.METHODNAME() but I've seen a lot of suggestions that this isn't the best way to do what I'm trying to do. Has anyone got any insights on how I should structure this code? Keep using the workaround, or put all the delegation into a totally different place? I can't really just stick it in the prototype, since I won't necessarily have an instance to call the method on (or can I essentially still call a method on the prototype from a static context, like putting SwatchableWidget.prototype.delegateEvents() into an onload function or something?
Here's a bit of code to illustrate what I'm talking about:
class Widget
#testProp: "ThemeWidget"
#delegateEvents: ->
console.log "delegate some generic events"
class SwatchableWidget extends Widget
#testProp2 = "SwatchWidget"
#delegateEvents: ->
console.log "delegate some specific swatchable widget events"
this.__super__.constructor.delegateEvents()
Widget.delegateEvents()
SwatchableWidget.delegateEvents()
Thanks for any help.
I suggest replacing
this.__super__.constructor.delegateEvents()
with
Widget.delegateEvents()
trying to use super to call static methods is not required (and doesn't make much sense)
I don't understand why delegateEvents would be a class-level method, or why Widget.delegateEvents have to be called again from SwatchableWidget.delegateEvents. If it's just class initialization code, you should put it in the class body directly:
class Widget
console.log "delegate some generic events"
...
#testProp: "ThemeWidget"
class SwatchableWidget extends Widget
console.log "delegate some specific swatchable widget events"
...
#testProp2 = "SwatchWidget"
I take it you're waiting for a specific DOM state before running this initialization code? Maybe I could suggest another approach if you told me a little bit more about the preconditions for delegateEvents.
It sounds like you want a different type of inheritance model where each inherited function of a certain type ("parent calling") will walk the inheritance tree and call all its parents with the same name.
You could call any direct parent functions in each child manually as you've written. Then it will float up the inheritance chain anywhere you specify such a relationship.
I would bind the parents delegate call in the constructor to a current class function
delegateparents =>
#call any parent class methods