Hello everyone,
I know this topic has been already treated, but I’m stuck on the simple task of spawning an Actor class (APickup derived from AActor) and replicate it.
The Character spawns the Pickup actor as Server, but it does appear only on the Server. The Clients can’t see the Pickup actor, but when they spawn it only the Server can see it.
I’ve done several searches on the UE forum and online, it seems to me that what I’m doing everything correct, I can’t understand why Pickup Actor isn’t replicated on clients, or at least why i cant see it, even if it’s spawned from the server.
Can anyone suggest me what I should check or if I’m missing something?
Everything it’s working and get replicated as expected, except for the spawned Pickup actor… I can even see the client moving (from the server viewport) and picking up the “invisible” actor (invisible for the client).
The same pickup actor is showned on both client and server only if the actor has been dragged in the level from the editor.
The following screenshot shows on the left the Server, on the right the Client, on the Server the pickup actor is visible (and correctly initialized):
Does the item mesh happen to have bOnlyOwnerSee = true?
I meant if you create a blueprint child of the actor and spawn it (simulating the drop function), will it be visible? (check just the replicates and net load on client settings).
I made a Pickup BP child class and tried to spawn it, but it still not showing on clients.
if replicates and net load are forced in the constructor, shouldn’t be the same for child classes?
Since the Mesh is set in the BeginPlay by calling the Initialize function, does the mesh get set also on clients?
Since distance is not an issue (always relevant), then my guess is the actor is replicated, but I’m guessing you are setting the mesh and other properties inside InitializeDrop(), which are not replicated, and you have to handle that
You can check if that’s the case by checking your outliner, and seeing if the actor is there on clients. You can change your outliner to show a different world’s actors by clicking on the Cogwheel → Choose World. That way you can switch between the server and the clients’ worlds to see the actors in each of them
You have to work with replicated variables to initialize the actor on your clients as well. If you replicate the ItemBase property (probably with COND_InitialOnly), then on begin play of your actor you can do the initialization on the clients as well. You should probably also replicate the amount, if you want the clients to see it on their end
I can the see the spawned pickup in the outliner, choosign both client and server world.
I guess the problem is that, like you suggested, I’m not setting properly the Mesh on initialization.
But as @PREDALIEN suggested, i printed the Pickup BeginPlay function and I see it being executed on both client and server. InitializeDrop is a similar method for initilizing from an already existing data (while in the BeginPlay i call the Initialize method which get the data from a datatable), maybe InitializeDrop is not replicating, but at least the Initialize function shouldn’t work?
BeginPlay will get called on both, that’s expected
But if your client’s version of the actor doesn’t know what item was dropped (it can only know through a replicated variable), then it can’t know what values to pull from the data table
Functions are not replicated by default, and you don’t want to handle this with an RPC, since it’s wrong and won’t work for late joiners, or for people that come into replication range of the dropped actor later, should you ever disable Always Relevant (which you should)
Ok I’m starting to see the problem here, I need to call a SpawnActorDeferred I guess, then I should be able to set the replicated property that i need before the BeginPlay (does SpawnActorDeferred let me do that?)
I solved it, as @zeaf suggested I replicated the properties I need to initialize the actor, then with the SpawnActorDeferred I set those property , finally the BeginPlay of the Pickup actor properly initialize the data (and the mesh) on both Server and Client.
Thanks for the help!