Download

No owning connection for actor. Function will not be processed.

I have a new class derived from AActor and I want it to have variables that are replicated, like a Lever that’s on or off.

I’ve read this article, and I understand that the general gist, that an Actor needs an owning connection.
https://dawnarc.com/2017/09/ue4no-ow…-be-processed/

What’s the kosher way to do this? I’m trying the following, but no avail:

AMyCharacter.cpp


void AMyCharacter::Interact()
{
*   [bla bla bla]*

    if (GetWorld()->LineTraceSingleByObjectType(
        OutHit,
        Start,
        End,
        FCollisionObjectQueryParams(ECollisionChannel::ECC_WorldStatic),
        TraceParams))
    {
        AActor* HitActor = OutHit.GetActor();

        ABaseElement* HitElement = Cast<ABaseElement>(HitActor);

        if (HitElement)
        {
**            HitElement->PlayerInput(GetOwner());**
        }
    }
}

ABaseElement.cpp


void ABaseElement::Server_PlayerInput_Implementation(AActor* MyOwner)
{
    PlayerInput(MyOwner);
}

void ABaseElement::PlayerInput(AActor* MyOwner)
{
    SetOwner(MyOwner);

    if (GetOwner()->GetLocalRole() == ROLE_Authority)
    {
*       [bla bla bla]*
    }
    else
    {
        Server_PlayerInput(MyOwner);
    }
}

This doesn’t feel right. I’ve tried using [FONT=courier new]if (GetLocalRole() == ROLE_Authority) and I’ve tried using [FONT=courier new]HitElement->PlayerInput(this) instead, but nothing seems to work.

Any suggestions for how this is usually handled?

I solved it by making the Interact() function check for authority, not the PlayerInput()

AMyCharacter.cpp


void AMyCharacter::Server_Interact_Implementation()
{
    Interact();
}

void AMyCharacter::Interact()
{
    if (HasAuthority())
    {
*       [bla bla bla]*

        if (GetWorld()->LineTraceSingleByObjectType(
            OutHit,
            Start,
            End,
            FCollisionObjectQueryParams(ECollisionChannel::ECC_WorldStatic),
            TraceParams))
        {
            AActor* HitActor = OutHit.GetActor();

            ABaseElement* HitElement = Cast<ABaseElement>(HitActor);

            if (HitElement)
            {
**                HitElement->PlayerInput();**
            }
        }
    }
    else
    {
        Server_Interact();
    }
}

ABaseElement.cpp


void ABaseElement::PlayerInput()
{
*   [bla bla bla]*
}