I’m designing a multiplayer system and set most of my objects to replicate.
I have a treasure chest that can be blown up and replaced with pickup coins.
When the character moves within a certain distance of the chest, I piece of text pops up prompting the user to press a button to interact. That text is a component of the chest blueprint.
I have the chest set to replicate which works great. However, I want the text to only be displayed to the people currently within range. If I’m close to a chest then that text should appear right above the chest from my perspective. Other players watching me should not see that text. They should also be able to walk up to that chest and see their own text note independet of me.
Basically, I want everything about the chest to replicate EXCEPT for the text component. That should be unique to each individual player.
I’ve seen this question asked a few times in the community and it is also mentioned in the UE4 documentation but I can’t get it to work for some reason. I am supposed to use the “Set Is Replicated” method on the text component. I’ve tried attaching this command to multiple places but I can’t get it to work.
What am I doing wrong?
How should this function be used to achieve the desired results?
The functionality you are asking for works almost automatically out of the box.
Make sure that the text popup is of course hidden in game by default, then on the client side you need to check for proximity, since this is a purely cosmetic activity, you can use an overlap event to be your trigger.
When the BeginOverlap event is triggered you should place a CanExecuteCosmeticEvents node immediately after to parse out who is and is not a client capable of displaying text to their screen. Set your text to no longer hidden in game and you will see your text only on the client that sent the overlap event to itself.
You can pair this an EndOverlap event to set the text hidden in game again for a simple show/hide effect on proximity!
A few things might be wrong here, so I will cover the likely ones and we can figure out what is missing. First, set a print string with a different message for each branch to be sure each branch is being hit, one could say ‘client’ and the other ‘server’. Next make sure that you are discerning between ‘hidden in game’ and ‘visible’ as they are two different booleans and setting the right one is necessary.
I mocked up a super simple version of what you are looking for for you to learn from. You will note I am filtering out everything but pawns for my overlap events, you don’t necessarily have to do this, but I find it useful.
I’ve mimicked your setup as best I could. The text does not appear or disappear as it should and I get the following output when entering the trigger box…
It is strange that your server is reporting that it can execute cosmetic events. It may be a quirk of a listen server, but should not cause any immediate undesired behavior. This still leaves us with the primary problem though. Is your text visible in your Blueprint Viewport? It should have Visible and Hidden in Game checked by default for this particular setup to work. It also should of course have some text to display.
The text component is named “Command” so that’s what I’m trying to display. When I use the Set Visibility method, it works find as far as showing the text. It doesn’t seem to be doing that with the current setup.
Alright, so I figured out why the text wasn’t showing. I had to go to the component settings check the “visible” and “hidden in game” values to make them true. Once I did that, it returned to its original functionality. It works fine but it can still be seen by both the server and the client. I am also getting the same print string values.
Yes. It appears in the game world of both the client and the server regardless of how close the other character is. The text is made to appear directly on top of the chest when approached and the client can see that happening with the server even though the client player is remaining still.
I did a bit more digging into this and asked a friend of mine, as I do not deal with listen servers often. I have tested this method on a listen server along with a few others and it seems to be getting the best results.