blackears / cyclopsLevelBuilder

A Godot plugin to let you block in levels inside the Godot editor.
MIT License
1.09k stars 44 forks source link

CyclopsConvexBlock can be manually created outside of a CyclopsBlocks parent, causing error spam #3

Closed Calinou closed 1 year ago

Calinou commented 1 year ago

In 4.1.dev d6dde819b, adding a CyclopsConvexBlock node spams errors if done outside of a CyclopsBlocks parent:

res://addons/cyclops_level_builder/tools/tool_block.gd:238 - Invalid get index 'global_transform' (on base: 'Nil').
res://addons/cyclops_level_builder/cyclops_global_scene.gd:238 - Cannot call method 'get_children' on a null value.
res://addons/cyclops_level_builder/tools/tool_block.gd:238 - Invalid get index 'global_transform' (on base: 'Nil').
res://addons/cyclops_level_builder/cyclops_global_scene.gd:238 - Cannot call method 'get_children' on a null value.
res://addons/cyclops_level_builder/cyclops_global_scene.gd:238 - Cannot call method 'get_children' on a null value.

When creating the node, I suggest checking whether its parent is a CyclopsBlocks. If not, print a human-readable error message using push_error() (to let the user know about invalid usage) then queue_free() the node.

The error message could be:

Cannot create a CyclopsConvexBlock node outside of a CyclopsBlock parent. Create a CyclopsBlock parent first, then use the buttons in the 3D editor toolbar after selecting the CyclopsBlock node to create new CyclopsConvexBlocks.

blackears commented 1 year ago

I've updated the code to do some type checking to avoid this spam. i;m hoping to replace the CyclopsBlocks node in the future so this is hopefully temporary.