Multiplayer - Null object reference from server to client RPC

Working on my multiplayer spell system for an RPG game.

I’m running into an issue where I create a BP_Skill object on server side (replicates and always relevant), and I need to pass this reference to the client in order to set up some HUD-related things.

However, On the client-side function, the BP_Skill object is not found.
I have tested this with a struct (Skill Info), which gets passed properly to client.

Any help would be greatly appreciated!

1 Like

This is a fun one!

I tested this by passing an array of actor references to a “run on server” event that subsequently called “owning client” event and passed that array as well. Everything worked. There is no problem with putting references into arrays and passing them around with UE4 multiplayer framework.

Your problem is different. Notice how you spawn the actor, put their reference in the array and immediately pass it to an event. Well, the problem is that you are doing it so fast that the fact of spawning the actor did not get replicated to the client yet. So your arrays contain references of actors whose NetworksGUIDs are not yet known to the client.

The reason that structs are working is that they are simple data, they get passed by value. Actors however dont have that luxury.

Try adding a delay or calling that event a bit later in another manner (once you verify all clients have your actors)

Good luck

1 Like

Glad to help. Good luck with your project.

You’re an absolute life saver. I couldn’t figure it out for days because I didn’t expect there to be a spawn/delay issue.

Everything works as intended now after fitting in a 0.5s delay before passing the array of actors! Cheers!

Hey dudes!

Sorry for resurrecting this thread
but… isn’t setting a manual delay…
error prone? I mean, you can’t
guarantee that the variable will be
replicated in time to the client,
regardless of the amount you put.

yes. but in some cases if your delay is just small enough you can but your risking a lot on perfect ping. there are other ways around this. The problem is the method being used.

Hey dudes!

Sorry for resurrecting this thread but… isn’t setting a manual delay… error prone? I mean, you can’t guarantee that the variable will be replicated in time to the client, regardless of the amount you put.

Yes it is, which is why I also suggested the second way to handle it (verify all clients have your actors before executing an action that requires said actors). Can be done through either having a loop running with delay on client side checking the required actors for null and finally executing the follow-up action when it is not null, OR if the action HAS to be executed by server then server getting a callback from clients confirming creation of actors, and subsequent server initiated action.

Or maybe RepNotify? That’s what I’m using–pretty consistent. Just to sum up with your answers.

I had error even with repnotify, i ran out of options and redesign my code. It somehow worked