I want to write a small module to visualize some properties if my ASegment class in the editor. I already tried this tutorial: A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums
and got the basic module compiled and activated. I only got problems with the actual drawing and there aren’t many useful references about this topic. So this is my custom visualizer class declaration:
class ASegmentVisualizer : public FComponentVisualizer
{
public:
ASegmentVisualizer();
virtual void DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI) override;
};
and the implementation:
ASegmentVisualizer::ASegmentVisualizer(){
UE_LOG(CubeProjectModule, Warning, TEXT("SEGMENTVISUALIZER : CONSTRUCTOR"));
}
void ASegmentVisualizer::DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI)
{
//cast the component into the expected component type
if (const ASegment* TargetingComponent = Cast<const ASegment>(Component))
{
const FVector Locaction = TargetingComponent->GetActorLocation();
PDI->DrawPoint(TargetingComponent->GetActorLocation()+FVector(0,0,120), FLinearColor(255,0,0), 20.f, SDPG_Foreground);
PDI->DrawLine(TargetingComponent->GetActorLocation() + FVector(0, 0, 500), TargetingComponent->GetActorLocation(), FLinearColor(1.0, 0, 0), 20.f, SDPG_Foreground);
PDI->DrawLine(FVector(0, 0, 200), FVector(500, 0, 200), FLinearColor(1.0, 0, 0), 20.f, SDPG_Foreground);
}
UE_LOG(CubeProjectModule, Warning, TEXT("SEGMENTVISUALIZER : DRAW"));
}
the constructor gets called, but not the drawing method.
Here is my StartupModule() procedure:
void FCubeProjectModuleModule::StartupModule()
{
if (GUnrealEd != NULL)
{
TSharedPtr<FComponentVisualizer> Visualizer = MakeShareable(new ASegmentVisualizer());
if (Visualizer.IsValid())
{
GUnrealEd->RegisterComponentVisualizer(ASegment::StaticClass()->GetFName(), Visualizer);
Visualizer->OnRegister();
}
}
UE_LOG(CubeProjectModule, Warning, TEXT("CubeProjectModule: Log Started"));
}
I don’t really know how to get this working. Has anyone any ideas?