dialogic-godot / dialogic-1

Dialogic 1.x - For Godot 3.x!
MIT License
6 stars 4 forks source link

Remove_child on a dialog make it crash #1

Open ParisRomane opened 2 years ago

ParisRomane commented 2 years ago

Hello everyone ! I just tried dialogic for the first time a week ago, I love it.

My problem is : i want to be able to pause dialog and get back to it, without having to end dialog and play it back from the start. For example, i want to be able to open a menu or an inventory when we are in a middle of a dialog.

I have tried everything i can to pause dialog. Nothing works. I even tried to do it brutally, with remove_child(dialog) and add_child(dialog). That is when i find a bug i believe : remove_child(dialog) -> "Attempt to call 'get_visible_rect' in base 'null instance' on a null instance"

Describe the bug remove_child(dialog) make the game cash, with "Attempt to call 'get_visible_rect' in base 'null instance' on a null instance" in DialogNode.gd (also btw, is there a way to pause dialog ?)

To Reproduce Steps to reproduce the behavior:

  1. create a dialog, and instance it normally -> add_child(dialog)
  2. While the dialog isn't finished, do remove_child(dialog)
  3. See error ("Attempt to call 'get_visible_rect' in base 'null instance' on a null instance")

Expected behavior I expected to just remove the dialog. but it's seems like it is still working. But it can't so it crash.

Screenshots the result of the crash : bug

System (please complete the following information):

Solutions

Workaround Nothing that i tried works to get the dialog to pause. We can end dialog and play it back from the start tho.

Possible fixes No idea yet.

Jowan-Spooner commented 2 years ago

Hmm... it seems like the DialogNode doesn't like to be outside of the tree after connecting to the viewport. Removing nodes from the tree without deleting them is a unusual move, so this has never happened in testing.

If you just want to delete the node do dialog.queue_free().

For pausing: have you considered using godot's pause system? I understand that might not work for your project tho.

It's unlikely we will make a fix, as we are putting most efforts into dialogic 2.0. Here are possible "hacky"-quick-fixes:

ParisRomane commented 2 years ago

Thanks a lot for the answer ! Godot pause system doesn't really work as i want. Thanks a lot for the suggestions, they are really good ! I will try to create my pause fonction tomorow

ParisRomane commented 2 years ago

I have followed your advice. I might not have done it in the cleanest way. If someone need the same feature this is what i have done : in dialog_node.gd i add ->

var paused = false

func set_paused(pause):
    paused = pause

func get_paused():
    return paused

func _input(event: InputEvent) -> void:
    if paused :
        return
    [...]

in canvas_dialog_node.gd i add :


func set_paused(pause):
    dialog_node.set_paused(pause)
    if pause : # those line hide visually the dialog
        dialog_node.hide()
    else :
        dialog_node.show()

func get_paused():
    return dialog_node.get_paused()

Now i can have open a menu (or inventory) in the middle of a dialog. thanks again ! :+1:

zaknafean commented 6 months ago

This was completed.