but I am afraid that this are two different problems I have and since I really want to come forward with my project and can’t figure out how to solve my rerender problem, I’d like to state the issue here again.
As requested I opened a git repo:
In README.md I describe the issue as problem 2.
Basically it is that my Rectangle is just appearing on a rerender/resize of the browser and I can’t figure out why.
I want that the rectangle appears after first render.
and here is a sandbox of the code:
I hope anyone can help me to figure out what I do wrong.
I think it’s because you create your scene with 0,0 dimensions, so at start the GUI texture is 0/0. Only after a refresh does the texture is recreated with the right dimensions.
Thank you a thousand times for taking time on this @Evgeni_Popov !!!
I still don’t understand a 100% how the process works, because I assumed that the texture size is taken from canvas. (This way I wonder how to explicitly tell the dimension for the GUI texture?)
I guess my lack is more about reacts lifecycle management.
If you put some console.log, you will see that onSceneMount is called before componentDidMount and when onSceneMount is called, width=height=1.
After that, when updateDimensions is called, the engine.getRenderWidth / engine.getRenderHeight methods still return 1/1, meaning the underlying canvas has not been updated.
I don’t know how the react component works, but it seems it does not update the engine width/height canvas sizes. So you should do it yourself, by adding this in updateDimensions:
I found also some requests in other articles that people like to have the same code as functional integration, which is not covered by the tutorial. I just found this code which looks good to me: babylonjs-react - CodeSandbox
Hey @fneitzel definitely let me know what you’d like to update in the docs.
The How to use Babylon.js with ReactJS - Babylon.js Documentation page sounds like the right place to update based on this thread, so you can either run your ideas by us here, OR you can make the changes and submit the PR for review. Totally your call. Let us know how we can help!