Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to bind UMG Widget to JS? #342

Open
Yimi81 opened this issue Mar 7, 2024 · 2 comments
Open

How to bind UMG Widget to JS? #342

Yimi81 opened this issue Mar 7, 2024 · 2 comments

Comments

@Yimi81
Copy link

Yimi81 commented Mar 7, 2024

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
Copy link
Author

Yimi81 commented Mar 7, 2024

More Detail : #340 (comment)

@Yimi81
Copy link
Author

Yimi81 commented Mar 8, 2024

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')
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant