Skip to content

Engine APIs with nullable parameters should accept Option<Gd<T>>, but currently require Gd<T> #156

@atrefonas

Description

@atrefonas

[Edit bromeon]

If you come here because of an error message in gdext, that error message is correct. You likely encounter an API which is supposed to accept null arguments, but has a Gd<T> parameter declared -- so it's not possible to pass null.

Possible workaround: use Object::call() with Variant::nil().

Issue #494 tracks a similar problem, but applied to virtual functions (the I* traits) instead of godot::engine API.
That one cannot be worked around currently.

Original title of this issue was:

Codegen issue: the collision argument of PhysicsBody3D.test_move() should be Option<Gd<KinematicBody3D>>


Original message

In the GDScript docs for PhysicsBody3D, there is:

bool test_move ( Transform3D from, Vector3 motion, KinematicCollision3D collision=null,
  float safe_margin=0.001, bool recovery_as_collision=false, int max_collisions=1 )

As you can see, the 3rd argument has a default null value. Rust does not allow nulls, and uses Option instead.

However, in the generated Rust function, it (IMO incorrectly) requires a Gd value that needs to be non-null.

pub fn test_move(
    &mut self,
    from: Transform3D,
    motion: Vector3,
    collision: Gd<KinematicCollision3D>,
    safe_margin: f64,
    recovery_as_collision: bool,
    max_collisions: i64
) -> bool

The collision argument should be an Option so that it can take a None value. Otherwise, there is no known way to use the default arguments. This issue is related to #155

It's also likely that similar codegen issues exist in many other APIs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugc: engineGodot classes (nodes, resources, ...)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions