UE4中提供了很多预定义的调试绘制函数,在做调试的时候还是比较方便的。可以在场景里绘制点、线、圆、球、箭头、椎体、胶囊、甚至样条线、字符串、网格等等,基本上该有的都有了。比较赞的是,你能控制线条的厚度,调试的时候就比较直观了。
要使用这些函数,只需要包含DrawDebugHelpers.h 头文件即可。下面介绍几个主要的绘制函数:
1.绘制点
ENGINE_API void DrawDebugPoint(const UWorld* InWorld, FVector const& Position, float Size, FColor const& PointColor, bool bPersistentLines = false, float LifeTime=-1.f, uint8 DepthPriority = 0);
可选参数里面,我们可以控制点的尺寸、颜色、持续时间等。bPersistentLines表示,当前绘制的整个对象,是不是持久对象,设为true,它会一直显示当前World,直到你调用下面这个方法,释放它:
void FlushPersistentDebugLines(const UWorld* InWorld);
其他的绘制函数,此参数意义都是一样的。
2.绘制线
ENGINE_API void DrawDebugLine(const UWorld* InWorld, FVector const& LineStart, FVector const& LineEnd, FColor const& Color, bool bPersistentLines = false, float LifeTime=-1.f, uint8 DepthPriority = 0, float Thickness = 0.f);
注意Thickness这个参数,它控制线条的厚度。
3.绘制箭头
ENGINE_API void DrawDebugDirectionalArrow(const UWorld* InWorld, FVector const& LineStart, FVector const& LineEnd, float ArrowSize, FColor const& Color, bool bPersist