- Home /
Is there any way to send gameobjects over the network? (Mirror)
I have a pathfinding script for my 2D multiplayer game (using Mirror) that returns available/walkable tiles in a list. The 'tiles' stored in this list are game objects which are generated over my grid in the scene. I have a function that makes a call to the server in order to move my character with a network transform.. That function checks the index of the list to see which tile to move to (notice path[0]
referenced in this function. The index is a game object which is stored in my list of walkable tiles).
If I try to use this function I'll get error ArgumentOutOfRangeException
.. which I've gathered is because my 'tiles' are not actually being sent to the server.
From what I've read on other posts, it doesn't seem possible to send game objects like this over the network. But I also haven't found a solid answer on this anywhere yet. Seeing as how my pathfinder needs to check for game objects on the scene, I need to find a way to make this work. Should I just scrap this approach to my pathfinder using game objects?
My movement function:
[Command]
public void CmdMoveAlongPath()
{
var step = moveSpeed * Time.deltaTime;
var zIndex = path[0].transform.position.z;
character.transform.position = Vector2.MoveTowards(character.transform.position,
path[0].transform.position, step);
character.transform.position = new Vector3(character.transform.position.x, character.transform.position.y, zIndex);
if (Vector2.Distance(character.transform.position, path[0].transform.position) < 0.0001f)
{
PositionCharacterOnTile(path[0]);
path.RemoveAt(0);
}
}
Answer by VanToRiaXVII · May 24 at 06:54 PM
I remember seeing a thread about a similar issue a while ago on the forums. TL;DR: The server has to spawn the object first and then it will tell the client to spawn locally.
Here's the link: https://forum.unity.com/threads/mirror-networking-instantiate-objects.1003656/
Your answer
![](https://koobas.hobune.stream/wayback/20220613060724im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I want to make a powerup with a an associated timer on the server side using mirror 1 Answer
How to network a game for two players? 0 Answers
Is it possible to not allow the in-game cursor through certain sprites? 1 Answer
Does Unity 2D tools generate atlas? 1 Answer
How do you create a sun/moon/lightning/raining effect in Unity 2D? 0 Answers