x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Multicast not firing

Hey guys!

I've got a small setup where player can apply a camo to their weapon. Since other clients need to see the Camo too, i've made a small multicast function that sets the players camo for that client, and all other clients:

 void AChatSystemCharacter::SetWeaponCamo_Implementation(UMaterial * Mat)
 {
 GunMesh->SetMaterial(0, Mat);
 }

Once a player picks up a camo paint, upon using it the following function is called:

 //Called when the player uses the paint on their gun. Applies a camo to the gun
 void AWeaponPaint::Use()
 {

 AChatSystemCharacter* Character = Cast<AChatSystemCharacter>(UGameplayStatics::GetPlayerCharacter(this, 0));

 //This is a Multicast that sets and updates the players weapon material for the player and all other clients
 Character->SetWeaponCamo(WeaponCamo);

 //This just destroys the WeaponPaint actor after use
 Super::Use();

 }


The problem is that the WeaponCamo actor cannot call the Multicast function. It will be called on the local client, but won't get called on the other clients too, which is what a Multicast is supposed to do.

Anyone know what is happening? I have a feeling it is due to Ownership, but not sure what the solution is here.

Thanks everyone!

Product Version: UE 4.13
Tags:
more ▼

asked Jan 12 '17 at 04:49 AM in C++ Programming

avatar image

Denzel Jerry
27 3 6 9

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

So there are two common patterns to follow for multiplayer programming:

Have the client execute a Run At Server RPC to get from the Client to the Server. Then run a Multicast RPC on the server to replicate an event to all clients.

This method is good for temporal things. Things that happen, but then disappear, such as particle effects and animation montages.

The second pattern is to have the client execute a Run At Server RPC to get from the Client to the Server. Then have the Server change the value of a Rep Notify variable. Then when the variable value is replicated back to the Client, an OnRepNotify function is called on the client to allow you to change whatever it is you need to change on the client.

The second pattern is much better for permanent changes because unlike the multicast it will maintain state. I think in your case since you want the camo to stay set for more than just a few seconds,you probably want to go with the second pattern. From your code I can't tell if you are missing the initial Run At Server RPC to get from the Client to the Server. If so, then that is probably why your multicast isn't working. But even if you get it to appear like it is working with a Multicast, I have a feeling it will work intermittently until you switch to a Rep Notify variable instead.

If you have any questions about the difference between the two, take a look at this video on Network Relevancy that explains the difference between Multicast and Rep Notify:

https://www.youtube.com/watch?v=6w8_eC5qlSs

more ▼

answered Jan 12 '17 at 05:33 AM

avatar image

Dartanlla
2.6k 61 26 281

avatar image Denzel Jerry Jan 12 '17 at 07:14 AM

Thanks for the info. Quick question - is a RepNotify executed on all clients like a NetMulticast?

avatar image Dartanlla Jan 12 '17 at 02:11 PM

Yes, RepNotify is executed on all clients that have the object.

Another thing you will want to look into for multiplayer programming is which objects exist on which clients. For example, every client has a copy of every Character object, but the PlayerController object is only on the client that owns it.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question