Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Weaver - Get rid of your magic strings

Discussion in 'Assets and Asset Store' started by Kybernetik, Dec 3, 2018.

  1. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    Last edited: Aug 7, 2020
    WinterboltGames likes this.
  2. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    What is the difference with the Lite and Pro versions?
     
  3. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
  4. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    511
    @Kybernetik Just found a bug on the inspector after creating the 14th layer.
    upload_2020-2-5_1-18-3.png
    All the layer names would shift to the right.
     
  5. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    Thanks, I'll take a look at it.
     
    Gekigengar likes this.
  6. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    Is this hotfix "Fixed CSharp.IsValidInMemberName to correctly treat the pipe symbol "|" as an invalid character" that could be included in the next update...
     
  7. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    It will be included in the next update when I do some work on Weaver again, it's just a pain to test and upload the Pro and Lite versions with several different versions of Unity each (more so than my other assets because Weaver tests include procedural scripts so they can't be automated) so I haven't done it just for that one bug fix.
     
  8. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    Speaking on new Unity versions.. just updated my project to 2020.1.0a22 and it was Weaver causing some issues with one of its build scripts that builds the BuildDetails.cs script

    Well I mean you could just update the Pro version first and then do the Lite version as and when time allows, so Lite version doesn't get as frequent an update.. it is afterall the free version.
     
  9. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    Trying to support alpha and beta versions of Unity is a massive waste of time because they often introduce bugs that are fixed by the time that version actually releases. For example, in one of the recent Unity versions they implemented a new API for adding your own page to the preferences window but during the beta the old system was broken and the new one completely undocumented, then when it released the old API worked fine again.

    Setting up the tests and separating everything from the rest of my unreleased systems is also a significant chunk of the time involved and doing each version separately would increase the possibility of having different issues with only one of them, which is already a significant hassle as it is.
     
  10. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
     
  11. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    yeah fair enough can't blame you on that when it's unity breaking stuff without having adequate replacements they stick to and document properly.

    Anyway the above error is from 2020.1.a22 but I'm not utilising weaver just yet, so I've removed it for now.
     
  12. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    If you try it again, check the import settings of the DLLs because that sounds like the external scripts can't see anything in the DLLs so Unity might have lost the import settings (if so, that's a bug I would expect them to fix before release). The ones in Assets/Plugins/Weaver should be editor-only and the ones in the Runtime folder are for all other platforms.
     
  13. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    hmm doesn't seem to be the issue
     
  14. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    Weaver v6.0 is now up on the Asset Store. The Change Log is actually rather small, but since Weaver Pro now consists of raw source files instead of pre-compiled DLLs the Upgrade Guide has a process you need to follow if you want to keep your settings (custom layer masks, asset injection links, etc.)
     
  15. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    Weaver v6.1 is now up on the Asset Store. Its Changes are mostly just improvements to the procedural scripting system which I needed in order to implement the Controller State Generator system for Animancer.
     
  16. Bezoro

    Bezoro

    Joined:
    Mar 16, 2015
    Posts:
    67
    Is Weaver supposed to work well with Amplify Shaders? Because it causes a bunch of errors after generating the shader constants. Seems to be that it's generating multiple duplicated lines.
    Manually deleting the duplicated lines gets around the problem, but doing that every time the script is regenerated is less than ideal.

    Unity 2020.2.7f1
    Weaver Lite 6.1
    Amplify 1.8.9
    URP 10.3.2
     
    Last edited: Mar 7, 2021
  17. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    Can you email your shader to mail@kybernetik.com.au so I can see where it's going wrong?

    In the mean time, you could just copy the fixed class generated for that shader into another script and take it out of Weaver's list so it doesn't keep getting regenerated.
     
  18. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    The attached zip should fix the issue. Just extract the DLL and XML files into
    Assets\Plugins\Weaver\Utilities\Weaver Lite
    and overwrite the existing files (not the ones inside the Runtime folder).
     

    Attached Files:

  19. Bezoro

    Bezoro

    Joined:
    Mar 16, 2015
    Posts:
    67
    Beautiful.
    Thanks for taking the time.
    Love your assets.
     
  20. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    283
    @Kybernetik Does this asset support tags as well? Can't seem to find anything related to tags...
     
    Last edited: Apr 11, 2021
  21. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    I haven't included anything for tags because I never use them and unfortunately Weaver is not popular enough to justify the time it would take to properly implement, document, test, and support features I'll never use.

    But if all you want is a simple procedural class containing all the tags as constants without any customisation options or anything, just put the attached script anywhere in your project and save the scene to get it to generate.

    Given how simple it is I might include it in future versions, but I'm not actively working on Weaver at the moment so that won't be any time soon.
     

    Attached Files:

  22. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    283
    Yes, just that and being able to use the asset injection with tags. Thank you.
     
  23. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    What do you mean? Asset injection has nothing to do with tags.
     
  24. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    283
    Well, I didn't buy your asset yet. Maybe I didn't understand it right, but doesn't the asset injection allow me to use static fields or properites on scripts in the inspector? So I just mean being able to pass Tag.mytag to a function's string parameter in the inspector. Assuming the tags generated are static.
     
  25. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    Weaver Lite lets you try out all the features in the editor so you can see how it works before deciding if you want to buy it to use it in runtime builds.

    Asset Injection achieves something similar to regular serialized fields for statics, but not exactly the same. The fields are shown in the Weaver window, not the Inspector. It also only applies to asset references, not other field types (float, string, etc.).
    I'm not sure what you mean by that.
     
  26. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    283
    I mean this upload_2021-4-12_8-38-6.png . I am passing a hard-coded string as an argument in the inspector. Unity doesn't allow me to pass a static variable here. I was hoping with your asset I could somehow do this. In this case, I'd like to pass one of the tags generated by your script as an agument.
     
  27. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    That's not possible with Unity Events.

    But my UltEvents plugin supports enum parameters which could come somewhat close if you make an enum containing all your tags and use it as the parameter for your SetPrefabTag method.

    Personally though, I prefer to just avoid tags altogether.
     
    Marks4 likes this.
  28. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    283
    Ok, I'm curious. You cleary don't like tags...why? What do you use instead?
     
    Last edited: Apr 12, 2021
  29. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    It depends on what I'm actually trying to do. In most cases there's a component I'll be able to use to identify the object type. Do you have something specific you're trying to do?
     
  30. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    283
    How could I do that in combination with your script that generates the tag constants? I'd like to keep the enum updated every time I add a tag, remove, edit.

    Same for the layers. I think it'd be nice to get all of these constants as enums to make them readily usable by your UltEvent asset. This way we can avoid magic strings in the inspector as well.

    I am instantiating multiple prefabs, and tags are the easiest way that I found to identify which prefab was instantiated. Since there doesn't seem to be a way to get the type of the prefab or something like that. The tag serves as a unique identifier.
     
    Last edited: Apr 12, 2021
  31. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    That would need to be completely different because the ScriptBuilder system doesn't support enums.

    Basically, you'd take out everything except the Script property and GenerateScript method and in that method you'd need to build the enum script's text manually with something like this (untested):
    Code (CSharp):
    1. text.AppendLine("public enum Tags");
    2. text.AppendLine("{");
    3.  
    4. var tags = UnityEditorInternal.InternalEditorUtility.tags;
    5. for (int i = 0; i < tags.Length; i++)
    6. {
    7.     text.Append("    ");
    8.     text.Append(Weaver.Editor.Procedural.Scripting.CSharpProcedural.ValidateMemberName(tags[i]));
    9.     text.AppendLine(",");
    10. }
    11.  
    12. text.AppendLine("}");
    But even then, changing the tags and regenerating the script won't update any of the values you have already configured in events so it still isn't possible to make a fully reliable system when using tags.
     
  32. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    283
    Okay forget about enum. Could you make UltEvent accept a static string as parameter on string fields in the inspector? Unity only accepts hard coded strings, it would be amazing if we could pass variables. I think this applies to int, floats, etc. Regular Unity only allows hard coded values in the inspector. I want to avoid magic strings in the inspector, but I can't find a way. It seems that I will just need to stop using the inspector for this. I like the inspector's convenience, and I'd like to keep using the inspector if there's a way to avoid magic strings on them. I was hoping weaver could do this. But maybe UltEvent can be updated to support this?
     
  33. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    It would be possible, but if I get time to do more development on UltEvents there are a lot of more useful features I'd work on before something like that.
     
  34. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    283
    I added the post to the UltEvents thread where it should be.

    When you put it that way I get the feeling I'll never see this update though ;_;
     
  35. Bezoro

    Bezoro

    Joined:
    Mar 16, 2015
    Posts:
    67
    Hey man, just wanted to make sure that Weaver is still being maintained.
    I hate Unity's reliance on strings with a passion and after trying out the free version I really like it and would love to get the pro version.
    I already have Animancer Pro and Inspector Gadgets Pro and can't really see myself using Unity without them. Would love to add Weaver to that list.

    Also, I had an issue when using the free version with Amplify Shaders, to which you sent me a hotfix.
    Would you happen to know if that issue is present in the pro version?
     
  36. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    I'm still fixing bugs as necessary, but I'm not working on any new features at the moment.

    The shader issue is still present in v6.1 Pro, but if you send an email to mail@kybernetik.com.au with your invoice number I can just give you the fixed script. It's annoying to have to test everything in each Unity version so I've been waiting for them to drop support for Unity 2018.4 LTS before I upload it as a new version, but they still haven't dropped it (even though they were supposed to when 2020.3 LTS released).
     
  37. BoteRock

    BoteRock

    Joined:
    Jan 10, 2013
    Posts:
    8
    Hey! I have been a happy Weaver user for some time, so congratulations for the great plugin!
    One issue that I'm having right now, is that when I open the Unity editor, the weaver window shows some references as broken, because these are not loaded yet. These get loaded without issues after hitting play the first time.

    The problem is that if I start unity in headless mode, to make an automated build, these never get loaded when the build starts, so the assets never get linked in the build and I get NullReferenceExceptions as soon as the project launches.

    Is there a way to force all the references to load right before the build starts? I think it should be done automatically, but still if there is some function to call manually, I would appreciate it.

    Edit: After digging the source code a bit, I found that AcquireSavedData _is_ called at unity startup, and it _does_ manage to get the saved asset. The strange part of it is that it still shows up as red in the Unity inspector, so I don't know what could be making that the assets are not referenced correctly at startup, and therefore, not linked in the build.
     
    Last edited: Jun 3, 2021
  38. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    Which Unity version? And are all the missing assets prefabs? I'm pretty sure it's caused by the nested prefab system in newer Unity versions because I've run into issues with other systems when I've been referencing components on a prefab where it just loses or fails to load the references at certain times.

    I might be able to work around the issue by storing the target's details alongside the direct reference so that if the reference fails I can try to get the asset manually using the details.

    Try using a GameObject reference to the prefab itself alongside your component reference and see if it works when the component fails.
     
  39. BoteRock

    BoteRock

    Joined:
    Jan 10, 2013
    Posts:
    8
    Version is Unity 2019.4, and yes, all the missing assets are prefabs (it doesn't happen with scriptables, prefs, etc)

    Edit: it also happens with AssetReference when the referenced asset is Weaver.Asset<MyComponent> too, I think that hints that it could be related to prefabs.

    It is very strange, because after digging more with the debugger, it definitely loads the AssetInjectionData.Asset correctly, but then later it becomes null, no reason why.

    I'll try the GameObject reference, and will come back to you if I find something else.

    Edit2: it also happens when the linked prefab doesn't have a nested prefab.
    I also found that when I edit code, it reloads the references correctly. Also, when I edit code when unity is closed, the recompilation when starting the engine again also leads to the references getting grabbed back correctly
     
    Last edited: Jun 3, 2021
  40. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    Yeah, it's not the actual nesting, it's the way they redesigned the system to support nesting. My theory is that the system doesn't deserialize the whole prefab immediately in case it might contain other nested ones that it might also need to load which is normally fine because it gets resolved before anything normal tries to use it, but only works inconsistently with Weaver trying to access it immediately as soon as it loads.
     
  41. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    I just tried it in Unity 2019.4 but haven't managed to replicate the problem.

    Is the component you're referencing on the root object of the prefab?

    Does the issue occur even on an empty prefab with nothing but the component you're referencing?
     
  42. BoteRock

    BoteRock

    Joined:
    Jan 10, 2013
    Posts:
    8
    Hey! I managed to work around the issue by doing something like this in the affected objects:
    Code (CSharp):
    1.  
    2.     //[Weaver.AssetInstance]
    3.     public static DDEventsSystem instance;
    4.  
    5.     [Weaver.AssetInstance]
    6.     public static GameObject objInstance;
    7.  
    8.     void Awake() {
    9.         instance = this;
    10.     }
    11.  
    It seems to work, but now I had another issue making an automated build, it seemed to be related with an AssetList :'(

    About those questions: yes, the referenced component was in the root GameObject of the prefab.
    I haven't tried with an empty prefab, I can test it tomorrow, as it is getting late here today.

    Best regards
     
  43. JosephSelahJr

    JosephSelahJr

    Joined:
    Oct 1, 2020
    Posts:
    14
    I'm getting errors as well. Just imported today. This is the top error I'm getting

    CS0115 'AssetList.Directory': no suitable method found to override Weaver D:\GitHub\Fighting Game Tutorial\Assets\Plugins\Weaver\Asset Lists\AssetList.cs 29 Active
     
  44. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    I just tried importing Weaver Lite into a new project and didn't get any errors. Try just deleting it and importing it again.

    Otherwise:
    • Check the import settings of the DLLs in Assets\Plugins\Weaver\Utilities\Weaver Lite. The one outside the Runtime folder should be active only in the Editor and the one inside the Runtime folder should be active in all other platforms.
    • Which platform are you using? Unity doesn't actually let me configure platforms that I don't have installed so I have to edit those DLL settings manually as text and sometimes get it wrong, though that version has been up for a while and no one else has had this problem.
    • Which Unity version are you using?
     
  45. JosephSelahJr

    JosephSelahJr

    Joined:
    Oct 1, 2020
    Posts:
    14
    So I can just delete the Weaver projects? No additional clean up is needed? I went for it and I do see left over files. I'm hooked up to git and I see some Weaver files in Assets/Plugins. And I see some files in Assets/Procedural Assets. Not sure if it's related to Weaver.

    By platform, do you mean the IDE? I'm using Visual Studio 2019 for Win.

    My Unity version is 2020.3.11f1
     
  46. JosephSelahJr

    JosephSelahJr

    Joined:
    Oct 1, 2020
    Posts:
    14
    Actually ignore my last post. I reimported as you recommended and it appears to be working. No compile time errors and runs without crashing at least.
     
  47. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    I meant build platform (PC, Android, etc.).

    And yeah, you'd need to delete those two folders. The one in Plugins is Weaver itself and the Procedural Assets folder is where it puts the scripts generated for the Project Constants and any other procedural assets you make.

    Glad you got it working.
     
  48. JosephSelahJr

    JosephSelahJr

    Joined:
    Oct 1, 2020
    Posts:
    14
    Unfortunately the error has come back. I tried to do a reimport again, and it failed after one successful run. I think the error may not occur until after the first run. Seems to be consistent.

    The errors for reference:

    upload_2021-6-18_9-23-26.png
     
  49. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    It's so strange that that's the first error you get. If it wasn't able to see the classes in the DLL, it should be complaining that it can't inherit from AssetListBase before the Directory property.

    If you open the AssetList script, click on AssetListBase, and press F12 to go to the definition, what do you get? It should show the public members of the class defined in the DLL.

    Would you mind trying it in an empty project to see if you can still get it to happen there and when it does, email the project to mail@kybernetik.com.au?
     
  50. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,773
    Posting here in case others have the same issue.

    Looks like it's caused by a bug in Unity 2020+.

    If you open the Weaver.csproj file in the root of your project with a text editor (just outside the Assets folder) it has a block that looks like this:
    Code (CSharp):
    1.      <None Include="Assets\Plugins\Weaver\Utilities\Weaver Lite\Weaver.Lite.xml" />
    2.      <None Include="Assets\Plugins\Weaver\Utilities\Weaver Lite\Runtime\Weaver.Lite.dll" />
    3.      <None Include="Assets\Plugins\Weaver\Weaver.asmdef" />
    4.      <None Include="Assets\Plugins\Weaver\Utilities\Weaver Lite\Weaver.Lite.dll" />
    Since there are two DLLs with the same name, Visual Studio only sees the first one which doesn't have any of the Editor-Only code like the AssetListBase.Directory property. In Unity itself this isn't a problem because the Runtime DLL's import settings have it disabled in the Editor and vice versa so Unity only ever uses one at a time. The problem is simply that the Weaver.csproj generated by Unity 2020+ references both of them where older versions of Unity only referenced the correct one.

    I've reported it as a Unity bug, but for now the issue can be avoided by editing the csproj file to remove the reference to "...\Runtime\Weaver.Lite.dll" so I wrote a script to automate it (since the file gets regenerated whenever you add/delete/move any script). Just import the attached script anywhere in your project and it will run automatically (might as well put it in Assets\Plugins\Weaver\Utilities\Weaver Lite).
     

    Attached Files:

unityunity