So, I have a behavior tree that I have set up. I have a timer node in it as a ConditionLeaf. I use the same node two places in my code, one is for my enemies movement, the other is for their attack. I use @export variables so that I can change the time while using same script. One node works just fine and has a timer of 0.33 seconds, the other timer for my attack starts out at 1.0, and then when it resets it resets to 0.2, and that is what it keeps resetting to, never continuing down my behavior tree to initiate the attack.

@icon("res://icons/node_2D/icon_time.png")

extends ConditionLeaf

@export var timer_length: float
@export var current_timer: float
@export var debug_switch: bool

func tick(actor, blackboard):
	if debug_switch:
		return FAILURE
	if not current_timer > 0:
		current_timer = timer_length
		return SUCCESS
	current_timer -= blackboard.get_value("delta", null, actor)
	return RUNNING

This is the code, this is the same code used in both places, one works, and one fails. The working one the timers are set to 0.33, the failure is 1.0. The blackboard is getting delta time stored at the top of the behavior tree.

  • xyz replied to this.
  • One approach is to create a new minimal reproduction project that illustrates the problem.

    "Minimal" means using only enough nodes and scripts to duplicate the symptom.

    Often the process of doing that will reveal the mistake.

    xRegnarokx You haven't provided enough context for someone to debug this for you. Either way, it may be time to stop asking debugging questions and learn to get confident with debugging your own code.

      xyz Yeah... unfortunately what other context is there, that is why I am stumped. I cannot for the life of me figure out what is causing one of two identical timers to work, and the other not to. I have spent two days trying to debug this, and rewritten the code multiple times, that is why I posted here.

      I have searched every inch of my code and there is no references to this part of the code from outside changing it. This is why it has been so frustrating. I guess then completely deleting my behavior tree and rebuilding it from ground up again is my next step.

      • xyz replied to this.

        One approach is to create a new minimal reproduction project that illustrates the problem.

        "Minimal" means using only enough nodes and scripts to duplicate the symptom.

        Often the process of doing that will reveal the mistake.

          xRegnarokx Then you need to learn to debug better. Print everything and use breakpoints to determine what's actually happening. Try to isolate the bug by gradually excluding parts that you're certain can't be the cause.

            DaveTheCoder I do know what minimal is, but that is a good idea if it actually reveals the bug. I often do that when I've helped people debug their projects.

            xyz I've excluded already everything else except for that segment of code. I know where it is having a problem but not why.

            • xyz replied to this.

              xRegnarokx I know where it is having a problem but not why

              How do you know you're right about this?

                xyz Because I used print statements throughout my code, as well as writing "debug" lines like you can see in the example code to turn off non associated nodes.

                Also, I have the same setup for my player and the timer works for my player.

                xRegnarokx In any case, best to do what Dave said; make a MRP. If in the process of making it the cause of the problem doesn't become apparent - post it for additional pair of eyes to look at it.