Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Loading UMA string data from server using UNET.

Discussion in 'UNet' started by Thorious, Dec 7, 2015.

  1. Thorious

    Thorious

    Joined:
    Oct 24, 2015
    Posts:
    22
    I am trying to load UMA string data from the server and send it out to the clients to load up. I have saving the file to the server working, and loading the client side character works fine. But the rest of the clients do not see what the other characters look like. I thought the [ClientRpc] sends that out to all to load up but it does not work right.

    I can go into the inspector and click on the player and click load and they see the player I loaded. Below is my script for the saving and loading portion. Any help would be much appreciated.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UMA;
    4. using System.IO;
    5. using UnityEngine.Networking;
    6. using System.Runtime.Serialization.Formatters.Binary;
    7.  
    8. public class Player_Creator : NetworkBehaviour
    9. {
    10.  
    11.     [SyncVar]
    12.     public string PlayerID;
    13.  
    14.     [SyncVar]
    15.     public string syncUMAData;
    16.  
    17.     void Start()
    18.     {
    19.         GenerateUMA();
    20.     }
    21.  
    22.     public override void OnStartLocalPlayer()
    23.     {
    24.         syncUMAData = Player_Data.playerData.umaSerialData;
    25.         PlayerID = Player_Data.playerData.playerID;
    26.         CmdSaveUMADataOnServer(syncUMAData, PlayerID);
    27.         CmdLoadUMADataFromServer(PlayerID);
    28.     }
    29.  
    30.     ////////////////// Load and Save //////////////////
    31.     public void Save()
    32.     {
    33.         //Generate UMA String
    34.         UMATextRecipe recipe = ScriptableObject.CreateInstance<UMATextRecipe>();
    35.         recipe.Save(umaDynamicAvatar.umaData.umaRecipe, umaDynamicAvatar.context);
    36.         syncUMAData = recipe.recipeString;
    37.         Destroy(recipe);
    38.  
    39.         CmdSaveUMADataOnServer(syncUMAData, PlayerID);
    40.     }
    41.  
    42.     [ClientRpc]
    43.     public void RpcLoad()
    44.     {
    45.         //Regenerate UMA using string
    46.         UMATextRecipe recipe = ScriptableObject.CreateInstance<UMATextRecipe>();
    47.         recipe.recipeString = syncUMAData;
    48.         umaDynamicAvatar.Load(recipe);
    49.         Destroy(recipe);
    50.     }
    51.  
    52.     [Command]
    53.     public void CmdSaveUMADataOnServer(string strData, string ID)
    54.     {
    55.         BinaryFormatter bf = new BinaryFormatter();
    56.         FileStream file = File.Create(Application.persistentDataPath + "/" + ID + "UMA.dat");
    57.  
    58.         PlayerUMAData data = new PlayerUMAData();
    59.         data.umaSerialData = strData;
    60.  
    61.         bf.Serialize(file, data);
    62.         file.Close();
    63.     }
    64.  
    65.     [Command]
    66.     public void CmdLoadUMADataFromServer(string ID)
    67.     {
    68.         if (File.Exists(Application.persistentDataPath + "/" + ID + "UMA.dat"))
    69.         {
    70.             BinaryFormatter bf = new BinaryFormatter();
    71.             FileStream file = File.Open(Application.persistentDataPath + "/" + ID + "UMA.dat", FileMode.Open);
    72.             PlayerUMAData data = (PlayerUMAData)bf.Deserialize(file);
    73.             file.Close();
    74.  
    75.             syncUMAData = data.umaSerialData;
    76.             PlayerID = ID;
    77.             RpcLoad();
    78.         }
    79.     }
    80.  
    81. }
     
    Last edited: Dec 10, 2015
    RaRdq likes this.
  2. Thorious

    Thorious

    Joined:
    Oct 24, 2015
    Posts:
    22
    I found that putting my RpcLoad into the command CmdLoadUMADataFromServer does now allow the host to see the clients UMA recipe when loaded, but the client still does not see the recipe from the host.
     
  3. Thorious

    Thorious

    Joined:
    Oct 24, 2015
    Posts:
    22
    Would anyone have any ideas? I was thinking a synclist? As many people that use UMA, I just cant imagine they don't use it with UNET.
     
  4. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,676
    Actually, it's possible that very few people have used UNET with UMA, because I know several people are holding back on using UNET till it matures a bit. So you could be the first. :)

    I don't have any particular advice, except for the obvious (which you probably have already done): try to get your UMA spawning based on a recipe string you send it, simulating how the client would receive the recipe string. Then, if you have that working, try to send and and receive a string over network without any errors. If you have those two down, then do the final step of hooking up the two bits of code.
     
  5. Thorious

    Thorious

    Joined:
    Oct 24, 2015
    Posts:
    22
    Thank you for responding. I do have it working correctly on the host. They see everyones recipe. Just the client does not see the hosts recipe. But if I hit the load function on the host, the client does. Makes me wonder if I need to work out a On Hook function.
    As for being the first, I have seen a lot of people say they got it to work on the old networking, with photon, with uLink, and various others, jut no one wants to share how. :cool: But I dont mind sharing my code :)
     
    RaRdq and hopeful like this.
  6. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,676
    Heck, if you have generic code for UNET and UMA, and an example scene, it might be possible to have Fernando or somebody add it to the official version of UMA.

    Which would be pretty cool. :)
     
  7. Thorious

    Thorious

    Joined:
    Oct 24, 2015
    Posts:
    22
    I can do that, once I get it working, would love to get anyone to look at it and make it better for us all.
     
    hopeful likes this.
  8. Thorious

    Thorious

    Joined:
    Oct 24, 2015
    Posts:
    22
    Sorry hopeful, I don't think people want to share that how nor can Unity offer any help.
     
  9. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,676
    Still stuck, eh?

    I'm sure something will turn up. It's probably something very simple.
     
  10. RaRdq

    RaRdq

    Joined:
    Dec 18, 2015
    Posts:
    2
    Stuck at this problem too... But i even have no experience in networking =(
     
  11. rickcollette

    rickcollette

    Joined:
    Mar 17, 2013
    Posts:
    304
    Thread necro!!

    I don't suppose you got this working?
     
  12. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,676
    Not sure if this will help you, but there is a network demo in the newest release of UMA (2.5).

    If this demo isn't working for you in some way, I'd suggest asking about it in the main UMA thread. I would expect the networking demo to successfully demonstrate sending an UMA recipe across the net.
     
    dasouth and rickcollette like this.
  13. dasouth

    dasouth

    Joined:
    Nov 21, 2016
    Posts:
    10

    as a beginner, I find that demo very confusing tbh..
    So yea, I'm still trying to synx my uma's