Are local variables replicated automatically if the fucntion is called on the server?

I’ve been using standard replicated variables so far, but trying to tidy up my blueprints and functions, so I was wondering if local variables are automatically replicated so long as the function is called on the server.


If you mean local variables, as in that variable exists only in a local scope (like a function) the answer is no.

This type of variable only exists while the function is called and since the function is not even called on the clients, the variable doesn’t even exist on the clients. Not even talking about replication or not.

Thanks for replying.

Just so I’m sure, the event below is in my controller and it executes on the server. When I call the event, the Item and Amount variables are replicaed but in the “add item” function, I use local variables to keep things tidy and judging from your 1st answer, I shouldn’t use local variables, I should use standard replicated ones?

Hope that makes sense.

Thanks again.

I’m just guessing here
but I would assume your Add Item Function is adding those items to a local array in the function?

If that is the case it will not work on either the server or the client, because the local variable only exists during the execution of the function. Meaning every time this is called on the server a new array is created your item is added to that and at the end of the execution of the function the array is destroyed.
This will result in your items not being stored anywhere.

If you want to separate code into different parts the way to go would be components and structs