Unreal.js icon indicating copy to clipboard operation
Unreal.js copied to clipboard

How to bind UMG Widget to JS?

Open Yimi81 opened this issue 1 year ago • 2 comments

class MyTestWidget extends WidgetBlueprint.Load('/Game/Test/MyWidget').GeneratedClass{

    // Override an event which was declared in Blueprint
    Test() {
        console.log("Press Button From Javascript")
    }
}

Like this https://github.com/ncsoft/Unreal.js/wiki/Override-Blueprint-Function, I want js inherits the widgets created in the blueprint and can then rewrite the methods inside, but I am unable to establish a connection between the two. The above method seems to be incorrect

Yimi81 avatar Mar 07 '24 08:03 Yimi81

More Detail : https://github.com/ncsoft/Unreal.js/issues/340#issuecomment-1983008707

Yimi81 avatar Mar 07 '24 08:03 Yimi81

The correct code, SendButton is the corresponding button name in UMG

/// <reference path="typings/ue.d.ts">/>

function GetPC() {
    return PlayerController.C(GWorld.GetAllActorsOfClass(PlayerController).OutActors[0])
}

function Test() {
    console.log("Press Button From Javascript")
}

function main()
{
    let PC = GetPC()

    let TestWidget = WidgetBlueprint.Load('/Game/Test/WBP_Test').GeneratedClass
    let widget = GWorld.CreateWidget(TestWidget, PC)
    widget.AddToViewport()
    
    widget.SendButton.OnClicked.Add(Test)
}

try
{
    module.exports = () =>
    {
        let cleanup = null;
        
        process.nextTick(() => cleanup = main());

        return () => cleanup();
    }
}catch(e)
{
    require('bootstrap')('test')
}

Yimi81 avatar Mar 08 '24 05:03 Yimi81