You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Add null checks to AnimationTreeEditors and _clear_editors()
This commit is contained in:
@@ -46,6 +46,11 @@ StringName AnimationNodeBlendSpace1DEditor::get_blend_position_path() const {
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEvent> &p_event) {
|
||||
AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
|
||||
if (!tree) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<InputEventKey> k = p_event;
|
||||
|
||||
if (tool_select->is_pressed() && k.is_valid() && k->is_pressed() && k->get_keycode() == Key::KEY_DELETE && !k->is_echo()) {
|
||||
@@ -71,11 +76,8 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven
|
||||
|
||||
menu->add_submenu_item(TTR("Add Animation"), "animations");
|
||||
|
||||
AnimationTree *gp = AnimationTreeEditor::get_singleton()->get_animation_tree();
|
||||
ERR_FAIL_COND(!gp);
|
||||
|
||||
if (gp->has_node(gp->get_animation_player())) {
|
||||
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(gp->get_node(gp->get_animation_player()));
|
||||
if (tree->has_node(tree->get_animation_player())) {
|
||||
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(tree->get_node(tree->get_animation_player()));
|
||||
|
||||
if (ap) {
|
||||
List<StringName> names;
|
||||
@@ -180,7 +182,7 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven
|
||||
blend_pos *= blend_space->get_max_space() - blend_space->get_min_space();
|
||||
blend_pos += blend_space->get_min_space();
|
||||
|
||||
AnimationTreeEditor::get_singleton()->get_animation_tree()->set(get_blend_position_path(), blend_pos);
|
||||
tree->set(get_blend_position_path(), blend_pos);
|
||||
blend_space_draw->queue_redraw();
|
||||
}
|
||||
|
||||
@@ -203,13 +205,18 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven
|
||||
blend_pos *= blend_space->get_max_space() - blend_space->get_min_space();
|
||||
blend_pos += blend_space->get_min_space();
|
||||
|
||||
AnimationTreeEditor::get_singleton()->get_animation_tree()->set(get_blend_position_path(), blend_pos);
|
||||
tree->set(get_blend_position_path(), blend_pos);
|
||||
|
||||
blend_space_draw->queue_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace1DEditor::_blend_space_draw() {
|
||||
AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
|
||||
if (!tree) {
|
||||
return;
|
||||
}
|
||||
|
||||
Color linecolor = get_theme_color(SNAME("font_color"), SNAME("Label"));
|
||||
Color linecolor_soft = linecolor;
|
||||
linecolor_soft.a *= 0.5;
|
||||
@@ -301,7 +308,7 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_draw() {
|
||||
color.a *= 0.5;
|
||||
}
|
||||
|
||||
float point = AnimationTreeEditor::get_singleton()->get_animation_tree()->get(get_blend_position_path());
|
||||
float point = tree->get(get_blend_position_path());
|
||||
|
||||
point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
|
||||
point *= s.width;
|
||||
@@ -575,12 +582,17 @@ void AnimationNodeBlendSpace1DEditor::_notification(int p_what) {
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_PROCESS: {
|
||||
AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
|
||||
if (!tree) {
|
||||
return;
|
||||
}
|
||||
|
||||
String error;
|
||||
|
||||
if (!AnimationTreeEditor::get_singleton()->get_animation_tree()->is_active()) {
|
||||
if (!tree->is_active()) {
|
||||
error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails.");
|
||||
} else if (AnimationTreeEditor::get_singleton()->get_animation_tree()->is_state_invalid()) {
|
||||
error = AnimationTreeEditor::get_singleton()->get_animation_tree()->get_invalid_state_reason();
|
||||
} else if (tree->is_state_invalid()) {
|
||||
error = tree->get_invalid_state_reason();
|
||||
}
|
||||
|
||||
if (error != error_label->get_text()) {
|
||||
|
||||
Reference in New Issue
Block a user