Why cannot mutate arrays with UndoRedo?

Godot Version

v4.3.stable.official [77dcf97d8]

Question

When I bind a value to Array.append and pass it as a Callable arg to UndoRedo.add_do_method, the array seems unchanged.

Cannot I use UndoRedo to add or remove elements of arrays?

Reproduction

	_undo_redo.create_action('Add 5')
	_undo_redo.add_do_method(_array.append.bind(5))
	_undo_redo.add_undo_method(_array.erase.bind(5))
	_undo_redo.commit_action()

This results _array -> [].

Thank you!

In godot source:

void UndoRedo::add_do_method(const Callable &p_callable) {
	ERR_FAIL_COND(!p_callable.is_valid());
	ERR_FAIL_COND(action_level <= 0);
	ERR_FAIL_COND((current_action + 1) >= actions.size());

	ObjectID object_id = p_callable.get_object_id();
	Object *object = ObjectDB::get_instance(object_id);
	ERR_FAIL_COND(object_id.is_valid() && object == nullptr);

Array is NOT Object so Array has no object ID:

  1. get_object_id() -> 0
  2. get_object() -> null
  3. UndoRedo does not call Array methods :frowning_face:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.