How to bind UObject to WebBrowser?

I am trying to bind an UObject to an SWebBrowser with SWebBrowser::BindUObject().

First I noticed that the documentation is not up-to-date, the UE object on the javascript side is window.ue and not window.ue4. I tried to create a pull-request to fix it, but got a 405 Not Allowederror.

I managed to call c++ functions from javascript with my bound UObject, however, I can’t access any of its properties (by reading the C++ code, I think it is maybe normal) and more important, the function parameters that I send from the javascript side do not arrive in the C++ side, and I can’t get any result back.

I know bound functions return a javascript promise, but I can’t read the returned value with them.

For example, in javascript:

window.ue.MyUObject.FunctionA(123).then( function(TheReturnedValue) { console.log(TheReturnedValue); } ).catch( function(error){ console.log(error); } )

TheReturnedValue is always null.

in C++

UCLASS(Blueprintable, BlueprintType)
class UJSLink : public UObject
{
	GENERATED_UCLASS_BODY()

public:

	UPROPERTY()
	FString InaccessibleUProperty;

	UFUNCTION(BlueprintCallable)
	float FunctionA(float bInvisibleParameter);
};

 // .cpp side:
 float UJSLink::FunctionA(float bInvisibleParameter) {
     return bInvisibleParameter; // it could be return 456; it would not change anything.
 }
1 Like

I am also study this ,try to find how to call UE method in javascript side.

1 Like

hi Arthur Masson.
I got the right response from ue4

window.ue.MyObject.FunctionA(123).then( function(TheReturnedValue) { console.log(TheReturnedValue); alert(TheReturnedValue)} ).catch( function(error){ console.log(error);alert(error) } )

I use alert to display message,and I got the 123 .

I don’t know why you are not success.

here is my MyObject source code

MyObject.h

#pragma once

#include "MyObject.generated.h"



UCLASS(Blueprintable, BlueprintType)
class UMyObject : public UObject
{
    GENERATED_UCLASS_BODY()

public:
    UPROPERTY()
    FString InaccessibleUProperty;

	UFUNCTION(BlueprintCallable, Category = "Web Browser")
    float FunctionA(float bInvisibleParameter);
private:



};

MyObject.cpp

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.

#include "MarsUI2PrivatePCH.h"
#include "MyObject.h"


UMyObject::UMyObject( const FObjectInitializer& ObjectInitializer )
    : Super( ObjectInitializer )
{
}

float UMyObject::FunctionA(float bInvisibleParameter) {
	int a = 1;
	float ret = bInvisibleParameter * a;

    return ret;
}

add this is bind code

		MarsUI2 = SNew(SWebBrowser)
			.InitialURL(PrefixProcess(InitialURL))
			.ShowControls(false)
			.SupportsTransparency(bSupportsTransparency)
			.OnUrlChanged(BIND_UOBJECT_DELEGATE(FOnTextChanged, HandleOnUrlChanged));

		UMyObject* MyObject = NewObject<UMyObject>(UMyObject::StaticClass());
		if (MyObject != NULL)
		{
			MarsUI2->BindUObject("MyObject", MyObject);
		}
1 Like

What is the correct way of calling this code:

window.ue.MyObject.FunctionA(123).then( function(TheReturnedValue) { console.log(TheReturnedValue); alert(TheReturnedValue)} ).catch( function(error){ console.log(error);alert(error) } )

?

For anyone who might come searching for a solution, here are the details of my solution.

Apparently binding a UObject to an SWebBrowser causes both the name and functions to become lowercase.

I found this using:

console.log(Object.keys(window.ue));

So, the same example code needs to be changed as follows:

window.ue.myobject.functiona(123).then( function(TheReturnedValue) { console.log(TheReturnedValue); alert(TheReturnedValue)} ).catch( function(error){ console.log(error);alert(error) } )
1 Like