how to fix the error nonexistent function "instance" in base"nil"

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By J_JPr0du

Hello everyone,
When encoding this tape:
var new_platform = scene_platform.instance() as StaticBody2D

an error appears: nonexistent function “instance” in base"nil"

how to fix the error??

:bust_in_silhouette: Reply From: kidscancode

This error is telling you that the variable you’re calling instance() on is null. Where are you setting the value of scene_platform?

I’m not sure if I understood correctly, but if you mean it:
export (PackedScene) var scene_platform
if i’m wrong. then please help me how can i get the scene_platform value))

J_JPr0du | 2022-07-19 15:58

Yes, that’s right. Have you assigned a scene to that variable in the Inspector? Because the error is saying that you haven’t.

kidscancode | 2022-07-19 16:02

with your help, I can see what the problem is, BIG THANK YOU)
but can you help me fix it?)

J_JPr0du | 2022-07-19 16:16

Well, you’ve defined the variable as export meaning it will be visible for you to set a value in the Inspector, so that’s what you need to do.

In the Inspector, you can assign the scene you want in a couple of ways:

  1. Drag the tscn file from the FileSystem tab and drop it on the variable in the Inspector
  2. In the variable in the inspector, click the down arrow (where it says “[empty]” and choose “Load”, then choose the scene you want

kidscancode | 2022-07-19 16:20

I tried both options a few times and saved the changes as well

  1. scene_platform was still empty
  2. after starting the scene, the same problem appears again the exported file disappears from the field

J_JPr0du | 2022-07-19 16:31

You drag it in there and it stays empty?

Do you have this scene with the exported field instanced somewhere else?

kidscancode | 2022-07-19 16:37

i drag the tscn scene into the field:
Script Variables:
scene_platform [nul]

it is preserved, but the value
equal to [null]

yes, I have a saved tscn scene, and no, it is not instantiated anywhere else
after restarting the game, the same problem appears and the field-Script Variables:
scene_platform- becomes empty

J_JPr0du | 2022-07-19 16:47

I feel like I’m missing something in your description. Words are failing us here.

If you zip up your project and send it to me I’d be happy to look at it and see what’s going on.

kidscancode | 2022-07-19 16:49

can i send you the whole project file to your email? I’m not sure if it’s possible to submit it on this site

J_JPr0du | 2022-07-19 17:24

That or you can post it on a filesharing site.

It’s chris at

kidscancode | 2022-07-19 17:30

I sent you the zip file of the project by email, if you find the problem, please write back

J_JPr0du | 2022-07-19 17:44