When an object is set as a global object, it does not appear in already open scenes until those scenes are either closed and reopened, or some kind of search happens in the object list.
Steps to reproduce the behavior:
Yes, more generally the UI is not properly refreshing when global objects are changed (added, removed or edited). Would need some clever solution to trigger a refresh of the object lists - maybe just refresh the object lists when a tab is activated?
The object list should listen for some custom event emitted by the "Set as Global Object" action and refresh itself ...
I would like to work on this!
Please go ahead :) Though this might need some careful thinking. We traditionally don't use JavaScript "events" in GDevelop codebase, but we pass information through React props/callbacks. You might want to specify multiple props in components to say "global objects were updated"...
OR maybe better and cleaner, just force a refresh of the objects list when a tab is activated :) Again needs some experiment to find the best solution :)
@4ian, refreshing the objectList on the change of tab does seem a better approach. Did some digging and found that the tabs are changed by changeCurrentTab() in EditorTabsHandler.js , which is being called in index.js (Mainframe folder) inside _onChangeEditorTab().
So, can we just refresh/re-render the objectList when the above method is called?
Sure, seems to make sense. You still need to identify a way to say to the underlying tab editor that it was just set active and so should refresh itself (and then the editor should propagate this to the objects list).
@4ian, I did mange to solve the issue.
What I did was add a boolean state "tabChanged" to index.js (Mainframe), which is set to true once the changeCurrentTab() is called, which is then propagated to the sceneEditor, where it is checked whether this prop is true and if it is true, I just call forceUpdateObjectList(). However, this method is called inside of the render() of SceneEditor, which shoots a warning: "Cannot update during an existing state transition (such as within render). Render methods should be a pure function of props and state." Any tips as in what should be done.
Using this approach does solve the issue though! :)
Unfortunately I'm 99% sure that the solution is not by adding a boolean state tabChanged. Sure it will be set to true, but then if I add another object, what it will be... ? :)
It's an anti pattern generally to "add stuff in state" to get things to work.
React is trying to warn you that you also called a function at a wrong place. Try again but learn about React "refs" and see if you can do something else.
Thanks for investigating so far :)
Yeah, I might be wrong here, tabChanged once set true, it is always true. What I tried to do was update the object list (due to which global object shows up) on every tab change by passing a boolean. Adding a another Object will not affect the state, changing the tab will (that too only once, it is set true!) This refreshes the object list on each render of SceneEditor!
Sure, I'll do some digging and come up with a better solution! :)
React state is good at describing an application in a "declarative" way. Here you want to force something to happen that can not be captured in a state (or you would need to put the boolean back to false) - so you want something that is more "imperative". :)
This refreshes the object list on each render of SceneEditor
If this is not needed, we probably want to avoid this as it slightly hurts performance/battery drain.
@4ian Sorry for taking a lot of time, but had my college midsems and a hackathon, so if took some time. I have a solution ready (using refs :)) and will send a PR in some time!