I'm currently working on the dialogue system in Godot 4 using Dialogue Manager 3. I created a function "checkDialogueFinished" to check whether the dialogue event has ended already. Its supposed to get subscribed to in the "checkInteract" function but it never does. Any help will be appreciated, tyia!
using Godot;
using System;
using DialogueManagerRuntime;
public partial class ObjectInteract : Node {
private Resource dialogue = GD.Load<Resource>("res://Dialogue/Test.dialogue");
private bool isInDialogue = false;
/*
Function Desc: Gets the distance between an object and the player via slope
@param ObjectX -> x-coordinate of the Object
@param ObjectY -> y-coordinate of the Object
@param PlayerX -> x-coordinate of the Player
@param PlayerY -> y-coordinate of the Player
*/
public float getDistanceSlope(float ObjectX, float ObjectY, float PlayerX, float PlayerY){
float dx = ObjectX - PlayerX;
float dy = ObjectY - PlayerY;
float distance = dx * dx + dy * dy;
float trueDistance = (float)Math.Sqrt(distance);
return distance;
}
/*
Function Desc: Checks whether the player is close enough to interact with the object
@param slope -> Distance between object and player
@param objectName -> Name of the object
*/
public void checkInteract(float slope){
if (slope < 850 && Input.IsActionJustPressed("interact") && !isInDialogue){
DialogueManager.ShowExampleDialogueBalloon(dialogue);
isInDialogue = true;
DialogueManager.DialogueEnded += checkDialogueFinished;
GD.Print("Event fired!");
}
}
private void checkDialogueFinished(Resource dialogue) {
GD.Print("Event ended, setting isInDialogue back to false!");
isInDialogue = false;
DialogueManager.DialogueEnded -= checkDialogueFinished;
}
}
I tried checking the DialogueManagerRuntime but still haven't found a solution.
The Prepare()
method in DialogueManager.cs
isn't being called properly in Dialogue Manager 3.3.2. This may be the cause of the problem you're experiencing, as Prepare()
is responsible for connecting the C# Wrapper events to their underlying GDScript signals.
Either edit the DialogueManager.cs script to call it or make it static and call it manually in _Ready()
.
EDIT:
I delved into the C# Wrapper's code again and discovered that GetNextDialogueLine()
was never being called. This is where calls to Prepare(node)
are located. To fix this, open the example_balloon
scene located at:
/dialogue_manager/example_balloon/example_balloon.tscn
Then, replace the example_balloon.gd
script with ExampleBalloon.cs
located in the same directory. Save the scene, and all signals/events should work. Additionally, ensure all custom balloons use ExampleBalloon.cs.