Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.1.beta3][GDScript] Cannot call virtual function because it hasn't been defined. #78532

Closed
adamscott opened this issue Jun 21, 2023 · 4 comments · Fixed by #78533
Closed
Assignees
Milestone

Comments

@adamscott
Copy link
Member

adamscott commented Jun 21, 2023

Godot version

4.1.beta3

System information

Fedora Workstation 38 - Godot 4.1.beta3 - Vulkan (Forward+)

Issue description

This is an issue created by the production team, we're working on it

Currently, it's impossible to call virtual functions within GDScript.

This currently returns an error:

# a.gd
extends Node

func _process(delta: float) -> void:
	pass
# main.gd
extends Node

var my_node: Node = preload("res://a.gd").new()

func _process(delta: float) -> void:
	my_node._process(delta)  # Cannot call virtual function "_process()" because it hasn't been defined.

Steps to reproduce

  1. Create a script (a.gd) based on Node that declares _process();
  2. Create a main node;
  3. Attach a script to the main node;
  4. Initialize a variable with a new a.gd instance;
  5. Try to run _process() on that node;
  6. Find out that it returns an error.

Minimal reproduction project

virtual_functions.zip (updated)

@adamscott adamscott pinned this issue Jun 21, 2023
@adamscott adamscott changed the title Cannot call virtual function because it hasn't been defined. [Beta 3][GDScript] Cannot call virtual function because it hasn't been defined. Jun 21, 2023
@adamscott adamscott added this to the 4.1 milestone Jun 21, 2023
@adamscott adamscott self-assigned this Jun 21, 2023
@adamscott adamscott changed the title [Beta 3][GDScript] Cannot call virtual function because it hasn't been defined. [4.1 Beta 3][GDScript] Cannot call virtual function because it hasn't been defined. Jun 21, 2023
@adamscott adamscott changed the title [4.1 Beta 3][GDScript] Cannot call virtual function because it hasn't been defined. [4.1.beta3][GDScript] Cannot call virtual function because it hasn't been defined. Jun 21, 2023
@anvilfolk
Copy link
Contributor

I think this might mean we need to partially revert #77324, without any replacement 😞

The issue is that at compile-time we cannot check whether any Object, Node or otherwise, has a script attached. The script is the one responsible for implementing virtual functions, so the base type is simply not enough. I'll have a PR ready momentarily.

@hilfazer

This comment was marked as off-topic.

@AThousandShips

This comment was marked as off-topic.

@hilfazer

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants