Search Unity

syncRotationAxis can't be set from script

Discussion in 'Multiplayer' started by chanfort, Jan 25, 2016.

  1. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    I was trying to set syncRotationAxis through script while inside editor. I am doing this in a usual way:
    Code (CSharp):
    1. go.GetComponent<NetworkTransform>().syncRotationAxis = NetworkTransform.AxisSyncMode.AxisY;
    However, it bounces back and resets to XYZ. I am doing this on a prefab GameObject after calling
    Code (CSharp):
    1. UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>("Assets/myNetPrefab.prefab")
    which loads previously saved prefab. NetworkTransform component is being added directly on the loaded prefab after it has been loaded. However, I tried also to repeat this before prefab has been created, but there is no difference.
    Another thing which I tried was to change to AxisY on prefab in Awake() while in play mode (as I have saved its reference) as well as on instances. Both cases sometimes changes it to Y and sometimes it remains the same XYZ, however, the change is random.
    Other variables, like InterpolateMovement changes nicely while doing things this way.

    I looked at the source code in bitbucket and I noticed that in Init() function at line 68 there is default assignment to XYZ, so I was thinking if it's not being reseting each time when I am trying to set it to Y? So what could be possible solutions or work arounds for this?

    P.S. keeping XYZ do not work properly, as transform is not being synchronised.
     
  2. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    So I came back to multiplayer again and still facing the same problem (using the newest Unity 5.3.4). Here is a simple script, which creates GameObject prefab with NetworkTransform and NetworkIdentity:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Networking;
    4.  
    5.  
    6. public class CreatePrefab : MonoBehaviour {
    7.  
    8.     public void Create(){
    9.         string name = "prefab";
    10.      
    11.         GameObject go = new GameObject(name);
    12.         go.AddComponent<NetworkIdentity>();
    13.         NetworkTransform nt = go.AddComponent<NetworkTransform>();
    14.         nt.syncRotationAxis = NetworkTransform.AxisSyncMode.AxisY;
    15.      
    16.         UnityEditor.PrefabUtility.CreatePrefab("Assets/"+name+".prefab",go,UnityEditor.ReplacePrefabOptions.Default);
    17.         UnityEditor.AssetDatabase.Refresh();
    18.      
    19.         UnityEngine.Object.DestroyImmediate(go);
    20.     }
    21. }
    22.  
    In the line 14 syncRotationAxis should be changed to Y, but when I am checking the created prefab, it still has XYZ. I include package here to view it on the scene (with editor script and "Create" button).

    So any ideas, if I am missing something here or it's best to report a bug?
     

    Attached Files:

    Last edited: May 28, 2016