OnDrawGizmos

daphii

New member
I am just getting started with BD, and I'm really enjoying what ive seen so far!

I am trying to implement a version of the behaviour tree tutorial's CanSeeObject in my own project, and everything seems to be working well so far, but ive come across a small snag i cant seem to sort out!

Everything works as intended while in edit mode, but if i press play, my gizmo disappears! The Behaviour Tree Gizmos are enabled in both play and edit mode, but seems to stop being called in play mode. (the debug confirms this by stopping after about 100 frames in play mode.

public override void OnDrawGizmos() { DrawWireArc(Owner.transform.position, Owner.transform.forward, fieldOfViewAngle.Value, viewDistance.Value); Debug.Log("Drawing Gizmo"); // } public void DrawWireArc(Vector3 position, Vector3 dir, float anglesRange, float radius, float maxSteps = 20) { var srcAngles = GetAnglesFromDir(position, dir); var initialPos = position; var posA = initialPos; var stepAngles = anglesRange / maxSteps; var angle = srcAngles - anglesRange / 2; Gizmos.color = gizmoColor; for (var i = 0; i <= maxSteps; i++) { var rad = Mathf.Deg2Rad * angle; var posB = initialPos; posB += new Vector3(radius * Mathf.Cos(rad), radius * Mathf.Sin(rad), 0); Gizmos.DrawLine(posA, posB); angle += stepAngles; posA = posB; } Gizmos.DrawLine(posA, initialPos); } static float GetAnglesFromDir(Vector3 position, Vector3 dir) { var forwardLimitPos = position + dir; var srcAngles = Mathf.Rad2Deg * Mathf.Atan2(forwardLimitPos.z - position.z, forwardLimitPos.x - position.x); return srcAngles; }

Edit Mode:
1697572663730.png1697572705653.png

Play Mode:
1697572798776.png

The Gizmo Shows up for the first 100 or so frames, then stops.

This might just be a setting or something, but I cant for the life of me figure it out! Any advice would be welcome!

Thanks for your time! <3
 
Glad you are enjoying Behavior Designer!

At runtime OnDrawGizmos is only called when the task is running or is being reevaluated. When the task is inactive then the gizmos aren't drawn. There isn't a setting to change this but if you download the runtime source you can then change it within Behavior.DrawTaskGizmos.
 
Thanks for your quick reply, that makes perfect sense! I think I was focused on it disappearing so quickly after starting, that I couldn't tell if it was actually running in play mode, or I was just seeing it for that moment when everything was loading!

Adding a repeater quickly showed me that all was fine, the sequence had just finished, so the gizmo was gone as well! It is working exactly as intended now!
 
Top