Help with NPC interaction!

Godot Version 4.5

To preface, I am a student and have never used Godot before last month! So be nice to me please!

Question

How do you fix a node not being able to see a child node? For context, I’ve been following this guide:

https://www.youtube.com/watch?v=ajCraxGAeYU

The problem I’m having is at 8:50 in the video. My NPC node has the Area2D interaction area node in it. My code has

@onready var interaction_area: interactionarea = $interactionarea

and later
func _ready():
interaction_area.interact = Callable(self, “_on_interact”)

I get the error:
Invalid assignment of property or key ‘interact’ with value of type ‘Callable’ on a base object of type ‘null instance’.
The comments had an answer for this! Someone wrote:

"When adding the interaction area scene to your interactable node, you must add it exactly as they do at 8:23! Don’t use “Add child node”. Use “Instantiate Child Scene”. You can do this a few ways:

  • Click the chain link button in the top left of the node list
  • Right click → Instantiate child scene
  • Drag the interaction area scene (tscn) file into the node list

If you add it as a child node, you can see that it won’t have the little WiFi symbol in the node list (no signals attached). If you add it with “Instantiate Child Scene”, it will have the little WiFi symbol, carrying over the signals you defined in the interaction area scene."

I tried the Instantiate Child Scene, but I couldn’t get a wifi symbol on my Area2d. How would I go about this?

I tried the Instantiate Child Scene, but I couldn’t get a wifi symbol on my Area2d. How would I go about this?

Did you follow the step at 7.38? The wifi symbol is a signal thats called automatically. The signal that was added was body_entered and body_exited (when the player enters the interaction area and leaves).

You declared a var of type interactionarea named interactin_area. The error is telling you that you can’t change this to type Callable.

For example, this would be valid:

# this is a declaration of variable c
var c: Callable

# this is assignment of variable c
c = Callable(self "_on_some_event")

The callable is assigned to interaction_area.interact, not interaction_area itself.


The property interact is searched for in an object of type null instance. That means something is wrong with the reference stored in interaction_area (which got initialized as $interactionarea). Either the node doesn’t exist (at the correct position with the correct name) or its class is not interactionarea.

If this error is in the code of the NPC and the NPC scene has the interactionarea node, maybe the issue is the NPC not getting instantiated as scene (but only as that scene’s root node)?

1 Like

the Area2d that was the child node in the NPC also needed to be named “interactionarea”! When I imported it it didn’t import the name as well. My game starts now!

The NPC still doesn’t start talking, but at least the game starts! Thanks!

I see, I missed the null instance. Sorry about that. Also sorry for the double post, I fat fingered some hot key and it submitted it before I was done typing.

Glad you got it working!