NPC with Dialogic2

Godot Version

Godot Engine v4.2.2.stable.official.15073afe3

Question

I am currently working on an NPC for my 2D game and use Dialogic2 for the dialog. The NPC is an Area 2D and should only be interactable when the player is in the CollisionShape.

Here is the Code from the Area 2D:

extends Area2D


func _on_body_entered(body):
	if "Player" in body.name:
		if Input.is_action_just_released("ui_accept"):
			Dialogic.start("Wegweiser1")


func _on_body_exited(body):
	pass

The text I have entered in Dialogic is simply not displayed when I press the Enter key. I just don’t know where the error is.

There already was a similar topic in the past:

The most important quote is this:

What this piece of code means is that you would need to press the “interact” action EXACTLY at the same time (down to a single frame) as the body entered the area, in order to emit the signal, which is close to impossible.

I would suggest you to rearrange your code to be the following:

var is_player_within_area: bool

func _on_body_entered(body: Node2D) -> void:
	if body.name == "Player":
		is_player_within_area = true

func _on_body_exited(body: Node2D) -> void:
	if body.name == "Player":
		is_player_within_area = false

func _unhandled_input(event: InputEvent) -> void:
	if event.is_action_pressed("ui_accept") and is_player_within_area:
		Dialogic.start("Wegweiser1")

Oh ok, I must have overlooked it before.
Thanks :slight_smile:

1 Like