FindComponentByClass runs twice every time

Do you know why this code is run twice?


void ADoor::BeginPlay()
{
	Super::BeginPlay();

	UpdateFunctionFloat.BindDynamic(this, &ADoor::UpdateTimelineComp);

	if (DoorTimelineFloatCurve)
	{
		UE_LOG(LogTemp, Warning, TEXT("[ ADoor::BeginPlay() ] : AddInterpFloat"));

		DoorTimelineComp->AddInterpFloat(DoorTimelineFloatCurve, UpdateFunctionFloat);
	}

	if (DoorLever)
	{
		UDoorInteractionComponent* InteractionComp = 
			DoorLever->FindComponentByClass<UDoorInteractionComponent>();

		if (InteractionComp)
		{
			UE_LOG(LogTemp, Warning, TEXT("[ ADoor::BeginPlay() ] : Get Interaction Component"));

			InteractionComp->OnInteraction.BindUObject(this, &ADoor::HandleOnInteraction);
		}
	}
		
}

I get this on the Output log:


LogTemp: Warning: [ ADoor::BeginPlay() ] : AddInterpFloat
LogTemp: Warning: [ ADoor::BeginPlay() ] : Get Interaction Component
LogTemp: Warning: [ ADoor::BeginPlay() ] : Get Interaction Component

The UDoorInteractionComponent is:

UDoorInteractionComponent : public UActorComponent

It might be because it’s running on the client and the server. This could be a candidate for the switch has authority roles?

1 Like

Thanks. The problem was that there was to instances of the same object in the level.

1 Like