0 votes

Hi, newbie here crossing over from Unity, I often like to refer to other c# classes I might have declared in my project e,g:

public class Foo
{
  private Bar bar;

  public void init()
  {
     bar = new Bar();
  }
}

In GDScript I am trying to declare bar like so:

Foo.gd

extends Spatial

class_name Foo

var bar: Bar

Bar.gd

extends Node

class_name Bar

But I get the following error:
'The identifier "Bar" isn't a valid type'

in Engine by (12 points)

2 Answers

0 votes

dont know if i understood the question correctly, but if you want the Bar to have all the properties and methods of Foo plus whatever you add to the Bar script, you can extend it from the Foo script

extend "res://Foo.gd"
by (1,514 points)
0 votes

In case of external text editor (such as Visual Studio Code) you might have to restart Godot Editor to update classnames and methods (I use Godot 3.2.3 and I have to restart Godot to refresh methods and classnames, or VSCode highlights lines as warnings/errors).

by (1,650 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.