FyroxEngine / Fyrox

3D and 2D game engine written in Rust
https://fyrox.rs
MIT License
7.65k stars 345 forks source link

Unresolved scripting issues #327

Closed mrDIMAS closed 2 years ago

mrDIMAS commented 2 years ago

There are number of unresolved issues with scripting system:

Script manually assigned to a node will be not initialized

When you doing some_node.script = Some(Box::new(YourScript::new())) the engine will not call on_init of the script. This is not a problem, until you use prefabs with scripts assigned in the editor, but could be a huge problem if you want to create objects procedurally.

Potential solution: Send a message from the scene node to the parent graph and process these messages in main loop and call on_init correctly.

No on_destroy method in ScriptTrait

Fixed in: https://github.com/FyroxEngine/Fyrox/commit/389a564c41caccc5bf05658e1d90439355de02a6

This prevents performing some clean up before script is destroyed. Some scripts may create scene entities that must be deleted when the script is about to be destroyed.

Potential solution: Send script instances to the parent graph and destroy them one-by-one in the main loop. When the scene is destroyed, send all non-destroyed (pending) scripts to the engine and destroy them one-by-one in the main loop, this will allow to do a clean up in the parent plugin.

Other

There could be some other issues that will be discovered later.

mrDIMAS commented 2 years ago

Fixed in 0.27+.