Hey,
i have tryed to make a derived class from UNavLinkCustomComponent to get an BlueprintSpawnableComponent
that i can use to have a SmartLink on an Actor. I know i can make a NavLinkProxy derived class to get the same Result, but i need to change the SnapRadius of the SmartLink and therefore i have tryed to change the GetLinkModifier() function of the UNavLinkCustomComponent class. With the changes of the GetLinkModifier() funktion i get the expected result. The SnapRadius sets correctly, but the the SmartLink can’t be used for pathfinding after level load. But the SmartLink will work fine if i build navigation (On next level load pathfinding still not working).
I used UnrealEngine version 4.12.5.
SmartLinkComponent.h file:
#pragma once
#include "AI/Navigation/NavLinkCustomComponent.h"
#include "SmartLinkComponent.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FSmartLinkReached, AActor*, MovingActor, const FVector&, DestinationPoint);
UCLASS(meta = (BlueprintSpawnableComponent))
class MYPROJECT_API USmartLinkComponent : public UNavLinkCustomComponent
{
GENERATED_BODY()
USmartLinkComponent(const FObjectInitializer& ObjectInitializer);
public:
UPROPERTY(BlueprintAssignable)
FSmartLinkReached OnSmartLinkReached;
UFUNCTION(BlueprintCallable, Category = "SmartLink")
virtual FNavigationLink GetLinkModifier() const;
virtual bool OnLinkMoveStarted(UPathFollowingComponent* PathComp, const FVector& DestPoint) override;
};
SmartLinkComponent.cpp file:
// Fill out your copyright notice in the Description page of Project Settings.
#include "CrazyZombies.h"
#include "Navigation/PathFollowingComponent.h"
#include "SmartLinkComponent.h"
USmartLinkComponent::USmartLinkComponent(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
}
FNavigationLink USmartLinkComponent::GetLinkModifier() const
{
FNavigationLink LinkMod = Super::GetLinkModifier();
LinkMod.SnapRadius = 8.0F;
return LinkMod;
}
bool USmartLinkComponent::OnLinkMoveStarted(UPathFollowingComponent* PathComp, const FVector& DestPoint)
{
bool IsBaseDelegateBound;
IsBaseDelegateBound = Super::OnLinkMoveStarted(PathComp, DestPoint);
AActor* PathOwner = PathComp->GetOwner();
AController* ControllerOwner = Cast<AController>(PathOwner);
if (ControllerOwner)
{
PathOwner = ControllerOwner->GetPawn();
}
if (OnSmartLinkReached.IsBound())
{
OnSmartLinkReached.Broadcast(PathOwner, DestPoint);
return true;
}
return IsBaseDelegateBound;
}