Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Scriptableobject assetbundle error in Unity5

Discussion in 'General Discussion' started by wiyi, Jun 29, 2016.

  1. wiyi

    wiyi

    Joined:
    Feb 20, 2013
    Posts:
    17
    I Created a scriptableobject asset:"test.asset"
    When I loaded it use "AssetDatabase.LoadAssetAtPath();", that is right.
    When I build a assetbundle and loaded is use "WWW",it's field is right,but it's property is error.

    Code (CSharp):
    1. public class MYtest:ScriptableObject
    2. {
    3.     public string Name;
    4.     private int aaa;
    5.     public int AAA
    6.     {
    7.     get { return aaa; }
    8.     set { aaa = value; }
    9.     }
    10. }
    11. // function
    12. MYtest mt = ScriptableObject.CreateInstance<MYtest>();
    13. mt.AAA =199999;
    14. mt.Name="Hello";
    15. AssetDatabase.CreateAsset(mt,"mytest.asset");
    16. AssetDatabase.SaveAssets();
    17.  
    18. /****************/
    19. //Loaded AssetDatabase.LoadAssetAtPath
    20. var mt = AssetDatabase.LoadAssetAtPath("mytest.asset", typeof(MYtest));
    21. //mt.AAA ->199999
    22. //mt.Name ->Hello
    23.  
    24. /****************/
    25. //Loaded WWW
    26. string url = @"file:///E:\Test\mytest.unity3d";
    27. WWW _www = new WWW(url);
    28. yieldreturn _www;
    29. MYtest mt = _www.assetBundle.LoadAsset<MYtest>("mytest");
    30. //mt.AAA ->0 ERROR!!!
    31. //mt.Name ->Hello Right!
     
  2. wiyi

    wiyi

    Joined:
    Feb 20, 2013
    Posts:
    17
    Wndows 8 X64 ,Unity3D 5.3.4f1 ,Editor ,Android
     
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,327
    You need to mark
    Code (csharp):
    1.  
    2. private int aaa;
    3.  
    With [SerializeField] tag.
    Code (csharp):
    1.  
    2. [SerializeField] private int aaa;
    3.  
    Non-public properties without [SerialzieField] are not serialized. Public properties also are not serialized. Classes taht are not marked as [System.Serializable] are not serialized. Generic lists are not serialized for many types, etc.

    http://blogs.unity3d.com/2014/06/24/serialization-in-unity/
     
  4. wiyi

    wiyi

    Joined:
    Feb 20, 2013
    Posts:
    17
    ok

    private not serialized