TriggerActorCount increment by 2

Hi all, I noticed that when I trigger with one of the keys the ActivedTriggerCount increases by two and this thing allows me to trigger the transporter component earlier than expected.

Hi and welcome to the community.
Can you share the code associated (not screenshot if you can) and also of any blueprint that may be present.

Can you check your code against end of lecture as well please. Thanks.

Sorry in the end I had already solved it and didn’t delete the post. I had inserted one too many OnCollected.Broadcast(); at the end of my method OnRep_IsCollected()


#include "CollectableKey.h"
#include "CoopAdventureCharacter.h"
#include "Components/AudioComponent.h"
#include "Components/CapsuleComponent.h"
#include "Net/UnrealNetwork.h"

ACollectableKey::ACollectableKey()
{
	PrimaryActorTick.bCanEverTick = true;

	bReplicates=true;
	SetReplicateMovement(true);

	RootComp = CreateDefaultSubobject<USceneComponent>(TEXT("RootComp"));
	SetRootComponent(RootComp);

	Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
	Mesh->SetupAttachment(RootComp);
	Mesh->SetIsReplicated(true);  
	Mesh->SetCollisionProfileName(FName("OverlapAllDynamic"));

	CapsuleComp = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CapsuleComp"));
	CapsuleComp->SetupAttachment(RootComp);
	CapsuleComp->SetIsReplicated(true);
	CapsuleComp->SetCollisionProfileName(FName("OverlapAllDynamic"));
	CapsuleComp->SetCapsuleHalfHeight(150.0f);
	CapsuleComp->SetCapsuleRadius(100.0f);

	CollectAudio = CreateDefaultSubobject<UAudioComponent>(TEXT("CollectAudio"));
	CollectAudio->SetupAttachment(RootComp);
	CollectAudio->SetAutoActivate(false);

	RotationSpeed = 100.0f;

}

void ACollectableKey::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);
	DOREPLIFETIME(ACollectableKey, bIsCollected);
}

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

void ACollectableKey::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	if (HasAuthority())
	{
		Mesh->AddRelativeRotation(FRotator(0.0f, RotationSpeed * DeltaTime, 0.0f));
		
		TArray<AActor*> OverlappingActors;

		CapsuleComp->GetOverlappingActors(OverlappingActors, ACoopAdventureCharacter::StaticClass());

		if(OverlappingActors.Num() > 0)
		{
			if(!bIsCollected)
			{
				bIsCollected = true;
				OnRep_IsCollected(); 
			}
		}
		
	}
	
}

void ACollectableKey::OnRep_IsCollected()
{
	if (HasAuthority())
	{
		UE_LOG(LogTemp, Display, TEXT("OnRep_IsCollected called from SERVER"));
		if(bIsCollected)
		{
			OnCollected.Broadcast();
		}
	}
	else
	{
		UE_LOG(LogTemp, Display, TEXT("OnRep_IsCollected called from CLIENT")); 
	}

	Mesh->SetVisibility(!bIsCollected);
	CollectAudio->Play();

	if(bIsCollected)
	{
		if(KeyHoldRef)
		{
			KeyHoldRef->ActivateKeyMesh();
		}
	}

	//OnCollected.Broadcast();
	//the wrong call... 

}

1 Like

Glad you got it sorted.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms