You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-13 13:31:48 +00:00
Add error checks for bad configuration in PathFollow2D/3D set_progress_ratio
When a PathFollow is badly configured it's possible to have code that
call get_progress_ratio just after set_progress_ratio does not return
the value just set, which may be confusing for developer (ie that
myPathFollow2D.set_progress_ratio(0.5)
myPathFollow2D.get_progress_ratio()
does not return 0.5)
This commit makes ensures the developer has useful error messages in
such case, to make it easier to troubleshot it.
This commit is contained in:
committed by
Rémi Verschelde
parent
139f9989e6
commit
ea9dff87ae
@@ -378,9 +378,10 @@ real_t PathFollow2D::get_progress() const {
|
||||
}
|
||||
|
||||
void PathFollow2D::set_progress_ratio(real_t p_ratio) {
|
||||
if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) {
|
||||
set_progress(p_ratio * path->get_curve()->get_baked_length());
|
||||
}
|
||||
ERR_FAIL_NULL_MSG(path, "Can only set progress ratio on a PathFollow2D that is the child of a Path2D which is itself part of the scene tree.");
|
||||
ERR_FAIL_COND_MSG(path->get_curve().is_null(), "Can't set progress ratio on a PathFollow2D that does not have a Curve.");
|
||||
ERR_FAIL_COND_MSG(!path->get_curve()->get_baked_length(), "Can't set progress ratio on a PathFollow2D that has a 0 length curve.");
|
||||
set_progress(p_ratio * path->get_curve()->get_baked_length());
|
||||
}
|
||||
|
||||
real_t PathFollow2D::get_progress_ratio() const {
|
||||
|
||||
Reference in New Issue
Block a user