touilleMan / godot-python

Python support for Godot 🐍🐍🐍
Other
1.87k stars 142 forks source link

Inherited ExportedFields are not read #334

Closed ARoefer closed 4 months ago

ARoefer commented 2 years ago

I don't know if I am missing a step, but I have observed the following:

Given a base class

from godot import exposed, export
from godot import *

@exposed
class AgentBase(KinematicBody):

    # member variables here, example:
    interaction_radius = export(float, default=1.0)
    agent_speed        = export(float, default=0.8)
    agent_idx          = export(int, default=0)
    agent_radius       = export(float, default=0.3)

And a derived class

from godot import exposed, export
from godot import *

from scripts.agent_base import AgentBase

@exposed
class HumanPlayer(AgentBase):
    cursor_speed    = export(float, default=1.5)

    def _ready(self):
        self.interaction_center = self.get_node('InteractionCenter') # type: Spatial
        self.interaction_center.translation = Vector3(0, 1.05, -self.interaction_radius)

I get the following error:

Traceback (most recent call last):
  File "build/x11-64/pythonscript/_godot_instance.pxi", line 128, in _godot.pythonscript_instance_call_method
  File "/[...]/scripts/human_player.py", line 42, in _ready
    self.interaction_center.translation = Vector3(0, 1.05, -self.interaction_radius)
  File "build/x11-64/pythonscript/godot/builtins.pyx", line 114, in godot.builtins.Vector3.__init__
TypeError: must be real number, not ExportedField

When I use self.cursor_speed in the construction of the vector, I do not run into this problem. Is there a way to work around this issue?