How to handle local / player only components?

Hello,

I’m currently building an interaction system and have created an actor component for my player character which takes care of the line traces and adds outlines to the objects I hover over, which works well so far.

However, when I later tested the whole thing in multiplayer with 2 players, I noticed that my actor component is also replicated on the other player characters without having set it up that way.

The reason for this is probably that (from the Unreal documentation): ‘Static components are components that are created when the Actor is created. Static components do not need to be made to replicate to exist on clients; they exist by default.’

However, it does not say how to switch off this behaviour, of course I could now check in the BeginPlay event of my Actor Component with the help of the ‘Is Locally Controlled’ function whether the component is only executed in the local Actor and then deactivate or destroy it accordingly, but I’m wondering if this is the right way, especially because I can’t find anything on the internet about this topic.
At first I thought that there might be a way to define a component as “local only” or to switch off replication (even across unreal behavior with static components).

What I also wonder: The replication behaviour with ‘Static Components’ also means that the camera component of each player character is replicated, isn’t that unnecessary, why does someone else need to know about the other player’s camera or am I just thinking wrong?

Component that the character will always have should be added via the Add component option in the Components panel.


You have to account for all three proxies (Autonomous, Authority, Simulated) when you code for multiplayer. Use Get Local Role, Switch has Authority, Is Locally Controlled, Is Server in various combinations to handle which proxy can/cannot do x,y,z.

Spectator role can make use of the sims camera. You’ll also need to reference it to replicate some actions in a local environment. Traces utilize camera a lot.

2 Likes

Ah alright, then I create the components that are only local dynamically behind the “Is Locally Controlled” check and do not add them to the static components.

Thanks for your answer :slight_smile:

1 Like

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