# Drawing debug lines to persona viewport from AnimNode

**URL:** <https://forums.unrealengine.com/t/drawing-debug-lines-to-persona-viewport-from-animnode/277475>\
**Category:** Debugging, Optimization, & Profiling\
**Tags:** Debugging, viewport, unreal-engine, editor, UE4, CPP, question\
**Created:** [March 20, 2014, 4:34am UTC](https://forums.unrealengine.com/t/drawing-debug-lines-to-persona-viewport-from-animnode/277475 "2014-03-20T04:34:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![twiddle](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@twiddle](https://forums.unrealengine.com/u/twiddle)\
**Post date:** [March 20, 2014, 4:34am UTC](https://forums.unrealengine.com/t/drawing-debug-lines-to-persona-viewport-from-animnode/277475/1 "2014-03-20T04:34:30Z")

</div>

So I’ve been still wrestling with the SkelControl bone rotation issue I asked about in **[this question](https://answers.unrealengine.com/questions/12420/bone-local-axis-orientation-in-custom-animnode.html)** , and I figured that at the very least being able to draw the calculated rotation axis to the viewport would help me in debugging the issue.  
Is it possible for me to access the viewport and draw some debugging lines, etc, to it, from inside my custom AnimNode/SkelControl? If so, where should I look in the documentation to find out how?

Edit: So, I found

`void UAnimGraphNode_SkeletalControlBase::Draw( FPrimitiveDrawInterface* PDI, USkeletalMeshComponent * PreviewSkelMeshComp ) const;`

There’s a caveat with that though. If I want to use it to draw data that’s generated during EvaluateBoneTransforms() on my runtime node, I need to cache that data so that Draw() can pull it out.  
However the instance of my runtime node that is created inside the AnimGraph node

`UPROPERTY(EditAnywhere, Category=Settings)`

`FAnimNode_Fabrik Node;`

(as the documentation says I should), isn’t the same as the instance that is actually running, when I look at it in the debugger; all the values I’m caching aren’t present in the instance that Draw() can access. How should I be doing this instead?

Edit 2: More digging with the debugger shows that the constructor for my AnimGraphNode is being called at least 6 or 8 times during editor startup, as well as when I open the Anim Blueprint in the editor. I’m now even more confused.

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 26, 2014, 5:33am UTC](https://forums.unrealengine.com/t/drawing-debug-lines-to-persona-viewport-from-animnode/277475/2 "2014-03-26T05:33:41Z")

</div>

#Persona Viewport World?

Is the Persona Viewport a world you can determine?

If so then you can use

[Draw Debug Line](https://wiki.unrealengine.com/Draw_3D_Debug_Points,_Lines,_and_Spheres:_Visualize_Your_Algorithm_in_Action!)

with that UWorld()

---

<div class="post-metadata">

**Author:** ![twiddle](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@twiddle](https://forums.unrealengine.com/u/twiddle)\
**Post date:** [March 26, 2014, 5:49am UTC](https://forums.unrealengine.com/t/drawing-debug-lines-to-persona-viewport-from-animnode/277475/3 "2014-03-26T05:49:02Z")

</div>

So the persona Viewport is AnimationEditorViewportClient, which inherits from FViewportClient and that class has GetWorld() implemented.  
The issue is that each node in the graph (the editor class) has a secondary class responsible for the actual calculations of each node (a runtime class) and it is the runtime class that needs to be able to draw the information. However it doesn’t have a reference to the Graph Node that is its parent, which makes sense because in runtime mode you wont have a parent graph node (the graph doesnt exist in the runtime context, just the editor context). The runtime class, which is a subclass of FAnimNode\_SkeletalControlBase, doesn’t know anything about the world it is in, it’s just given skeletal data and told to update the bones it needs to.

So the issue is that I can confirm that the viewport has a world reference, but I cannot access the viewport from the runtime object, and while the editor node might be able to access the viewport, I cannot use it to pull the data from public variables on the runtime object, because the instance that the graph node has is not the instance actually performing the calculation.

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 26, 2014, 7:35am UTC](https://forums.unrealengine.com/t/drawing-debug-lines-to-persona-viewport-from-animnode/277475/4 "2014-03-26T07:35:44Z")

</div>

#Initialize(const FAnimationInitializeContext & Context)

```
UWorld * TheWorld = Context.AnimInstance->GetWorld();

```

* * *

I found a way to access the world context just fine in my Turn in Place Animation node, I have not fully updated it to UE4 though, but this is what worked in the Beta!

#Entire Source Code  
Full code here:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

#Excerpt

```
void FAnimNode_VictoryTurnInPlace::Initialize(const FAnimationInitializeContext & Context) 
{
	//Init the Inputs
	BasePose.Initialize(Context);
	TurnPose.Initialize(Context);
 
	//Get the Actor Owner
	OwningActor = Context.AnimInstance-> GetSkelMeshComponent()->GetOwner(); 
 
	//Editor or Game?
	UWorld * TheWorld = Context.AnimInstance->GetWorld();
	if (!TheWorld) return;
	// ~~~~~~~~~~~~~~~~
 
	WorldIsGame = (TheWorld->WorldType == EWorldType::Game);
}
```

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 26, 2014, 7:51am UTC](https://forums.unrealengine.com/t/drawing-debug-lines-to-persona-viewport-from-animnode/277475/5 "2014-03-26T07:51:01Z")

</div>

#AnimNodeBase

It’s now called AnimNodeBase, not AnimNode\_Base

---

<div class="post-metadata">

**Author:** ![twiddle](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@twiddle](https://forums.unrealengine.com/u/twiddle)\
**Post date:** [March 26, 2014, 7:51am UTC](https://forums.unrealengine.com/t/drawing-debug-lines-to-persona-viewport-from-animnode/277475/6 "2014-03-26T07:51:21Z")

</div>

This looks good. I’ll give it a shot as soon as I have a chance to sit down with the code again - I’m a bit surprised I missed the GetWorld function as being accessible in the animation context as I did go looking there, but it looks like its defined fairly high up in the class hierarchy so I didn’t look hard enough evidently. 🙂 I will return to mark this as resolved once I’ve tested it.

---

<div class="post-metadata">

**Author:** ![twiddle](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@twiddle](https://forums.unrealengine.com/u/twiddle)\
**Post date:** [March 26, 2014, 7:52am UTC](https://forums.unrealengine.com/t/drawing-debug-lines-to-persona-viewport-from-animnode/277475/7 "2014-03-26T07:52:53Z")

</div>

All good, its still AnimNode\_Base in the codebase I’m using at present. But thanks for notifying me.

---

<div class="post-metadata">

**Author:** ![twiddle](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@twiddle](https://forums.unrealengine.com/u/twiddle)\
**Post date:** [March 26, 2014, 10:19am UTC](https://forums.unrealengine.com/t/drawing-debug-lines-to-persona-viewport-from-animnode/277475/8 "2014-03-26T10:19:27Z")

</div>

Caching the world reference in Initialize() and then calling DrawDebugLine() inside the EvaluateBoneTransforms() did the trick. Thanks 🙂

---

<div class="post-metadata">

**Author:** ![735333df6d5b4784be24](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@735333df6d5b4784be24](https://forums.unrealengine.com/u/735333df6d5b4784be24)\
**Post date:** [February 20, 2023, 8:26am UTC](https://forums.unrealengine.com/t/drawing-debug-lines-to-persona-viewport-from-animnode/277475/9 "2023-02-20T08:26:49Z")

</div>

hello.

this just returns Null!!!

```auto
InAnimInstance->GetWorld()

```

```auto

	virtual void
	OnInitializeAnimInstance(const FAnimInstanceProxy* InProxy, const UAnimInstance* InAnimInstance) override
	{
		CurrentRetargetAsset = nullptr;
		Super::OnInitializeAnimInstance(InProxy, InAnimInstance);
		MyWorld = InAnimInstance->GetWorld();
		UE_LOG(LogTemp, Warning, TEXT("the world initialized."));
	}

```

---

<div class="post-metadata">

**Author:** ![ceriseraine](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ceriseraine](https://forums.unrealengine.com/u/ceriseraine)\
**Post date:** [August 10, 2023, 2:30am UTC](https://forums.unrealengine.com/t/drawing-debug-lines-to-persona-viewport-from-animnode/277475/10 "2023-08-10T02:30:40Z")

</div>

This is 1000 years old, but using the “FPoseContext” you can access the “AnimInstanceProxy” which contains calls to visual debug drawing functions.

here the FPoseContext name is output:

```auto
#if (!UE_BUILD_SHIPPING && UE_EDITOR)
		output.AnimInstanceProxy->AnimDrawDebugSphere(
			output.AnimInstanceProxy->GetSkelMeshComponent()->GetComponentLocation() + 
				(FQuat(output.AnimInstanceProxy->GetSkelMeshComponent()->GetComponentRotation()) * jointLocation), 
			10, 10, FColor::Red);
#endif

```
