- Home /
Question by
Pmatt · Nov 03, 2016 at 02:12 PM ·
networkingspriteanimator
Unity Lobby Networking - Change player RuntimeAnimatorController and sync?
I'm new to unity so any help would be greatly appreciated. I'm using the the unity Lobby manger in the Asset Store. I need to have two sprite characters in my game with their own settings. I've worked out how to change certain things such as my Layer and sync differences across the network.
The problem is whenever I try to sync the RuntimeAnimatorController all the settings I changed go blank.
Just some background before I show you the code: I'm using OnLobbyServerSceneLoadedForPlayer To set up each player's Settings depending on which character they want to play.
Below is the code I'm using to sync the settings:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class SyncPlayer : NetworkBehaviour {
// Var to sync
[SyncVar]private Vector3 syncPlayerScale;
[SyncVar]private string syncName;
[SyncVar]private int syncLayer;
[SyncVar]private int syncSortingOrder;
[SyncVar]private RuntimeAnimatorController syncRuntime;
// Use this for initialization
void Start () {
transmit_setup ();
// if is not isLocalPlayer then set sync's
if (!isLocalPlayer) {
gameObject.name = syncName;
gameObject.layer = syncLayer;
gameObject.GetComponent<SpriteRenderer> ().sortingOrder = syncSortingOrder;
gameObject.GetComponent<Animator> ().runtimeAnimatorController = syncRuntime;
}
}
// FixedUpdate is called at a Fixed Interval
void FixedUpdate () {
transmit ();
// if is not isLocalPlayer then set sync's
if (!isLocalPlayer) {
transform.localScale = syncPlayerScale;
}
}
[Command]
void CmdSync( Vector3 scale ) {
syncPlayerScale = scale;
}
[Client]
void transmit () {
// Send localScale if this is the local player
if (isLocalPlayer) {
CmdSync (
this.transform.localScale
);
}
}
[Command]
void CmdSync_setup(
string name
, int Layer
, int SortingOrder
, RuntimeAnimatorController Runtime
) {
syncName = name;
syncLayer = Layer;
syncSortingOrder = SortingOrder;
syncRuntime = Runtime;
}
[Client]
void transmit_setup () {
// Send setting if this is the local player
if (isLocalPlayer) {
CmdSync_setup (
gameObject.name
, gameObject.layer
, gameObject.GetComponent<SpriteRenderer> ().sortingOrder
, gameObject.GetComponent<Animator> ().runtimeAnimatorController
);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612095926im_/https://answers.unity.com/themes/thub/images/avi.jpg)