Best way to have a PlayerCharacter interact with Pickup Actor (multiplayer C++)?

Hi everyone!

First of all an excuse from me about the list of questions!
I’ve been busy for days, looking through documentation, watching courses, but in my head it still hasn’t clicked unfortunately.

A bit of stage setting:

In a Listen server multiplayer game, I’ld like to have the PlayerCharacter go up to a Pickup Actor and then the name of the Pickup item appears above it.
Other players don’t get to see this text when they’re not close to it.

In my head there are 2 options to do this:

  1. The PlayerCharacter has a SphereCollision in front of him.
    When this Sphere collides with a ‘pickup’ collision box, it’ll trigger an Overlap event.
    Then from here the pickup’s Visibility will be enabled.

  2. Like in the Multiplayer C++ Unreal course:
    Let the pickup in the tick function search for overlapping actors of type ‘PlayerCharacter’.
    If one is found, put the Visibility to true, to show the text.

Which one of these would be best performance wise?

For me the tick function seems the least performant.
There will also be quite a few of pickup actors around the map.

I also have questions about the first option

In this option, the player has a sphere collision that’ll trigger an overlap event in case it hit’s a ‘pickup’ collision box. I’m trying to get this to work, but my mind is still scrambled about Ownership & Replication & RPC’s.

What needs to happen inside this OverlapEvent to only enable the visibility of the pickup name for the character that actually overlaps with the collision box? Since the game is running on a listen server, I need some way to only set the visibility of the Pickup to show it’s widget. So I don’t think a Replicated bShowText is what I need here.

The Pickup Actor’s are placed in the level from the content browser.
They don’t belong to a PlayerCharacter.
I’m setting the Overlaps in BeginPlay of the PlayerCharacter without a filter (no HasAuthority(), since the Host also is the player here).

My result now is that for the server it works, but when a client goes to a pickup actor, the text shows up for … the server player (Host), not the client, even if the server player is not there. I have a log inside the BeginOverlap function. This log is printed #players_connected_to_the_server times and I don’t know how. I’ld expect it’ll only trigger for the actual player that is overlapping, not for all players.

My current code in TriggerBeginOverlaps:

UE_LOG(LogTemp, Warning, TEXT("Begin Overlap!!!"));
bool ImplementsInterface = UKismetSystemLibrary::DoesImplementInterface(OtherActor, UInteractableActorInterface::StaticClass());

if (ImplementsInterface){
	APickup* pickup = Cast<APickup>(OtherActor);
	if(pickup){
		pickup->SetItemNameVisibility(true);
	}
}

What am I missing to make this possible?
My guess is something about the ownership, but I don’t have a clue on what I should filter…

And to end … another question

Currently my Pickup Actor has a WidgetComponent, where the Widget itself is a C++ Userwidget I created with a TextBlock containing the Pickup Name.

Would instead of using a widget, a Text Render be better?

Using a WidgetComponent I can make the Widget in 3D space, just like a Text Render.
What are the advantages / disadvantages of using the one over the other?


Big thanks to anyone that could help me!

-Nick

Hi Nick,
Welcome to the community.
Just checking but is this related to the Co-op Multiplayer course we offer? This covers pickups.

Generally we can’t help with questions outside of courses (we try when we can) but the community is primarily for supporting these courses and showcasing work.

Hi,

Well I think the first question does apply to the course actually.
The course teaches overlaps using the tick function.

My question is if the other option would be better performance wise. I’ve seen similar questions on the C++ course videos.

The course gives a great introduction to multiplayer Unreal. The closest to my Pickup example, would be the Collectable Key in the course, which uses, like I mentioned, the tick function to constantly check for Player character overlaps.

The rest of the questions might not entirely overlap with the course content.

In the beginning of every GameDev course, the viewer is said to don’t hesitate about asking questions.

Well, for once I just thought about giving it a shot myself.

I understand now that this forum is ment only for “customer support if stuck with the course”.

A bit of a shame, since I often end up on GameDev forum with useful posts on the forum that we’re allowed/ not removed and not mentioned in the course.

Have a Nice day!

Hi Nick,
Generally as TAs our job is to ensure students get to the end of the course. We do help and the discord is actually the best place to seek help outside of the course. As a TA I have a day job which is 40hr+ a week plus helping here (I spend maybe 10 hours a week answering questions and QAing new materials) and a family so I have to limit what I can help with and the same applies to the majority of the team. We also get a lot of questions where users ask us about other courses not ours so we have to check. If the question had been tagged with the lecture ID then we know it is course related or at least a student question. I just wanted to clear this up.

Regarding performance, tick or overlap. I’ve had numerous discussions about this and the answer is there is little between the two.

Why? Basically the overlaps run on a tick type process detecting when 2 objects overlap. Arguably overlap offers a better approach but it isn’t more or less performant, that is all dependant on how complex your code is. I’ve also heard people going tick is not best practice. Best practice is actually subjective. I say whatever works for you. In fact, it is possible that tick might be more performant as overlap events will require tracking of the object boundaries to perform the checks.

Text render vs widget. Again, either but there’s advantage to a widget in that you can use outlined text or anything else you want. The text renderer is convenient because you can throw it onto your blueprint as a component but the end result of a widget is better. You can also animate if you need to.

Effects like text and particles are client so to get it to show you need to set up a system again like in the course (section 2 multiplayer fundamentals towards the end)

Why it shows on the “server” is there is a client also running on the server and it gets updated.

I hope this helps.

1 Like

Hi Beegeedee!

First of all I completely understand what you said before, no hard feelings what so ever!

I assumed the forum really was more “Open” in a way, meaning other students / visitors who come over here also read these questions and try there best to help if possible!
I definitely didn’t expect an actual GameDev teacher (Or volunteer!) to spend time on me to answer!
I just wanted to ask my question at the community as a whole.

GameDev really is awesome, and you definitely are a part of it.

Thank you very much!

1 Like

We are actually moving to a new Q&A system for answering questions related to course materials. The forums themselves, not sure what is going to happen but the Discord is where all the action is and you’ll get peer support there as well. I occasionally pop in and help out too when I can.

If I were being completely honest, I’d love to do this full time but I have bills to pay.

Good luck!

1 Like

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

Privacy & Terms