I recently successfully compiled my simple plugin and began creating classes for my tool. However I am at a point where I have a class that takes an array of another class and I would like to see a visual debug connection from the first element in the array to the last. The part marked in red I want to call the OSMNodeActor class getActorLocation function but I do not know how to do such a thing.
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "OSMRoadEditorPrivatePCH.h"
#include "OSMWayActor.generated.h"
/**
*
*/
class AOSMNodeActor;
UCLASS()
class OSMROADEDITOR_API AOSMWayActor : public AActor
{
GENERATED_BODY()
public:
AOSMWayActor(const FObjectInitializer& ObjectInitializer);
void DrawDebugLines();
UPROPERTY(EditAnywhere, Category = "Way Properties")
//Street Name
FName WayName;
UPROPERTY(EditAnywhere, Category = "Way Properties")
//Whether or not to draw Debug Lines.
bool DrawLines;
UPROPERTY(EditAnywhere, Category = "Way Properties")
//Nodes that Make Up This Way.
TArray<AOSMNodeActor*> NodesInThisWay;
};
OSMWayActor.cpp
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#include "OSMRoadEditorPrivatePCH.h"
class AOSMNodeActor;
AOSMWayActor::AOSMWayActor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
WayName = "NULL";
NodesInThisWay.Init(0);
DrawLines = false;
if (DrawLines == true){
AOSMWayActor::DrawDebugLines();
}
}
void AOSMWayActor::DrawDebugLines(){
if (NodesInThisWay.Num() != 0 && NodesInThisWay.Num() < 1){
for (int32 i = 0; i <= NodesInThisWay.Num(); i += 2){
[COLOR="#FF0000"]FVector LinkStart = GetActorLocation();
FVector LinkEnd = GetActorLocation();[/COLOR]
//if (!LinkStart) continue;
//if (!LinkStart->IsValidLowLevel()) continue;
DrawDebugLine(
GetWorld(),
LinkStart,
LinkEnd,
FColor(255, 0, 0),
true, -1, 0,
12.333
);
}
}
}
Geeky, that seems like reasonable code, however the cast<AOSMNodeActor*>(Itr); bit did not work so I changed it to Itr; thinking that might fix it and LinkStart = LinkEnd; was called outside of the scope that it was declared in so I moved that up one bracket. After all of that it does not work still…
looks like the cast should read AOSMNodeActor currNode = cast<AOSMNodeActor>(*Itr); but that still does not do the trick.
Edit: it tells me that cast is an undeclared identifier and that I can not use <AOSMNodeActor> as it is illegal.
I did exactly as you have there, and still no line draw between items in the array, now this array is initialized to zero at the start of running the editor and I add my own items to the array afterwards so I am wondering if that might cause the lines not to show.
You’ve created an array of 0 elements with unitialized data. You haven’t added any nodes for the debug loop to run through, so it will crash because the data is null.
Start writing your code to add the real nodes into the TArray (using add or addunique). I cant believe you’d want them hard coded, so I assume you are building up to a system that allows you to add nodes on into a map.
Thanks for your help Geeky, I have been able to get the DrawDebugLines function to work with preset vectors, and was able to figure out how to load an instance of my NodeActor into my array at begin play, however I would like to load the array in the engine as soon as the WayActor is is placed in the editor viewport.