When working in the editor, we now automatically reload images and Tiled maps when they change on disk. This means that you can edit image e.g. in GIMP, save it, and just Alt + Tab back to the editor to see the new image displayed as part of UI or in the viewport. Similarly, you can edit and save the map in Tiled and just switch back to the editor to see the new map.
This is in addition to our earlier feature of auto-reloading the scenes when the change, which allows to e.g. edit in Blender, export to glTF and then immediately see the update in CGE editor.
To be precise, components that now support automatic reloading are:
- Images in
TCastleImageControl
(see using images) - Images in
TCastleImageTransform
(see using images) - Tiled maps in
TCastleTiledMap
(see Tiled maps) - Scenes
TCastleScene
(see viewport and scenes)
To take it a step further, you can enable this automatic activation also at run-time (when the game actually runs)! This allows to develop and test your game “live”, right as it runs. E.g. tweak a scene with 3D enemy, right when you actually see the given scene in the game. Or tweak an image right when you actually see it appear in the UI.
To enable this, enter the inspector (press F8 on desktop, by default) and select the checkbox “Monitor and Auto-Reload Data”. If you don’t see this checkbox, make sure you have regenerated your project files using the latest engine version.
Warning: Reloading the content at run-time cannot be a 100% safe operation in all the cases. In general, your project code may make assumptions that are true in “normal” project usage, but will be broken by reloading the image or scene. For example:
- Reloading image components means that image size may change in the middle of work. If you have been using the image size in some calculations, that calculation has to be redone now.
-
Reloading
TCastleScene
means that all X3D nodes are freed, and then loaded back from file. If you have done some post-processing of a loaded scene, this will be lost. If you have saved some references to nodes (TX3DNode
instances inMyScene.RootNode
), they will be invalid after reloading.You could make these scenarios work, e.g. observe for node release using notification mechanism like
TX3DNode.AddDestructionNotification
orAnyNodeDestructionNotifications
to set freed references tonil
. Then reinitialize them on-demand. But it is completely understandable that you may also just ignore this issue — auto-reloading should not happen when regular users play a release version of your project. And the extra code to account for hot-reload could be an additional complication. It is your decision whether/when it is worth it. -
For the above reasons, we have also disabled for now “auto reload” for reusable designs (in
TCastleDesign
andTCastleTransformDesign
, see reusable designs). Auto-reloading them could cause too many problems, since in most cases you keep references to some components inside loaded designs in your code — these references would become invalid.Although it is almost implemented.. but commented out. If you want to experiment, go ahead and test uncommenting it in castletransform_design.inc (for TCastleTransformDesign) and/or castlecontrols_design.inc (for TCastleDesign). I welcome feedback — if you feel that this feature is more useful than it is dangerous, we can make it active. Or introduce a 2nd checkbox like “Monitor and Auto-Reload ALL Data (dangerous!)”
This feature was inspired by Tomorrow Corporation Tech Demo. It’s quite amazing demo cranking such “hot reload” features “up to eleven” π Very advised to watch and be inspired!
Note: There are some known missing pieces related to reloading. Nothing is ever perfect π Comments and encouragements to extend this are welcome as usual. And this feels like a good place to remind that we cherish your support on Patreon – please support us if you can. Thank you!