Mover Won't Function

After not getting a reply for 7 days, I have decided to try and fix the issue with my blueprints myself, I believed I had come to the solution to my issue, that was to create a child blueprint class of the BP_secret door, however, when I moved the trigger component of the child blueprint class to the statue, with the correct tags, the gate did not move, I made sure the mesh was set to movable, among other various things.

No matter what i do, it would appear i can not get the mover to move the component i attach it to

Could you show your code and blueprint please?


Mover.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "Mover.h"
#include "Math/UnrealMathUtility.h"

// Sets default values for this component's properties
UMover::UMover()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}


// Called when the game starts
void UMover::BeginPlay()
{
	Super::BeginPlay();

	OriginalLocation = GetOwner()->GetActorLocation();
}


// Called every frame
void UMover::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	if (ShouldMove)
	{
		FVector CurrentLocation = GetOwner()->GetActorLocation();
		FVector TargetLocation = OriginalLocation + MoveOffset;
		float Speed = FVector::Distance(OriginalLocation, TargetLocation) / MoveTime;

		FVector NewLocation = FMath::VInterpConstantTo(CurrentLocation, TargetLocation, DeltaTime, Speed);
		GetOwner()->SetActorLocation(NewLocation);
	}
	
}

void UMover::SetShouldMove(bool NewShouldMove)
{
	ShouldMove = NewShouldMove;
}

Mover.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Mover.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class CRYPTRAIDER_API UMover : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UMover();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

	void SetShouldMove(bool ShouldMove);

private:
	UPROPERTY(EditAnywhere)
	FVector MoveOffset;

	UPROPERTY(EditAnywhere)
	float MoveTime = 4;

	UPROPERTY(EditAnywhere)
	bool ShouldMove = false;

	FVector OriginalLocation;		
};

TriggerComponent.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "TriggerComponent.h"

UTriggerComponent::UTriggerComponent()
{
    PrimaryComponentTick.bCanEverTick = true;
}

void UTriggerComponent::BeginPlay()
{
	Super::BeginPlay();
}

void UTriggerComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

    if (Mover == nullptr)
    {
        return;
    }

    AActor* Actor = GetAcceptableActor();
    if (Actor != nullptr)
    {
        UPrimitiveComponent* Component = Cast<UPrimitiveComponent>(Actor->GetRootComponent());
        if (Component != nullptr)
        {
            Component->SetSimulatePhysics(false);
        }
        Actor->AttachToComponent(this, FAttachmentTransformRules::KeepWorldTransform);
        Mover->SetShouldMove(true);
    }
    else
    {
        Mover->SetShouldMove(false);
    }
}

void UTriggerComponent::SetMover(UMover* NewMover)
{
    Mover = NewMover;
}

AActor* UTriggerComponent::GetAcceptableActor() const
{
    TArray<AActor*> Actors;
    GetOverlappingActors(Actors);
    for (AActor* Actor : Actors)
    {
        bool HasAcceptableTag = Actor->ActorHasTag(AcceptableActorTag);
        bool IsGrabbed = Actor->ActorHasTag("Grabbed");
        if (HasAcceptableTag && !IsGrabbed)
        {
            return Actor;
        }
    }

    return nullptr;
}

TriggerCompoent.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/BoxComponent.h"
#include "Mover.h"
#include "TriggerComponent.generated.h"

/**
 * 
 */
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class CRYPTRAIDER_API UTriggerComponent : public UBoxComponent
{
	GENERATED_BODY()

public:
	UTriggerComponent();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

	UFUNCTION(BlueprintCallable)
	void SetMover(UMover* Mover);

private:
	UPROPERTY(EditAnywhere)
	FName AcceptableActorTag;

	UMover* Mover;

	AActor* GetAcceptableActor() const;
};

And the mover, actor, and tags?

they match perfectly.


And the mover’s details?


Everything seems to look okay. Have you tried logging in various places? E.g. are you getting an acceptable actor?

what do you mean by that?

Logs in places that will result in it not moving like so.

    if (Mover == nullptr)
    {
        UE_LOG(LogTemp, Warning, TEXT("Mover is null"))
        return;
    }

    AActor* Actor = GetAcceptableActor();
    if (Actor == nullptr)
    {
        UE_LOG(LogTemp, Warning, TEXT("didn't get an acceptable actor"))
    }
    else
    {
        UPrimitiveComponent* Component = Cast<UPrimitiveComponent>(Actor->GetRootComponent());
        // ...

To determine where it’s going wrong.

i can’t place this code anywhere, it says that “Mover” and “GetAcceptableActor” aren’t identified…

It’s from your code that you posted here

I’ve only added the logs. (and inverted the condition for the second if and added an else for what was already there).


the result, regardless of what’s in the trigger area

Now add logs in that function to see why it’s returning nullptr. What’s in the volume? Do they have the right tag? Are they not grabbed?

what do you mean by volume?

i can answer the other questions though.

yes, the tags are correct, it doesn’t matter if the actor is grabbed or not, the mover doesn’t move.

it will still give a nullptr

By volume I mean the collision volume of the trigger i.e. I mean doing this

AActor* UTriggerComponent::GetAcceptableActor() const
{
    TArray<AActor*> Actors;
    GetOverlappingActors(Actors);
    for (AActor* Actor : Actors)
    {
        bool HasAcceptableTag = Actor->ActorHasTag(AcceptableActorTag);
        bool IsGrabbed = Actor->ActorHasTag("Grabbed");

        UE_LOG(LogTemp, Warning, TEXT("%s:"), *Actor->GetName());
        UE_LOG(LogTemp, Warning, TEXT("\tHasTag: %s"), HasAcceptableTag ? TEXT("true") : TEXT("false"));
        UE_LOG(LogTemp, Warning, TEXT("\tIsGrabbed: %s"), IsGrabbed ? TEXT("true") : TEXT("false"));

        if (HasAcceptableTag && !IsGrabbed)
        {
            return Actor;
        }
    }

    return nullptr;
}

Then check everything is as it should be.


it stops

the ulogger stops logging the moment i grab the actor, however, it does have the grabbed tag.

That says it doesn’t have the right tag. What tag do you have on the trigger?


Unlock2, the exact same one on the statue

Privacy & Terms