Search Unity

Full Inspector: Inspector and serialization for structs, dicts, generics, interfaces

Discussion in 'Assets and Asset Store' started by sient, Jan 23, 2014.

  1. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Prefabs are handled in FI by an element inside of an list/array that Unity serializes. If that data (which is really just the raw FI serialization data) is propagated correctly by Prefab Evolution, then everything should work properly.
     
  2. zee_ola05

    zee_ola05

    Joined:
    Feb 2, 2014
    Posts:
    166
    I will be using both assets for my project. If I see any problems, I'll let you guys know!
     
  3. cjke-7777

    cjke-7777

    Joined:
    Apr 28, 2013
    Posts:
    9
    You are right, something became truncated. Essentially I would like to show the values (see in the first pic below) as a progress bar (even something as simple as the slider used in the MinMax example). I tried capturing the CustomPropertyEditor but it fails to find it - I assume this is because its located beneath an Editor folder, which moves it to a different part of the compile process.

    I have also attached a second image, just because I absolutely love that database feature, so cool. I have jumped on and 5 starred the asset simply because of this. I would like to add an image to the database viewer, but that I might look at down the track.

    Thanks again



     
  4. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Glad to hear you're enjoy FI!

    Would you mind posting a complete sample where FI cannot find the custom editor? The editor folder distinction shouldn't matter, as FI will scan through every loaded assembly.
     
  5. cjke-7777

    cjke-7777

    Joined:
    Apr 28, 2013
    Posts:
    9
    I have zipped up an extract of the project, with only the relevant parts.

    https://dl.dropboxusercontent.com/u/13756312/RunesOfHeaven/Project-mock-sient.zip

    It seems to being throwing errors around "Assets\Scripts\RPGFramework\Definitions\Inspectors" when trying to create a custom attribute editor. The odd thing is that I can "Jump to Definition" just fine.

    If you have time, have a look, but if you cannot no drama's at all. It's not the end of the world - again the db feature is simply awesome. I want to add some images for a cool visual way of viewing each item in the database, but otherwise so very cool.
     
  6. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Yep, should work proper. :)
     
  7. stevethorne

    stevethorne

    Joined:
    Apr 8, 2013
    Posts:
    16
    Hey......

    I have some problems with the fullserializer. I'm trying to serialize a bunch of ints, and they are rather large. For example, one is -1988404566. The problem, is that your serializer is serializing these ints differently than unity does, and because of that, it loads up improperly, where precision of these ints are absolutely necessary. The int mentioned above serializes as -1.988405E+09 in fullserializer. Why is fullserializer doing this? I really need to be able to serialize these ints with full precision.
     
  8. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Can you try moving `RangeEditor` into an Editor folder? Unity's build environment cannot find the PropertyEditor<T> type, so in this scenario the editor folder distinction actually does matter, unfortunately.

    Also -- can you take down the dropbox upload or at least remove the link? It includes FI. Thanks.
     
  9. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Ah, this is unfortunate. Full Serializer serializes all numeric types as floats, which cannot express all integral values. The best solution is to refactor FS so that it properly supports ints, but for the moment you can write a custom converter to serialize the ints as strings. Let me know if I can help with this. I've created an issue here for this.
     
  10. cjke-7777

    cjke-7777

    Joined:
    Apr 28, 2013
    Posts:
    9
    Removed. Really sorry mate, I wasn't thinking


    UPDATE: By placing it within an editor folder it works just fine. I will proceed as such. Have you any tips regarding placing an image in there, especially for the database editor part.
     
    Last edited: Oct 21, 2014
  11. stevethorne

    stevethorne

    Joined:
    Apr 8, 2013
    Posts:
    16
    If I use a custom converter, will I still have the support of FS with generics being serialized?

    Edit: and originally I had wanted to serialize a long, but that serialized as a float, too. So my solution was to take the least significant bits ( because the long was a time value ), and use those in an int. Would it be possible to have support for serializing longs as well?

    Edit2: NVM! I found the converters and made my own for ints. We'll see how this goes.

    Edit3: WORKS! I modified fsPrimitiveConverter.cs to serialize ints and longs as strings.
     
    Last edited: Oct 21, 2014
  12. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    The only advice I can think of is instead of writing an entire custom property editor for the entire type instead write an [InspectorDisplayImage] attribute editor that will show the texture inline.
     
  13. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Awesome :). Feel free to submit a pull request; I'll accept it but likely have to make a minor modification so ints can be read as either strings or numeric values (so existing serialized data doesn't break).
     
  14. TeddyGeorgeoff

    TeddyGeorgeoff

    Joined:
    Oct 21, 2012
    Posts:
    9
    But I am not using the trial. I have purchased it.

    ...or maybe I didnt??? wtf... ok hold on. checking bank account records lol... maybe it didnt go through and I am using the trial...

    EDIT: ok yep, it was the trial. Re-purchased and it works great. 10/10 asset. Thanks! (and sorry for the trouble)
     
    Last edited: Oct 22, 2014
  15. aidesigner

    aidesigner

    Joined:
    May 2, 2012
    Posts:
    121
    Excellent work on every aspect of FI, and I especially like how you abstracted the serializer. I have some high level questions before my purchase that have not been addressed.

    -While FI is impressive I am actually focused on what looks like a Serializer Framework. In particular I want to understand how it can be leveraged to save the user game state. The dream would be to augment existing attributes or add new ones for the GO/classes/members that need to be preserved (ie. Saved to file). The attributes elements would return objects to the saved state when the user restarts the game. For reference the project http://whydoidoit.com/unity-serializer-version-2-0-features/ has similar concept, but is no longer supported. I probably can manually use FS in each class to save various components of the game to a file. However I am after an attribute way that conforms to the way FI/FS already works. Perhaps an extra optional attribute flag indicates to serialize/de-serialize an object for the inspector and to a file to save the game.

    -From experience I am somewhat cautions before adding 3rd party software plugins that are invasive (Even if impressive). Full Inspector falls in this category because I must modify the base classes and will forever be linked. The concern is what happens to all my FI based projects if for some unexpected reason FI dwindles (Happens). FI is impressive enough to take a chance but can you offer any support assurance? Also can a project easily revert back to Unity base classes and standard inspector without consequences? Does FI have anything to do with the final game or really just the editor and its inspector?
     
    rakkarage likes this.
  16. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    FI primarily enables inspector. I've always tried to ensure that serialization behavior remains stable across each release (I'm *very* sensitive to losing data) -- I don't support much customization beyond what the serialization engine itself supports.

    I'll be making FI less invasive in 2.5 with fiValue, which allows you to continue deriving from MonoBehaviour. The trickiest bit about reverting from a BaseBehavior is serialization data -- a lot of what FI supports Unity will simply ignore. If you're careful though, you can make reverting "easy", especially with fiValue. Send me an email if you'd like a build of 2.5.
     
    rakkarage likes this.
  17. cjke-7777

    cjke-7777

    Joined:
    Apr 28, 2013
    Posts:
    9
    Code (csharp):
    1.  
    2. float IPropertyEditorEditAPI.GetElementHeight(GUIContent label, object element, fiGraphMetadata metadata) {
    3.   if (element != null && element is TElement == false) {
    4.   Debug.LogError("Property editor " + GetType().FullName +
    5.   " cannot be used on an object of type " + element.GetType());
    6.   return 0;
    7.   }
    8.  
    9.   return GetElementHeight(label, (TElement)element, metadata);
    10.   }
    11.  
    I'm curious, should there be a null check wrapped around the GetElementHeight function? I've noticed that if I use the '[InspectorDatabaseEditor]' but the item is null, then I errors out on GetElementHeight. It's not really a big deal.

    Btw: Thanks for the note around the image.

    Btw2: Is there a git repo we can push changes back to? And do you accept merge requests?
     
  18. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    [Request]
    Please avoid swallowing exceptions! In some places you just print a warning and then continue on. Instead, always re-throw the exception so a proper error log is printed. That way we can just double-click the log and get directly to the correct line.

    Thanks! :)
     
  19. aidesigner

    aidesigner

    Joined:
    May 2, 2012
    Posts:
    121
    Can you provide some documentation or details about fiValue coming in Version 2.5? After the reply I will email you regarding a beta download.

    As I understand FS is simple/robust and works with all FI types, while ProtoBuf is complex/faster. Do the alternative serializers like ProtoBuf/EasySave2 inherently handle all the types FI supports (Interface/Dictionary/Delegate)? In the case of ProtoBuf do I simply put ProtoContract/ProtoMember on every Class/Member and everything works?

    As I understand FI/FS is really just concerned with the editor and has no game play impact. I am only interested in ProtoBuf because I will also be using it to save all game state, and I want to stick with one serializer. However, it may be difficult to indicate (attributes) all members are serialized for FI, while only some members to save game file. Is this analysis sound in your opinion?
     
  20. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    There were a few issues with the InspectorDatabaseEditor that I've patched up in 2.5 (array support and the null issue as you noticed). Send me an email and I'll send you 2.5 if you want the updates.

    For changes, the easiest way is to either send me the repo and I'll run a diff or submit the diff to GitHub, or just tell me what you've changed.
     
  21. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Ah... I wonder if I can print out the exception differently so the original error log gets captured. Do you have any particular source locations in mind where this is particularily troublesome?

    ie,

    Code (csharp):
    1.  
    2. Caught exception when reading property myGetSet with  context=GameObject (Test5); returning default value for int
    3. Exception:System.Exception: yay
    4.   at Test5.get_myGetSet () [0x00000] in C:\Users\jacob_000\Desktop\Unity\FullInspector2\Assets\Test5.cs:25
    5.   at (wrapper delegate-invoke) System.Reflection.MonoProperty/Getter`2<Test5, int>:invoke_int__this___Test5 (Test5)
    6.   at System.Reflection.MonoProperty.GetterAdapterFrame[Test5,Int32] (System.Reflection.Getter`2 getter, System.Object obj) [0x00000] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoProperty.cs:234
    7.   at System.Reflection.MonoProperty.GetValue (System.Object obj, System.Object[] index) [0x00070] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoProperty.cs:295
    8.   at FullInspector.InspectedProperty.Read (System.Object context) [0x00010] in C:\Users\jacob_000\Desktop\Unity\FullInspector2\Assets\FullInspector2\Core\Utility\InspectedProperty.cs:168
    9. UnityEngine.Debug:LogWarning(Object)
    10.  
    The actual exception is there and you can see the full call stack, ie, this portion is the callstack:

    Code (csharp):
    1.  
    2. at Test5.get_myGetSet () [0x00000] in C:\Users\jacob_000\Desktop\Unity\FullInspector2\Assets\Test5.cs:25
    3. at (wrapper delegate-invoke) System.Reflection.MonoProperty/Getter`2<Test5, int>:invoke_int__this___Test5 (Test5)
    4. at System.Reflection.MonoProperty.GetterAdapterFrame[Test5,Int32] (System.Reflection.Getter`2 getter, System.Object obj)
    5.  
     
  22. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    For the fiValue docs, I'll be pushing updated docs when 2.5 comes out. Here is the page on fiValue:

    fivalue-docs-next.PNG

    protobuf-net works nicely if you're not targeting AOT platforms. For AOT platforms, protobuf-net likes to do runtime code generation but it also supports AOT serializer generation. However, this AOT serializer generation is incompatible with the Unity build environment so I run a decompiler (which requires .NET 4, which means it has to be executed outside of Unity's env... which requires mono on OSX... sigh) on the generated assembly and get back the original C#, which is then piped into Unity's build process. As you can tell, this is a "shakey" process but it does give simple AOT support. This process can be triggered via the menu item "Window/Full Inspector/Developer/Create protobuf-net precompiled serializer (AOT platforms, beta)".

    protobuf-net generally works relatively well, but there are a number of edge cases, ie, it will deserialize empty arrays/lists into null, not the empty collection. If you're looking for serialization to a file, then all of the serializers can do it but they cannot serialize UnityObject references to files, which may be a big limitation depending on what you wanted to do (ie, it's not a "scene save" solution). See these docs for the simple file serialization solution.

    Yea, it might be difficult to disambiguate between "file serialization" and "full inspector" serialization annotations. You could use Json.NET or FullSerializer with a bunch of custom converters, but that seems painful. Maybe use wrapper types, ie, `MyType`, and `MyTypeSavedObject`?
     
  23. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    Yeah I've seen the warnings and ofc. used the callstack to track down the issue, but if you just re-throw the exception unity will log an error as expected, including the context, so you get to the exact line by just double-clicking! :)

    The particular place I was thinking about was InspectedProperty.Read.
     
  24. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Ah, sure. The double clicking is nice. I'll look into it and see what I can do.
     
  25. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    I'm relatively new to c# and serialization, I've been trying to record changes inside array elements for animations. serializedfields and public variables declared on a monobehavour record in mecanim, but I can't seem to get recording working for serialized custom classes, structs, or array elements declared as variables inside my component. Could I do that with this? or am I missing something else?
     
  26. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    I'm not sure how mecanim serializes array values. Do your custom classes serialize when declared directly on a MonoBehaviour? I'd recommend trying out the trial and seeing if it does what you want. The trial is outdated but the core serialization mechanisms are the same, so if it doesn't work in the trial then unfortunately it will not work in the latest release.
     
    AVOlight likes this.
  27. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    yes but serialized custom classes don't record animated variables unless they inherit from MonoBehaviour. my bad i forgot that thats the reason. Thanks anyway :)
     
  28. codingChris

    codingChris

    Joined:
    Apr 8, 2013
    Posts:
    7
    Hey sient,

    first of all thanks for this great asset. Very helpful. But now I'm stuck at writing a custom editor for a fairly simple class which contains a generic member. I followed the docs, but they are not up to date regarding the newly introduced metadata engine, which gives me trouble.

    This is the class I want to have an editor for:

    Code (CSharp):
    1.     [Serializable]
    2.     public class WeightedProbabilityGroupItem<T> {
    3.         public T Value { get; set; }
    4.         public float StartProbability { get; set; } // actually contains more logic, including a private backing field, nothing fancy though
    5.         public float EndProbability { get; set; } // actually contains more logic, including a private backing field, nothing fancy though
    6.        
    7.         public WeightedProbabilityGroupItem() : this(default(T), 0, 0) { }
    8.        
    9.         public WeightedProbabilityGroupItem(T value, float startProb, float endProb) {
    10.             this.Value = value;
    11.             this.StartProbability = startProb;
    12.             this.EndProbability = endProb;
    13.         }
    14.     }
    This is the consuming Mono-/BaseBehaviour:

    Code (CSharp):
    1. public class EnemySpawnPattern : FullInspector.BaseBehavior {
    2.  
    3.     public int[] intArray;
    4.     public List<int> intList;
    5.    
    6.     public WeightedProbabilityGroupItem<string> test;
    7. }
    8.  
    And finaly my Editor:

    Code (CSharp):
    1.     [CustomPropertyEditor(typeof(WeightedProbabilityGroupItem<>))]
    2.     public class WeightedProbabilityGroupItemEditor<T> : PropertyEditor<WeightedProbabilityGroupItem<T>> {
    3.         private static readonly IPropertyEditor _itemEditor = (IPropertyEditor)PropertyEditor.Get(typeof(T), null);
    4.         private static readonly float verticalOffset = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
    5.        
    6.         public override WeightedProbabilityGroupItem<T> Edit(Rect region, GUIContent label, WeightedProbabilityGroupItem<T> element, fiGraphMetadata metadata) {
    7.             if (element == null) {
    8.                 element = new WeightedProbabilityGroupItem<T>();
    9.             }
    10.  
    11.             element.StartProbability = EditorGUI.FloatField(region, label, element.StartProbability);
    12.             region.y += verticalOffset;
    13.             //element.Value = _itemEditor.Edit(region, label, element.Value, metadata.Enter("what goes here?"));
    14.             return element;
    15.         }
    16.        
    17.         public override float GetElementHeight(GUIContent label, WeightedProbabilityGroupItem<T> element, fiGraphMetadata metadata) {
    18.             return verticalOffset * 2;
    19.         }
    20.     }

    If you copy and paste this, you only see the `StartProbability` field, which is expected, because the line with the assignment to `element.Value` is commented out.

    My main Question is: What childIdentifier should I use for the metadata?

    I tried using a made up string, but when I did that, the whole CustomPropertyEditor wasn't used anymore (see the screen shot). Even worse: It doesn't revert back. I commented out that line, but the editor still shows the whole thing. Reimporting the assets and restarting Unity didn't help. Can I clear the serialization cache somewhere?

    Looking forward to your reply.
    Thanks, chris
     

    Attached Files:

  29. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Hey Chris,

    Error messages are now displayed when property editors throw exceptions in constructors.

    The property editor is not being displayed because of this line

    Code (csharp):
    1.  
    2. private static readonly IPropertyEditor _itemEditor = (IPropertyEditor)PropertyEditor.Get(typeof(T), null);
    3.  
    which throws an invalid cast exception. It should be instead

    Code (csharp):
    1.  
    2.     private readonly PropertyEditorChain _itemEditor = (IPropertyEditor)PropertyEditor.Get(typeof(T), null);
    3.  
    Because we're fetching the editor at construction time, there may still be cycles within the property editor construction loop which means that if we fetch the first editor right now we'll possibly get null (the chain might still be empty). When we need the actual IPropertyEditor we can just call .FirstEditor on the PropertyEditorChain.

    As for the metadata question, you just want to insert the name of the property that you're editing. In this scenario, it would be "Value". I can give a more detailed explanation of how the metadata solution works if you'd like to understand how it works under the hood.

    I've gone ahead and finished up your property editor. Let me know if you have any other questions.

    Code (csharp):
    1.  
    2. using FullInspector;
    3. using UnityEditor;
    4. using UnityEngine;
    5.  
    6. [CustomPropertyEditor(typeof(WeightedProbabilityGroupItem<>))]
    7. public class WeightedProbabilityGroupItemEditor<T> : PropertyEditor<WeightedProbabilityGroupItem<T>> {
    8.     private static PropertyEditorChain _itemEditor = PropertyEditor.Get(typeof(T), null);
    9.     private readonly float verticalOffset = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
    10.  
    11.     // When the dropdown arrow is shown, this will force the contents of the edited area to be indented.
    12.     public override bool CanIndentLabelForDropdown {
    13.         get {
    14.             return false;
    15.         }
    16.     }
    17.  
    18.     public override WeightedProbabilityGroupItem<T> Edit(Rect region, GUIContent label, WeightedProbabilityGroupItem<T> element, fiGraphMetadata metadata) {
    19.         if (element == null) {
    20.             element = new WeightedProbabilityGroupItem<T>();
    21.         }
    22.  
    23.         region.height = EditorGUIUtility.singleLineHeight;
    24.  
    25.         element.StartProbability = EditorGUI.FloatField(region, new GUIContent("Start Probability"), element.StartProbability);
    26.         region.y += verticalOffset;
    27.  
    28.         element.EndProbability = EditorGUI.FloatField(region, new GUIContent("End Probability"), element.EndProbability);
    29.         region.y += verticalOffset;
    30.  
    31.         element.Value = _itemEditor.FirstEditor.Edit(region, new GUIContent("Value"), element.Value, metadata.Enter("Value"));
    32.  
    33.         return element;
    34.     }
    35.  
    36.     public override float GetElementHeight(GUIContent label, WeightedProbabilityGroupItem<T> element, fiGraphMetadata metadata) {
    37.         if (element == null) {
    38.             element = new WeightedProbabilityGroupItem<T>();
    39.         }
    40.  
    41.         return verticalOffset * 2 + _itemEditor.FirstEditor.GetElementHeight(new GUIContent("Value"), element.Value, metadata.Enter("Value"));
    42.     }
    43. }
    44.  
     
  30. anthonie.angel91

    anthonie.angel91

    Joined:
    Nov 12, 2014
    Posts:
    1
    Hi, i'm just bought ur plugin, however when i imported, it said that: Assets/FullInspector2/Serializers/JsonNet/DLLs/BuildErrorOnAOT.cs(2,254): error CS1029: #error: 'The default Json.NET serializer that Full Inspector includes cannot be used on this platform. Apologies! Full Inspector includes support for this platform with the Full Serializer serializer. It's even easier to use than Json.NET! Please open the serializer importer to select it ("Window/Full Inspector/Developer/Show Serializer Importer").'

    It only happened on IOS platform, what should i do to make it work, i imported to new project
     
  31. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Click "Window/Full Inspector/Developer/Show Serializer Importer" in the menu; this will bring up the serializer importer. You can then easily remove Json.NET. You'll likely want to switch your default serializer to Full Serializer as well.

    If you want to use Json.NET, then you need to purchase Json.NET for Unity and then follow these instructions.
     
  32. codingChris

    codingChris

    Joined:
    Apr 8, 2013
    Posts:
    7
    Ahh, I see. Without the error messages I suspected the source of the problem being the metadata, but now I understand what was really going on. Thank you for the explanation and the code. Really appreciated.
     
  33. psxcode

    psxcode

    Joined:
    Jan 26, 2014
    Posts:
    26
    I have question about Rotorz library.
    In Rotorz you have an option to display an index of array element.
    In my project I have large arrays that fill the whole screen
    Elements are referenced by index, and when I check parameters of element,
    and want ensure that index is correct, I have to count from above the whole array.
    Please how can I enable index display in arrays
     
  34. Rodolphito

    Rodolphito

    Joined:
    Jan 31, 2014
    Posts:
    17
    I just bought this asset, so far it is amazing! I have a question, I would like to save changes made during play mode. Could someone give me a pointer on how to go about doing that?
     
  35. psxcode

    psxcode

    Joined:
    Jan 26, 2014
    Posts:
    26
    You can save state by clicking right mouse button on script header and selecting SaveState or RestoreState
     
  36. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    I've added a new attribute, [InspectorCollectionShowIndices], that will now handle this scenario. Below is an example of how to use it:

    Code (csharp):
    1.  
    2. using FullInspector;
    3. using System.Collections.Generic;
    4.  
    5. public class IndexSample : BaseBehavior {
    6.     public float[] array;
    7.     [InspectorCollectionShowIndices]
    8.     public float[] arrayIndexed;
    9.  
    10.     public List<float> list;
    11.     [InspectorCollectionShowIndices]
    12.     public List<float> listIndexed;
    13.  
    14.     public HashSet<float> collection;
    15.     [InspectorCollectionShowIndices]
    16.     public HashSet<float> collectionIndexed;
    17.  
    18.     public Dictionary<string, float> dictionary;
    19.     [InspectorCollectionShowIndices]
    20.     public Dictionary<string, float> dictionaryIndexed;
    21. }
    22.  
    upload_2014-11-23_15-28-44.png

    Send me an email or a PM if you'd like the latest build that includes this change.

    Thanks
     
  37. psxcode

    psxcode

    Joined:
    Jan 26, 2014
    Posts:
    26
    Thank you. Thats exactly what I needed.
    If you are planning to publish this update in a week or two, I can wait.
    Im now in another part of the project, so dont mess with custom build just for me
     
  38. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
  39. avee

    avee

    Joined:
    Feb 14, 2013
    Posts:
    6
    Hi,

    I have a very stupid question. How can you serialize Unity unsupported simple types that are direct member of BaseBehavior class? These include ushort, short, ulong, etc..

    I noticed that when we put it inside a struct, it gets serialized with the struct. But when we put the variables directly under the class it does not get serialized.
     
  40. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Yea, I've seen that serializer before but iirc it uses Reflection.Emit, which makes it a no-go on AOT platforms.
     
  41. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Ah, looks like Unity doesn't serialize those types but the code that prevents "double serialization" thinks it does. The fix is simple; I'll post it here but I'm happy to send you the latest build if you'd like that instead. Just shoot me an email or PM.

    For the manual fix, open up the file "FullInspector2\Core\Utility\InspectedType.SerializationQueries.cs"

    add this method

    Code (csharp):
    1.  
    2. /// <summary>
    3. /// Returns true if the primitive is *not* serialized by Unity
    4. /// </summary>
    5. private static bool IsPrimitiveSkippedByUnity(Type type) {
    6.     return
    7.         type == typeof (ushort) ||
    8.         type == typeof (uint) ||
    9.         type == typeof (ulong) ||
    10.         type == typeof (sbyte);
    11. }
    12.  
    and change the beginning of IsSimpleType from

    Code (csharp):
    1.  
    2. private static bool IsSimpleType(Type type) {
    3.  
    to

    Code (csharp):
    1.  
    2. private static bool IsSimpleType(Type type) {
    3.    if (IsPrimitiveSkippedByUnity(type)) {
    4.       return false;
    5.    }
    6.  
    7.    /* ... more code ... */
    8.  
     
  42. avee

    avee

    Joined:
    Feb 14, 2013
    Posts:
    6
    Thanks for the quick reply! I think I will just apply the manual fix for the time being. I will wait for the next Asset Store release for the next build.

    However I found out that the primitive list in IsPrimitiveSkippedByUnity is not complete, it should be

    Code (csharp):
    1.  
    2. private static bool IsPrimitiveSkippedByUnity(Typetype) {
    3.     return
    4.         type == typeof (sbyte) ||
    5.        type == typeof (short) ||
    6.        type == typeof (ushort) ||
    7.        type == typeof (uint) ||
    8.        type == typeof (long) ||
    9.        type == typeof (ulong);
    10.  }
    11.  
    Thanks for the support!
     
  43. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Thanks for the pointing that out.
     
  44. Remiel

    Remiel

    Joined:
    Oct 17, 2012
    Posts:
    105
    Soo...when is 2.5 gonna come out? :)
    I am really looking forward to fiValue<T> and allowing Full Inspector integration without deriving from BaseBehavior.
     
  45. IkeMacoco_Spark

    IkeMacoco_Spark

    Joined:
    Apr 25, 2014
    Posts:
    3
    I second this question. :)
     
    Remiel likes this.
  46. obula

    obula

    Joined:
    Jan 17, 2012
    Posts:
    4
    Hi sient,
    I just bought this plugin. It's awesome.
    But I got a problem. Here is my sample code:
    Code (CSharp):
    1. public class Heroes : BaseScriptableObject<BinaryFormatterSerializer>
    2.     {
    3.         public Dictionary<int, Hero> data;
    4.     }
    5.  
    6.     [System.Serializable]
    7.     public class Hero
    8.     {
    9.         public string heroName;
    10.         public int hp;
    11.     }
    It works.


    But when I changed field of class Hero like this:
    Code (CSharp):
    1. [System.Serializable]
    2.     public class Hero
    3.     {
    4. //        public string heroName;
    5.         public int hp;
    6.     }
    It will occur an exception and my data are all gone. Like this:


    In developing, the data classes would be modified frequently.
    Can you help me to solve this?

    Thanks.

    Obula
     
    Remiel likes this.
  47. Brammel

    Brammel

    Joined:
    Dec 25, 2013
    Posts:
    13
    Hi,

    i have a question regarding serialization of longs (int64)

    currently i have an [RunInEditMode] script that changes the values of some longs in attached components.

    serialization of longs works fine when i manually enter them in the editor,
    but any change this script makes just gets reverted back to the last value i entered manually the moment i press play.

    summary:
    long x = 0 when script is attached to an object.
    i manually fill the field to 5.
    pressing play keeps it 5.

    now i make a script change it to 15 during edit mode (values update correctly during editmode).
    pressing play now makes it 5 again.

    i figure id have to tell the script the values have changed, as it seems he only saves to disk after i manually enter the values and then loads them on pressing play.
    i tried using the dirty flag, but that doesnt seem to work.

    does anyone know how to solve this?
     
  48. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Soon, I expect by the end of next week. I'll finally have a big chunk of time then to do the release (doing the testing pass / etc takes quite a few hours).

    If you want the build now just send me an email or PM.
     
    Remiel likes this.
  49. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Try using a different serializer, ie, FullSerializerSerializer or JsonNetSerializer. Those should handle this situation properly. I strongly discourage use of BinarySerializer, as it's slow, buggy, and not well-supported on every platform.
     
  50. sient

    sient

    Joined:
    Aug 9, 2013
    Posts:
    602
    Let me know if you've resolved this from my response on the GitHub issue page, otherwise can you send me a test scene that will reproduce the issue with the included dirty flag set? Thanks!