Passing reference of actor to Run-On-Server event isn't working

Hi,

I’m building a multi-player game and came across an issue.

In my Event BeginPlay I do the following:

Then later I pass the reference for ‘DefenceToPlaceRef’ into the Run On Server function:

The output I get is as follows:

345348-pie.png

My understanding is that BeginPlay is called on each client who has a copy of this Character actor which is why there’s 4 actors spawned (see last screenshot above). I would expect then that for each client the DefenceToPlaceRef variable has a local copy of their spawned actor and when the owning client of the Character Actor passes their copy of DefenceToPlaceRef into the Place Defence on Server function, that the variable data would be available to the server, however, it currently shows as ‘Null’ when playing in editor (see last screenshot above).

The P_Test_Wall_2 Actor is set to replicate (inherited from it’s parent class).

After I removed AttachActorToComponent I can see that the result changes to the following once playing in the editor.

345361-pie-no-attachactortocomponent.png

My question is why does AttachActorToComponent stop the variable being passed in by reference and when AttachATC is removed allow both Server and Client to have reference to the same actor (see last screenshot output)?

Also just as an FYI, I’ve since changed the logic so that it only spawns the Wall actor on the server and replicated the DefenceToPlaceRef variable so that the issue no longer remains. This is just a question for my own understanding of why the variable was passing back null with my previous approach.

1 Like