How to drag TargetPoint to the panel?

Hello,

I don’t understand why does the complier not allow me to put object of TargetPoint in a TArray.

This is my code:

#include "CoreMinimal.h"
#include "AIController.h"
#include "GuardAIController.generated.h"

/**
 * 
 */
class ATargetPoint;
UCLASS()
class FPSGAME_API AGuardAIController : public AAIController
{
	GENERATED_BODY()

public:
	AGuardAIController();

	void OnMoveCompleted(FAIRequestID RequestID, const FPathFollowingResult& Result) override;
	
protected:
	void BeginPlay() override;

private:
	UPROPERTY(EditDefaultsOnly, Category = "TargetPoints")
	TArray<ATargetPoint> TargetPoints;

	int CurrentTarget;
	ATargetPoint* GetNextPoint();

	void WalkToNextPoint();
};

and cpp:

#include "GuardAIController.h"
#include "Engine/TargetPoint.h"

AGuardAIController::AGuardAIController() 
{

}

void AGuardAIController::OnMoveCompleted(FAIRequestID RequestID, const FPathFollowingResult & Result)
{
	Super::OnMoveCompleted(RequestID, Result);
	WalkToNextPoint();
}

void AGuardAIController::BeginPlay()
{
	CurrentTarget = -1;
	WalkToNextPoint();
}

ATargetPoint* AGuardAIController::AGuardAIController::GetNextPoint()
{
	if (CurrentTarget + 1 < TargetPoints.Num()) {
		CurrentTarget = CurrentTarget + 1;
		return &TargetPoints[CurrentTarget + 1];
	}
	else {
		CurrentTarget = 0;
		return &TargetPoints[0];
	}
}

void AGuardAIController::WalkToNextPoint()
{
	MoveToActor(Cast<AActor>(GetNextPoint()));
}

In general, I just want to make my character walk through each targetPoint. Now I face a problem. I don’t know how can I drag on target points into the slot of the editor. At the beginning, I use type “ATargetPoint*” instead of “ATargetPoint” for my TArray. I can complie it successfully and the slots shown on the pannel, However, After putting the target points into the slots, they are still showing “None”. I think may the slot is for type TargetPoint* but not TargetPoint? So I change the TArray to TArray. However, This time I just can’t complie the program.

I am new to C++ and Unreal. I really appreciate any help.

Using a pointer is the right way to do it, you should however close the editor and rebuild the solution from Visual Studio (or whichever IDE/Compiler you use)

Changing UProperties is extremely buggy with hot reload and I’ve had many issues running into null pointers (None) while using hot reload, which I eventually stopped using completely because it simply sucks too much.

You also seem to have a syntax error in line 21 of the cpp ( ATargetPoint* AGuardAIController::AGuardAIController::GetNextPoint())

And also just as a sidenote the upcasting you’re doing on line 34 of the cpp isn’t necessary (MoveToActor(Cast<AActor>(GetNextPoint()));), if your ATargetPoint is an actor (which it probably is since it starts with A) then the cast will always succeed and isn’t necessary since ATargetPoint already is an Actor, and if it isn’t an actor then the cast is going to return a nullptr and not warn you or anything.

Edit: I just talked that at some point no matter what I tried to do it was still not working and the "None"s persisted, what I suggest at this point if this happens to you is to make a new blueprint completely and derivate it from the same base cpp class, copy everything you had changed on it and then remove the old one completely, it was the only way I found after the blueprint was already corrupted sadly, if you know if any other way please do share it!

I really hope all of these blueprint corruption issues get fixed soon…

Thank you very much. I rebuild my project through my Visual Studio. But I still face the same problem. I upload a fig. “无” means “None”.

277543-cannotdrag.gif

. Do you have any ideas?

Oh yeah, at some point no matter what I tried to do it was still not working and the "None"s persisted, what I suggest at this point is to make a new blueprint completely and derivate it from the same base cpp class, copy everything you had changed on it and then remove the old one completely, it was the only way I found after the blueprint was already corrupted sadly.

I will edit the main post and add this part to it, please keep me updated and if this solves your problem please consider marking the issue as resolved!

Ah, It still doesn’t work…