Change visual state on received event in multiplayer


let me describe the context:

I have a multiplayer sports game, with a ball. This ball declares an event, when it’s owner changes.

Each character in the game owns a DecalComponent, which renders a colored circle on the floor. I created an instance material, so I can dynamically change the color of this circle, depending if the player has the ball in his hands or not. In the BeginPlay event, I make the character register to the event on the ball, and this is where the modification of the color of the decal happens.

In every case, the owner changed event is always correctly broadcated to every character in the game.


  • in a local game, the colors of the decal under the characters are correctly updated
  • in a multiplayer game when one client hosts the game, only the hosting client has updated colors
  • in a multiplayer game with a dedicated server, none of the clients have updated colors

Again, when I put a breakpoint in visual studio in ABBCharacter::OnBallOwnerChanged, it is triggered for every client, and I can see the code is actually correctly called. It’s just that visually, the decals still have the same color.

You can find below all the relevant code used for this case.

Thanks in advance

class ABBBall : public AActor
    DECLARE_EVENT_OneParam( ABBBall, FBallOwnerChangedEvent, const ABBCharacter & )
    FBallOwnerChangedEvent & OnBallOwnerChanged() { return OwnerChangedEvent; }

    FBallOwnerChangedEvent OwnerChangedEvent;

    void SetOwner(
        const class ABBCharacter & owner
        OwnerChangedEvent.Broadcast( owner );

class ABBCharacter : public ACharacter


    UPROPERTY( Category = Default, VisibleAnywhere )
    TSubobjectPtr< class UDecalComponent > DecalComponent;
    class UMaterialInstanceDynamic* DecalMaterial;


    virtual void BeginPlay() OVERRIDE
        Ball = GetWorld()->GetGameState< ABBGameState >()->Ball;

        check( Ball.IsValid() );
        Ball->OnBallOwnerChanged().AddUObject( this, &ABBCharacter::OnBallOwnerChanged );

    virtual void PostInitializeComponents() OVERRIDE

        if ( GetNetMode() != NM_DedicatedServer )
                * material_interface = DecalComponent->DecalMaterial;

            check( material_interface != NULL );

            DecalMaterial = UMaterialInstanceDynamic::Create( material_interface, this );
            DecalMaterial->SetVectorParameterValue( FName( TEXT( "BaseColorParameter" ) ), FLinearColor( 0.0, 1.0, 0.0, 1.0 ) );

            DecalComponent->SetDecalMaterial( DecalMaterial );


    void OnBallOwnerChanged( const ABBCharacter & ball_owner )
        if ( GetNetMode() != NM_DedicatedServer )
            if ( &ball_owner == this )
                DecalMaterial->SetVectorParameterValue( FName( TEXT( "BaseColorParameter" ) ), FLinearColor( 1.0, 0.0, 0.0, 1.0 ) );
                DecalMaterial->SetVectorParameterValue( FName( TEXT( "BaseColorParameter" ) ), FLinearColor( 0.0, 0.0, 1.0, 1.0 ) );

    TWeakObjectPtr< class ABBBall > Ball;

I found the error . If I have 2 players connected to a dedicated server, I only got the breakpoint 2 times, on the server.

What I did then was to use a boolean ItHasBall, which is replicated, and which I set in the OnBallOwnerChanged function of ABBCharacter.

And now it works :slight_smile: (for now)