Is this a bug?newbie with gdscript

Godot Version

4.3 stable

Question

https://github.com/godotengine/godot-docs-project-starters/releases/download/latest-4.x/instancing_starter.zip

extends Node

@export var Ball: PackedScene

func _input(event):
	if event.is_action_pressed("click"):
		var new_ball = Ball.instantiate()
		new_ball.position = get_viewport().get_mouse_position()
		add_child(new_ball)

With this demo i can run and all thing works
If i click a new ball is created , but if in script I change the variable name of Ball, click can not work any more as expected
But not work even I change it back

Quick tip: you can format your code in your posts by selecting all the code and pressing ctrl+e. It makes it much easier to troubleshoot.

Do you get an error message in the debugger?

thank you for tip , I got “Cannot call method ‘instantiate’ on a null value.”
to reproduce ,

  1. import demo repository
  2. run, all things works
  3. change the main script to (change only variable name)
extends Node

@export var Ball2: PackedScene

func _input(event):
	if event.is_action_pressed("click"):
		var new_ball = Ball2.instantiate()
		new_ball.position = get_viewport().get_mouse_position()
		add_child(new_ball)
  1. run again, get “Cannot call method ‘instantiate’ on a null value.”
  2. change code back to default
 extends Node

@export var Ball: PackedScene

func _input(event):
	if event.is_action_pressed("click"):
		var new_ball = Ball.instantiate()
		new_ball.position = get_viewport().get_mouse_position()
		add_child(new_ball)
  1. run , still get error “Cannot call method ‘instantiate’ on a null value.”

tested with MacOS 15 m2 and x86 vmware win10

You will have to place the ball scene in inspector after changing its variable name.

select your scene having this script and in the inspector load the ball scene in your ball2 var

It should look like this :point_down:
Screenshot 2024-09-18 195534

2 Likes

Thank you , I successfully make it working as expected.
I was too curious

1 Like

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