decentraland / sdk

PM repository for SDK
Apache License 2.0
4 stars 4 forks source link

UiCanvasInformation not found #915

Closed DrasticLp closed 1 year ago

DrasticLp commented 1 year ago

Hi, I have some UIs that need to get the screen size in order to work but when I try to get it, it crashes... image

image

Any ideas ?

nearnshaw commented 1 year ago

At what point during the scene's lifecycle are you trying to fetch this data?

Are you doing it from inside the main() function, a function called indirectly by main(), a system or an async block of code? If from any of the above, then this should work, and if not there's surely a bug.

However, if you're not, then it's likely that the corresponding entities are simply not loaded yet. The reason why we have a main function is that it's executed only once the engine has confirmed that everything is already loaded.

DrasticLp commented 1 year ago

I execute it inside a ui image The ui is registered inside the main() function I also tried only calling it after 15 seconds to test it and it still crashed

DrasticLp commented 1 year ago

It started to happend when I updated from 7.3.0 to 7.3.7

nearnshaw commented 1 year ago

Another snippet where it's not working:

´´´ts export function Main() { try { canvas = UiCanvasInformation.getOrNull(engine.RootEntity) if(!canvas) { canvas = {'width': 1024, 'height': 768} }

    pxWidth = canvas.width
    pxHeight = canvas.height

    return (canvas)
} catch (e: any) {
    utils.timers.setTimeout(() => {
        Main()
    }, 100)
}

} ´´´ Decentraland Editor SDK7 v1.21.0 in ui.tsx

pravusjif commented 1 year ago

@DrasticLp can you confirm that with this build the problem is solved?

You can test it starting your local scene and adding &explorer-branch=fix/sdk7-scenes-addition-to-datastore to the URL

pravusjif commented 1 year ago

Tackled at https://github.com/decentraland/unity-renderer/pull/5626

The fix will reach production (probably SDK 7.3.11) after the explorer's next release.