You'll probably be very disappointed to hear that...
nodes can not be passes through RPC :(
First you will need to send data necessary to create a new node. In my code it's this:
remote func insertUnit(unitFilename, path, unitName):
var unit = load(unitFilename).instance()
unit.set_name(unitName)
get_node(path).add_child( unit )
unitFilename is a path to .tscn file, path is a path in scene tree, name is a name of a node.
After a unit is created on client's game server calls this function of my Unit.gd script:
func sendToClient(clientId):
var unitData = {
position = get_position(),
nameLabelText = get_node(UnitNameLabel).get_text()
}
rpc_id(clientId, "copyUnit", unitData)
This is a function (also in Unit.gd) that will be called at client's side
remote func copyUnit(unitData):
set_position(unitData.position)
get_node(UnitNameLabel).text = unitData.nameLabelText
it initializes a unit that was created via insertUnit
before.
And here is a function that sends all units from server to a client:
func sendToClient(clientId):
var units = self.get_children()
for unit in units:
var unitFilename = unit.get_filename()
var path = get_path()
rpc_id(clientId, "insertUnit", unitFilename, path, unit.get_name())
unit.sendToClient(clientId)