Multiple Network Owners?

How can I add multiple Owners to a replicated actor?

For example, I’m building an Item Container that I want multiple players to access.

Currently, I need to set the Container’s Network Owner as the Interacting player in order for replicated functions on server to be called (and ensure items can move around properly). Because of this, only one player can interact with it properly.

Is there a work around to this?

Thanks!

I might be slightly off on this… but you don’t have to own the actor in order to be able to replicate or interact with it. In this case, the server should probably own the actual container and allow other clients to interact with it.

1 Like

An actor cannot have multiple network owners.

But just because you don’t own the actor, doesn’t mean you can’t interact with it and reference it over the network. The common solution to this problem is to build a generic “interaction” system where the player pawn/controller has their own interaction component, and the RPCs take references to other actors.

A simple psuedo-code example to give you an idea:

UInteractionComponent

UFUNCTION(Server, Reliable)
void Server_InteractWith(AActor* Target, const FGameplayTag Type);
void Server_InteractWith_Implementation(AActor* Target, const FGameplayTag Type)
{
	if (CanInteractWith(Target))
	{
		// Do interaction
		Cast<IInteractable>(Target)->HandleInteraction(this, Type);
	}
}

Interaction Interface

class IInterface
{
	virtual void HandleInteraction(UInteractionComponent* Source, FGameplayTag Type);
}

There are other ways of doing it, but this is very common :slight_smile:

1 Like

Yes! that worked.

I created a transfer function called from the Player’s Inventory to handle moving items around between it and the Container (Owned by the Server).

Kind of unrelated, but I ran into issues the past week with then updating the UI provided by the Server-Owned Container, since updates to the UI are called from an OnRep function tied to the Inventory Array. It would not update for 2 clients interacting with the container at the same in the PIE. However, turning “Run Under One Process” off in the Editor Settings fixed this. Hopefully this can help someone in a similar situation with me.