I disabled it on a server method of the character when it grabs the object.
Here’s a snippet my character .h
UFUNCTION(Server, Reliable, WithValidation)
void ServerPickUpObject();
virtual void ServerPickUpObject_Implementation();
virtual bool ServerPickUpObject_Validate();
And here’s the snippet of the .cpp. The AGoldenCube is the object I want to grab. I did the same for the DropObject method.
void ACollectingGameCharacter::ServerPickUpObject_Implementation()
{
UWorld *World = GetWorld();
if (World)
{
const FName TraceTag("HoldingTrace");
World->DebugDrawTraceTag = TraceTag;
FCollisionQueryParams HoldingTraceQuery = FCollisionQueryParams(TraceTag, false, this);
FHitResult HoldingTraceResult(ForceInit);
FVector Start = CurrentCamera->GetComponentLocation();
FVector End = (CurrentCamera->GetForwardVector() * 600) + Start;
bool blocking = World->LineTraceSingleByChannel(HoldingTraceResult, Start, End, ECollisionChannel::ECC_Visibility, HoldingTraceQuery);
if (blocking && HoldingTraceResult.Component->IsSimulatingPhysics())
{
UPrimitiveComponent *ObjectToPick = HoldingTraceResult.GetComponent();
AActor* SomeActor = ObjectToPick->GetOwner();
AGoldenCube* GoldenCube = Cast<AGoldenCube>(SomeActor);
if (GoldenCube && !GoldenCube->GetIsHeld())
{
HandleComponent->GrabComponentAtLocation(ObjectToPick, NAME_None, ObjectToPick->GetComponentLocation());
HandleComponent->GetGrabbedComponent()->SetEnableGravity(false);
holdingObject = true;
GoldenCube->SetIsHeld(true);
GoldenCube->SetLastHolder(this);
}
}
}
}