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"

How can I tell when an actor has been replicated?

I have a function in my AGameMode class which spawns a number of replicated actors and then calls a NetMulticast function which references those actors. If I run this function, it works fine on the server but fails on the clients as all the AActor* for the spawned actors are NULL. I can make it work by, after spawning the actors, not directly calling the NetMulticast function, but instead starting a timer to call the NetMulticast function after a few seconds. I assume this is necessary as it may take some time to replicate the actors to all the clients. However, I need this delay to be as short as possible. What is the best way to tell when an actor has been replicated? Is it better to do this on the server or client?

Product Version: Not Selected
Tags:
more ▼

asked Feb 27 '15 at 03:49 AM in C++ Programming

avatar image

Lambda42
33 7 10 15

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

2 answers: sort voted first

When an actor is replicated to the client it is getting spawned on the client side with the same NetIndex (this is a unique identifier of that Actor in your network play session). So knowing that they will all spawn sometime when that happens the BeginPlay method is called, using that method will give you the exact time when the replicated actors are entering the playground. Knowing the role of the actor is important to act accordingly, the available roles are outlined here: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Engine/ENetRole/index.html. You can also use the net mode to check if the BeginPlay is called on the client side or not.

To check if you are in the server you normally check the role to match the highest one which is ROLE_Authority.

If you have more questions just add a comment ^^ I'll be glad to help you out :D

Cheers, Moss

more ▼

answered Feb 27 '15 at 08:36 AM

avatar image

Moss
6.4k 127 98 606

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

I have a solution that seems to be working. I changed the AActor* from UPROPERTY(Replicated) to UPROPERTY(ReplicatedUsing = ...) and in the OnRep function I set a boolean flag. As far as I can tell the AActor* are not replicated until after the actors themselves (which makes sense), so I just have the client check to see if this flag is set in the NetMulticast function and if it isn't I start a very short timer to call the function again. Once the function actually runs, I clear the flag. Seems to be working so far.

more ▼

answered Mar 03 '15 at 04:10 AM

avatar image

Lambda42
33 7 10 15

(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