Search Unity

[RELEASED] GPU Instancer - Crowd Animations

Discussion in 'Assets and Asset Store' started by LouskRad, Apr 29, 2019.

  1. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,

    Single Pass Instanced is not supported since it uses its own instancing solution which would conflict with GPUI.

    On the other hand, Multi-Pass should work in HDRP without errors. We will test this with the specific versions you have mentioned; but at first glance the errors in the video might be related to internal Unity issues.
     
  2. Nyphur

    Nyphur

    Joined:
    Jan 29, 2016
    Posts:
    98
    Is there a particular reason why this hasn't this been tested? Custom shader support is listed as a feature on the asset store, and virtually everyone uses ASE or shadergraph now. It'd be great to get this converting ASE shaders out of the box, as the manual setup instructions in the docs don't work.
     
  3. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    The issue with the CA shader setup with custom shaders is that the order of the definitions and includes is important. The CA shaders in the package themselves were made with ASE, but we added the GPUI setup - as shown in the docs - from the shader code. As opposed to adding directives in the ASE editor; which is the thing I mentioned in that post as to what we haven't tested. This is because we can't control the order ASE will generate the defines and includes when they are declared in the ASE editor.

    As for ShaderGraph, you can simply use the setup node for Crowd Animations that we have added in the last update (v0.9.6). You can see this wiki article for more information.
     
  4. VirtusH

    VirtusH

    Joined:
    Aug 18, 2015
    Posts:
    95
    With the goal of streamlining our pipeline, what is the best way for me to programmatically add prefabs to the manager and tell it to bake?

    Currently I am doing this, which is successful-ish (no idea how to bake though):

    Code (CSharp):
    1. public void LoadDatabaseIntoGPUI()
    2.         {
    3.             if (variationDatabase is null)
    4.                 throw new NullReferenceException("Variation Database is null!");
    5.  
    6.             GPUICrowdManager crowds = GetComponent<GPUICrowdManager>();
    7.             GPUInstancerPrefabManager prefabManager = crowds;
    8.  
    9.             var combinedVariations = variationDatabase.GenerateFullyCombinedList();
    10.  
    11.             //Direct load into GPUI
    12.             for (int i = 0; i < combinedVariations.Count; i++)
    13.             {
    14.                 ReflGPUIEditorAddPrefab(prefabManager, combinedVariations[i].RuntimePrefabRef);
    15.             }
    16.         }
    17.  
    18.         //public static GPUInstancerPrefabPrototype AddPickerObject(GPUInstancerPrefabManager _prefabManager, UnityEngine.Object pickerObject, GPUInstancerPrototype overridePrototype = null)
    19.         void ReflGPUIEditorAddPrefab(GPUInstancerPrefabManager _prefabManager, UnityEngine.Object pickerObject)
    20.         {
    21.             System.Reflection.Assembly editorAssembly = System.AppDomain.CurrentDomain.GetAssemblies().First(a => a.FullName.StartsWith("Assembly-CSharp-Editor,")); // ',' included to ignore  Assembly-CSharp-Editor-FirstPass
    22.             Type utilityType = editorAssembly.GetTypes().FirstOrDefault(t => t.FullName.Contains("GPUInstancerPrefabManagerEditor"));
    23.             utilityType.GetMethod("AddPickerObject", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static).Invoke(obj: null, parameters: new object[] { _prefabManager, pickerObject, null });
    24.         }
    Note: 'RuntimePrefabRef' does not refer to a prefab generated at runtime, but rather one that is intended for runtime. This is simply so artists can add model prefabs in editor, and the tools will ensure they are converted to standard prefabs with the correct components.
     
  5. VirtusH

    VirtusH

    Joined:
    Aug 18, 2015
    Posts:
    95
    LouskRad said:
    For example, you can bake the animation data for a generic human rig that you are using, and use the same bake data on all the variations that use the same rig at runtime. We will look into adding a demo scene to exemplify this usage.


    Ok so for each of the two rigs we're using, I added one variation prefab that has animations to GPUI and baked that animation data. Then in my own data (scriptableobjects) I set certain variations as animation masters and gave them references to the baked animation data. At runtime, I use GPUICrowdAPI.DefineGameObjectAsCrowdPrototypeAtRuntime and supply it with the animation data from the correct rig.

    Maybe I am misunderstanding what you meant by reusing bake data in a more generic way, but I'm immediately getting errors out of GPUI. At a glance it appears the animation data expects objects with particular names, which doesn't really lend to the intention of generic reuse.

    Here is the error:
    (Following errors seem to be caused by the first..?)
    upload_2020-10-23_3-26-44.png
     
  6. OliverVSmith

    OliverVSmith

    Joined:
    Nov 7, 2017
    Posts:
    51

    I believe the issue stems around here
    upload_2020-10-25_23-5-58.png
    GPUICrowdUtility.cs ln 253
    Code (CSharp):
    1.    public static GPUICrowdPrototype GenerateCrowdPrototype(GameObject go, bool forceNew, bool attachScript = true, GPUICrowdPrototype copySettingsFrom = null)
    2.         {
    3.             GPUICrowdPrefab prefabScript = go.GetComponent<GPUICrowdPrefab>();
    4.             if (attachScript && prefabScript == null)
    5. #if UNITY_2018_3_OR_NEWER && UNITY_EDITOR
    6.                 if (!Application.isPlaying)
    7.                 {
    8.                     prefabScript = GPUInstancerUtility.AddComponentToPrefab<GPUICrowdPrefab>(go);
    9.                 }
    10.                 else
    11.                 {
    12.                     prefabScript = go.AddComponent<GPUICrowdPrefab>();
    13.                 }
    14. #else
    15.                 prefabScript = go.AddComponent<GPUICrowdPrefab>();
    16. #endif
    17.             if (attachScript && prefabScript == null)
    18.                 return null;
    19.  
    In the GenerateCrowdPrototype, in Editor the Defines will always call the Editor functions, which in our case, when loading from an asset bundle or procedurally creating, will return an empty path within the Utility function.
    I added a check for if the Application is running and that seems to resolve the errors and add to the Manager correctly, just need to adjust our workflow/spawning system for when we actually spawn them from an Asset Bundle now.


    I'd recommened GurBu add
     
    chadfranklin47 likes this.
  7. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Thank you for your feedbacks @VirtusH and @OrthrusOliver.

    Since these use cases are not actually internally designed features, so I cannot recommend a best practice for this. Basically, we had designed this functionality for editor use - but we will look into adding new API methods in the light of these feedbacks.
     
  8. OliverVSmith

    OliverVSmith

    Joined:
    Nov 7, 2017
    Posts:
    51
    @louskrad I'm just trying to go off of what you have available in your API.
    In my project, we were loading our Crowds from Asset Bundles (with their Baked data already attached) and then when instantiating, our somewhat hacky method was to get the Prototype, add it to the Managers Prototype List and then disable and re-enable the Manager.

    Code (CSharp):
    1.             GPUInstancer.CrowdAnimations.GPUICrowdManager man = MonoBehaviour.FindObjectOfType<GPUInstancer.CrowdAnimations.GPUICrowdManager>();
    2.             foreach (GPUInstancer.CrowdAnimations.GPUICrowdPrefab pref in prefab.GetComponentsInChildren<GPUInstancer.CrowdAnimations.GPUICrowdPrefab>())
    3.             {
    4.                 GPUInstancer.CrowdAnimations.GPUICrowdPrototype proto = pref.prefabPrototype as GPUInstancer.CrowdAnimations.GPUICrowdPrototype;
    5.                 if (!man.prototypeList.Contains(proto))
    6.                 {
    7.                     man.prototypeList.Add(proto);
    8.                     man.enabled = false;
    9.                     man.enabled = true;
    10.                 }
    11.                 IsInstanced = true;
    12.             }
    This was quite inefficient, and whilst usually reliable, could break at the drop of a hat for unknown reasons.

    So after reading your post about us being able to copy the baked rig data, I thought HUZZAH that's exactly what we want, and means we can easily support modded character models (using one of our rigs that we could share).
    This has led me to the following, and it's still not quite working:

    Bake one of each Rig, and store that on a Scriptable object in our Asset Bundle and have each character model have a Key that will relate to the appropriate rig (for example, "Human", "Deer", "Imp" etc).
    On load, we grab all the character models, run the DefineGameObjectAsCrowdPrototypeAtRuntime function in the GPUICrowdAPI supplying the Manager, the character prefab and the appropriate GPUICrowdAnimationData (based upon our Key).
    Then setup the Proto appropriately, run the InitializePrototype function for each CrowdPrototype (add the appropriate settings) and finally run the InitializeGPUInstancer function.

    Code (CSharp):
    1. foreach (Race race in StaticData.Races)
    2.         {
    3.             foreach (OAsset asset in race.crowdUnitType.prefabs)
    4.             {
    5.                 GameObject prefab = asset.GetAsset<GameObject>();
    6.                 InstanceReferencer inRef = prefab.GetComponent<InstanceReferencer>();
    7.                 if (inRef != null)
    8.                 {
    9.                     GPUInstancer.CrowdAnimations.GPUICrowdPrototype proto = GPUInstancer.CrowdAnimations.GPUICrowdAPI.DefineGameObjectAsCrowdPrototypeAtRuntime(CrowdManager, prefab, GPUInstancedCrowdData.Instance.GetAnimData(inRef.ObjectKey));
    10.                     proto.isShadowCasting = false;
    11.                     proto.enableRuntimeModifications = true;
    12.                     proto.addRemoveInstancesAtRuntime = true;
    13.                     proto.autoUpdateTransformData = true;
    14.                     proto.addRuntimeHandlerScript = true;
    15.  
    16.                     GPUInstancer.GPUInstancerAPI.InitializePrototype(CrowdManager, proto, 400);
    17.                     proto.isShadowCasting = false;
    18.                     proto.enableRuntimeModifications = true;
    19.                     proto.addRemoveInstancesAtRuntime = true;
    20.                     proto.autoUpdateTransformData = true;
    21.                     proto.addRuntimeHandlerScript = true;
    22.  
    23.                 }
    24.             }
    25.         }
    26.         //CrowdManager.InitializeRuntimeDataAndBuffers(true);
    27.         GPUInstancer.GPUInstancerAPI.InitializeGPUInstancer(CrowdManager);
    From there, I've tried a bunch of different things, but despite finally not getting any errors, any prefab that I spawn with the Prototype data, always says "Instancing has not been initialized" on it's component.

    It seems that the "GPUICrowdPrefab.SetupPrefabInstance" function is never called and even calling it manually makes no difference.


    I've been working on this for a few days now trying to debug and do different things, and I feel FRUSTRATINGLY CLOSE so any and all help would be greatly appreciated.
     
  9. OliverVSmith

    OliverVSmith

    Joined:
    Nov 7, 2017
    Posts:
    51
    UPDATE:
    Finally got it working!
    I needed to manually add a GPUInstancerPrefabRuntimeHandler component to every prefab we instantiate and finally, it works. Going to see what steps I can remove, working backwards.
     
    VirtusH and LouskRad like this.
  10. Simunek

    Simunek

    Joined:
    Jul 15, 2016
    Posts:
    49
    Hi,

    I was changing graphical pipelines, so I deleted old version of the asset (+ GPU). Then I import new one. I was moving from URP to old one. Can you help me fix this issue?



    https://drive.google.com/file/d/1f3U0uPS-LhZ_53akfy53U4m2tUi4Tw30/view?usp=sharing

    Kernel 'CSAnimateBones' not found
    UnityEngine.ComputeShader:FindKernel(String)
    GPUInstancer.CrowdAnimations.GPUICrowdManager:Start() (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:59)
    ArgumentException: Kernel 'CSAnimateBones' not found.
    GPUInstancer.CrowdAnimations.GPUICrowdManager.Start () (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:59)

    I also get in runtime:
    NullReferenceException: Object reference not set to an instance of an object
    GPUInstancer.CrowdAnimations.GPUICrowdManager.UpdateAnimatorsData (GPUInstancer.CrowdAnimations.GPUICrowdRuntimeData runtimeData) (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:461)
    GPUInstancer.CrowdAnimations.GPUICrowdManager.LateUpdate () (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:261)

    Thanks and have a nice day!

    Petr
     
    Last edited: Oct 28, 2020
  11. Simunek

    Simunek

    Joined:
    Jul 15, 2016
    Posts:
    49
    Got it! :)

    Compute/CSSkinnedMeshAnimate cound not compile because of Vulcan :) I just removed it from Graphics API list and all is good :)

    Anyways... Great asset! Thanks for it! :)

    Petr
     
    LouskRad likes this.
  12. VirtusH

    VirtusH

    Joined:
    Aug 18, 2015
    Posts:
    95
    @OrthrusOliver @LouskRad
    I appreciate the replies and investigative programming!
    However I'm still having the same issue...

    It seems to me that the baked animation data expects to find a SkinnedMeshRenderer on an object with a specific name..?
    This seems like a fundamental conflict with the idea of generic animation data.

    I'd love any additional insight you could provide OrthrusOliver, you seem to be doing something rather similar to what I am doing.

     
    chadfranklin47 likes this.
  13. mau_iida

    mau_iida

    Joined:
    Apr 2, 2020
    Posts:
    8
    Hi, we are using GPUInstancer v1.4.2 + Crowd Animations v0.9.5.

    when compiling this shader code.
    Assets/GPUInstancer-CrowdAnimations/Shaders/Lit_GPUICA.shader

    there is below error:
    Shader error in 'GPUInstancer/CrowdAnimations/Universal Render Pipeline/Lit': invalid subscript 'instanceID' at /UnitySamples/UniversalRenderingExamples-master/temp.hlsl(89) (on d3d11)

    Any idea about this?
     
  14. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    The problem is that skinned mesh bone indices and bind poses are also included in the bakes. You can do a workaround for this by creating a prefab with all the skinned meshes that you want to use the animation for, bake animation data from that prefab, and use this data in the prefabs you want to use. Keep in mind, however, that for this to work, all the prefabs still should be using the same rig (same bone counts, etc.)

    I suggest re importing the shader first, and if it doesn't work, delete the GPUInstancer-CrowdAnimations folder and reinstall crowd animations from the Asset Store.
     
    VirtusH likes this.
  15. mau_iida

    mau_iida

    Joined:
    Apr 2, 2020
    Posts:
    8
    Thanks, LouskRad.

    Reimporting can make the error go away once, and it's running fine with Unity Editor.
    But when making a build, the error will happen again.
    It also happens with the GPUI demo, easy to reproduce if you can have a look.
    Unity 2020.1.0f1 + URP 8.2.0
     
  16. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    We have tested this with Unity 2020.1.5f1 and URP 8.2.0 and can confirm that it is working with no such errors. It might be because of the 2020.1.0f1 version you are using; Unity have fixed many such errors after.

    So I would recommend updating to the latest 2020.1 version and see if it helps.
     
    mau_iida likes this.
  17. Alic

    Alic

    Joined:
    Aug 6, 2013
    Posts:
    137
    Hey LouskRad. I see in the release notes for GPU Instancer and the Crowds addon "New: Added Assembly Definition files." I love it when an asset handles assemblies itself so I don't have to add my own and worry about losing them on updates. Now that I've downloaded the project though, I don't see assembly definition files. Am I just missing them? Do I have to unzip them from somewhere?

    Thanks for your time!
     
    Last edited: Nov 18, 2020
  18. Alic

    Alic

    Joined:
    Aug 6, 2013
    Posts:
    137
    Uhoh, think I might have a hunch what's going on. I'm using Unity 2019.1.1. It looks like version 1.4.2 of GPU Instancer isn't compatible with anything below Unity 2019.1.10. So when I install the asset I'm getting version 1.4.1, which doesn't have assembly definitions. I'm actually also seeing compilation errors when I install the Crowds addon, so I think there may be problems with changes to Unity's AnimatorController in 2019.1 that make it so my version of unity isn't working with any version of the Crowds addon? I'm going to try upgrading to 2019.1.10. May not be worth moving my whole project up right now, but I'll try it out and report back.

    Thanks for reading!
     
  19. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Yes, the future updates of Crowd Animations will be for Unity 2019.1.10 and higher and this included the update we had made with the ASMDEF files.

    If after changing your Unity version, the package you import from the PackageManager does not change; you can delete the asset package from

    %AppData%\Roaming\Unity\Asset Store-5.x\GurBu Technologies\

    or on a mac:

    ~/Library/Unity/Asset Store-5.x/GurBu Technologies/

    and that should fix that potential issue.
     
  20. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    @LouskRad out of curiosity it's been in beta for a long time though I think it's working great, what's keeping you from saying it's 1.0?
     
  21. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    Also whilst I'm here, I am trying to use your crowd animator setup for crowds that actually change their positions, similar to how the World War Z game has loads of zombies running around chasing you. I've already used the plugin for crowds that don't walk really but just change their Y so I just modify their m13, using lerp, which is simple enough but I'm trying to think how to change the positions and rotations of loads of characters like that in an optimized way:


    Code (CSharp):
    1.  
    2. float pos = Mathf.Min( m_CrowdDataArray[ i ].CachedFinalPositions.y, m_PlatformTransformArray[ i ].m13 + distanceToTravel );
    3. float actualDif = pos - m_PlatformTransformArray[ i ].m13;
    4. for( int j = 0; j < length; j++ )
    5. {
    6.        m_TotalCrowdTransformArray[ j + ( i * length ) ].m13 += actualDif;
    7.  }
    8.  
    9. GPUInstancerAPI.UpdateVisibilityBufferWithMatrix4x4Array( m_GPUiCrowdManager, m_CrowdPrototype, m_TotalCrowdTransformArray );
    10.  
    Whilst the above works fine for hundreds of instances, using matrix4x4.TRS to similar amount of entries per frame doesn't really work. So I'm wondering how you would change transformations for all those entries properly.
     
  22. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Many features of the CA features started out as experimental, but they have been solidified so far with updates. We are still looking into overcoming more of the current limitations before we launch the 1.0 release.

    I would suggest looking into the Job System and the Burst Compiler for squeezing the most out of the C# side when using CA.
     
    Nihil688 likes this.
  23. Kaldorei

    Kaldorei

    Joined:
    Aug 12, 2010
    Posts:
    112
    Hello, do you plan to add a shader for motion vector pass for correct use with TAA and similar effects?

    Thanks
     
  24. Wenon

    Wenon

    Joined:
    Mar 18, 2018
    Posts:
    19
    @LouskRad Hello, is there a way to bake animation which skinned meshes are inside prefab? Something like Human as parent with animator but without skinned mesh renderer and children with skinned mesh renderer head, legs, hair, bones etc. This is human with customizable body, he can choose what parts of the body he wants.
     
    Last edited: Dec 5, 2020
  25. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,

    TAA is working out of the box in our tests, with the demo scene that's using the included Crowd Animations shader. If it is not working in your setup, you can send us the details and we can investigate it.

    Hi,
    yes, you can use the Has Optional Renderers feature for this.
     
  26. Wenon

    Wenon

    Joined:
    Mar 18, 2018
    Posts:
    19
    Thank you for answer. I got a little problem with this, when I trying to bake animation two errors appears, can you help me with this?
    I have posted photos in the attachment to the post
     

    Attached Files:

  27. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    When using CA in HDRP, please make sure you extract the HDRP package from the Assets/GPUInstancer-CrowdAnimations/Extras folder.

    Also, make sure the prefabs for the characters are using the GPUInstancer/CrowdAnimations/HDRP/Lit shader (which will appear after exporting this package).

    As for the error in the 2nd screenshot; it can be an import issue. Please try re-importing the GPUInstancer-CrowdAnimations folder and see if this helps.
     
  28. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    btw @LouskRad in your new update where you add asmdefs ( thank you for that :D I was adding them manually each time ) your GPU Instancer asmdef says it's missing it's reference ( could it be burst? )
     
  29. Wenon

    Wenon

    Joined:
    Mar 18, 2018
    Posts:
    19
    I set all materials for characters to use GPUInstancer/CrowdAnimations/HDRP/Lit. Error disappeared but still animation texture is missing after bake animation.
     

    Attached Files:

  30. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    How difficult would it be to use the baked animations on entities instead of gameobjects?
     
  31. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Yes, it is a reference to Burst but the GPUI code conditionally checks for the package's existence so if it's not found it does not cause an issue. Burst is currently only used for the async bone updates feature.

    Looks like the bake was not finished. Please make sure you are seeing the progress bar in the editor when the bake is running and check if you are getting any errors or warnings in the console that might tell about the problem. If the problem persists, you can send us a sample project showing the issue so we can investigate it.

    There is an included No-GameObject workflow scene in the package (NoGameobjectDemo) you can use as an example for not using GameObjects. You can use the same relevant CA API methods if you decide to use entities.
     
  32. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    Ooooolala!! All the other assets I looked at don't have an easy path to the ECS workflow, so this is great news! :) Do you foresee any problems with it running under Hybrid Renderer V2?

    Edit: I just realized that mobile platforms are not supported so I can't use it :-(
     
    Last edited: Dec 21, 2020
  33. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    blacksun666 likes this.
  34. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    lclemens likes this.
  35. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    Wow.... 10 million is insane! And that's with a $750 graphics card.

    I remember reading somewhere that they did some custom global lighting. At one point the game engine was (and probably still) is Unity. In the Steam description of UEBS2 it states "crowd rendering and AI technology which uses pure GPU POWER". They said that they used vertex based animation in UEBS1 (so probably baking vertex animations into textures), but with UEBS2 they're using the baked bone animation technique. From what I've read, the bone technique uses much less memory than vertex baking, but is tougher on the GPU so people end up playing tricks with LODs and reducing bone counts depending on distance to camera. With vertex baking on a laptop RTX 2060 Max-Q, I'm only able to get about 70k ECS entities at 30fps if the vertex count is 600 or less (using my own baked vertex animation system). GPU Instancer Crowd Animations apparently uses the bone baking technique.

    In one of the videos, Robert mentions that they're doing AI and pathfinding in the graphics card as well. That's really freakin cool. However, it means that everything is in the GPU, so they're probably not using ECS, and if they were to sell it on the asset store, integrating it with the rest of a game built in CPU space might tricky. They're basically building the entire game in GPU, so they must be really badass at coding in shader languages! Since it's all in the GPU, there's no copying of data back and forth and no CPU code to slow things down... it's like a self-contained GPU particle system, except instead of just a bunch of particles, it's an entire battle simulator. Brilliant, really.
     
    Nihil688 likes this.
  36. MisterZhou

    MisterZhou

    Joined:
    Nov 9, 2013
    Posts:
    15
    upload_2021-2-21_17-32-47.png
    When I run demo, I report an error directly...why?

    CSCrowdAnimatorController.compute:

    no variants for this platform (no compute support, or no kernels)
     
    Last edited: Feb 21, 2021
  37. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Please make sure your target platform meets the minimum requirements for Crowd Animations (specifically please note that mobile is not supported).

    If your target is a supported platform, please try re-importing the GPUInstancer-CrowdAnimations folder and see if it solves the issue.
     
  38. MisterZhou

    MisterZhou

    Joined:
    Nov 9, 2013
    Posts:
    15
    Thanks!It's worked!
     
    LouskRad likes this.
  39. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    Hi @LouskRad I'm trying to incoprorate the plugin in an already complex project so I am forced to use the Mecanim system for the animations and not remove bone game objects either. Anyway I'm using this very simple code to start testing:

    Code (CSharp):
    1. public void SetupEnemies()
    2.     {
    3.         m_GPUiCrowdManager.enabled = false;
    4.         List<GPUInstancer.CrowdAnimations.GPUICrowdPrefab> instanced = new List<GPUICrowdPrefab>();
    5.     GameObject parent =    GameObject.Find( "Horde_PoolParent" );
    6.         Animator[] animators = parent.GetComponentsInChildren<Animator>(true);
    7.         for( int i = 0; i < animators.Length; i++ )
    8.         {
    9.             instanced.Add(animators[i].GetComponent<GPUInstancer.CrowdAnimations.GPUICrowdPrefab>());
    10.         }
    11.        
    12.         GPUInstancerAPI.RegisterPrefabInstanceList(m_GPUiCrowdManager, instanced);
    13.         m_GPUiCrowdManager.enabled = true;
    14.     }
    I have a pool system and the prefabs are disabled when I do this ( not sure if it makes any difference ) but I get this error:

    KeyNotFoundException: The given key was not present in the dictionary.
    System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    GPUInstancer.CrowdAnimations.GPUIMecanimAnimator.UpdateDataFromMecanimAnimator (GPUInstancer.CrowdAnimations.GPUICrowdRuntimeData runtimeData, System.Int32 arrayIndex, UnityEngine.Animator animatorRef, System.Collections.Generic.List`1[T] animatorClipInfos) (at Assets/Extra/GPUInstancer-CrowdAnimations/Scripts/Core/AnimatorWorkflow/GPUIMecanimAnimator.cs:41)
    GPUInstancer.CrowdAnimations.GPUICrowdManager.UpdateAnimatorsData (GPUInstancer.CrowdAnimations.GPUICrowdRuntimeData runtimeData) (at Assets/Extra/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:483)
    GPUInstancer.CrowdAnimations.GPUICrowdManager.LateUpdate () (at Assets/Extra/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:261)

    now I tried using a per instance approach with

    GPUInstancerAPI.AddPrefabInstance( m_GPUiCrowdManager, prefab ); but it didn't work with this:

    Code (CSharp):
    1. public void AddEnemies(GameObject enemy)
    2.     {
    3.         GPUICrowdPrefab prefab = enemy.GetComponent<GPUICrowdPrefab>();
    4.         if( !first )
    5.         {
    6.             GPUInstancerAPI.InitializeGPUInstancer( m_GPUiCrowdManager, prefab.prefabPrototype );
    7.             first = true;
    8.         }
    9.         GPUInstancerAPI.AddPrefabInstance( m_GPUiCrowdManager, prefab );
    10.     }
    I feel a bit lost :D
     
  40. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,642
    We started to use Crowd in our no gameobjects scenario and we found a flaw with it.

    InitializeWithMatrix4x4Array which is a NoGameObject method calls
    InitializeGPUBuffer which calls
    runtimeData.InitializeData() which calls
    GPUICrowdUtility.SetAppendBuffers(this) which calls
    GPUISkinnedMeshData smd = prototype.animationData.GetSkinnedMeshDataByName(renderer.rendererRef.gameObject.name);

    which means I must create and keep a gameobject alive
     
  41. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,

    from the error message, it looks like the clip running in the Animator is not found in the bake data. That is, for some reason the baked animation data from the animator does not match the animations that are used at runtime. Could be an override, or maybe you edit the animator at runtime?

    Hi Sebastiano,

    if that was the case then the NoGamoObject Demo Scene would not run. The referenced "gameObject" there is the reference to the prototype's prefab (not the gameObject prefab instance).
     
    Nihil688 likes this.
  42. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    Hey guys.

    I keep getting this error when baking animations:

    System.IndexOutOfRangeException: Invalid kernelIndex (0) passed, must be non-negative less than 0.
    at (wrapper managed-to-native) UnityEngine.ComputeShader.SetTexture(UnityEngine.ComputeShader,int,int,UnityEngine.Texture,int)
    at UnityEngine.ComputeShader.SetTexture (System.Int32 kernelIndex, System.String name, UnityEngine.Texture texture) [0x00009] in <3dc54541a2574ac7826a004a212a4332>:0
    at GPUInstancer.CrowdAnimations.GPUICrowdAnimationBaker.AnimationBakerFinish () [0x00069] in E:\git\TestWithAssetImport\Assets\GPUInstancer-CrowdAnimations\Scripts\Editor\GPUICrowdAnimationBaker.cs:445
    UnityEngine.Debug:LogError(Object)
    GPUInstancer.CrowdAnimations.GPUICrowdAnimationBaker:AnimationBakerFinish() (at Assets/GPUInstancer-CrowdAnimations/Scripts/Editor/GPUICrowdAnimationBaker.cs:511)
    GPUInstancer.CrowdAnimations.GPUICrowdAnimationBaker:AnimationBakerUpdate() (at Assets/GPUInstancer-CrowdAnimations/Scripts/Editor/GPUICrowdAnimationBaker.cs:410)
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions()



    Can anyone help?
     
  43. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    Yeah I was overriding the controller, now that fixed it! But I get infinite messages of this Debug.Log:
    GPUI Mecanim Animator can not find state, the state's hash is 0, I thought of deleting any States that had no animations in but that didn't help.

    So apart from this message flooding the console one of the animations creates 1 frame where it stays there even though on the background you can see it continues the animation as should so it looks like 2 meshes are ontop of each other, a second later it disappears.
    Double frame.png

    And if I "kill" these monsters which returns them to a disabled pool I get the following error:

    Code (CSharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. GPUInstancer.CrowdAnimations.GPUIMecanimAnimator.UpdateDataFromMecanimAnimator (GPUInstancer.CrowdAnimations.GPUICrowdRuntimeData runtimeData, System.Int32 arrayIndex, UnityEngine.Animator animatorRef, System.Collections.Generic.List`1[T] animatorClipInfos) (at Assets/Extra/GPUInstancer-CrowdAnimations/Scripts/Core/AnimatorWorkflow/GPUIMecanimAnimator.cs:23)
    4. GPUInstancer.CrowdAnimations.GPUICrowdManager.UpdateAnimatorsData (GPUInstancer.CrowdAnimations.GPUICrowdRuntimeData runtimeData) (at Assets/Extra/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:483)
    5. GPUInstancer.CrowdAnimations.GPUICrowdManager.LateUpdate () (at Assets/Extra/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:261)
     
  44. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,642
    Hi Lous, that has nothing to do with the demo, we are already using the plugin in our title. However, that contract breaks our totally no game object flow as we will need to keep the game object for the prototype alive in the scene. this doesn't happen with GPUI Instancer it's a problem with Crowd only.
     
  45. OliverVSmith

    OliverVSmith

    Joined:
    Nov 7, 2017
    Posts:
    51
    Was just trying out the latest version (as we're looking at updating to 2020.3).

    Just wanted to do a reminder that the GenerateCrowdPrototype function is still broken by default for defining at Runtime.
    It'd would work fine in a build but won't in Editor.
    So At line 253 in GPUICrowdUtility.cs would be nice if you could just add a case for checking if the Application is Running or not.
    Code (CSharp):
    1. #if UNITY_2018_3_OR_NEWER && UNITY_EDITOR
    2.                 if (Application.isPlaying)
    3.                 {
    4.                     prefabScript = go.AddComponent<GPUICrowdPrefab>();
    5.                 }
    6.                 else
    7.                 {
    8.                     prefabScript = GPUInstancerUtility.AddComponentToPrefab<GPUICrowdPrefab>(go);
    9.                 }
    10. #else
    11.                 prefabScript = go.AddComponent<GPUICrowdPrefab>();
    12. #endif
     
  46. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Please make sure your target platform meets the minimum requirements for Crowd Animations (specifically please note that mobile is not supported).

    If your target is a supported platform, please try re-importing the GPUInstancer-CrowdAnimations folder and see if it solves the issue.

    This looks like an issue with the Add/Remove functionality - although I need more information on how you are doing this (are you using auto. add/remove, or the API?). Can you please email us further details on this, so we can follow the case better.

    Hi Sebastiano,
    what I meant was specifically the GPUInstancer - Crowd Animations/Demos/NoGameObjectsDemo scene that comes with the Crowd Animations package.

    That demo does not keep a GameObject alive in the sense that it is not kept in the Scene. It only references a prefab that sits among the project assets (not instantiated). The renderer.rendererRef.gameObject.name reference that you mentioned in your previous post is the reference to this prefab.

    So I don't see why you are keeping a GameObject alive. Can you please elaborate? Specifically, how and why exactly are you instantiating a GameObject?

    Hi Orthrus,

    Although this definitely solves the problem in your case (where the prefab comes from an asset bundle) - the solution would not work generically (for example if the prefab does not come from the asset bundle).

    We are, however, already looking into API design for generating Crowd prototypes for runtime scenarios in various cases. I can't however give you an ETA for when this will be added.
     
  47. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,642
    @LouskRad

    We may have been tricked by our use case so we need to double check if what we want to do can be done with ChangeMaterial, but our deal is that we need 2 prototypes from the same prefab because one will need a different material. We are realising now that we may be able to register twice the same prefab, generate 2 prototypes and change the material to one using ChangeMaterial. Is this right?
     
    Last edited: Apr 1, 2021
  48. ushakovn

    ushakovn

    Joined:
    Mar 7, 2021
    Posts:
    2
    @LouskRad ,

    Hello, today I got some errors when I tried use crowd animator with that asset model HORSEMAN ANIMATION COLLECTION | 3D Animations | Unity Asset Store

    Code (CSharp):
    1. CSInstancedRenderingVisibilityKernel.compute: Kernel at index (0) is invalid
    2. UnityEngine.StackTraceUtility:ExtractStackTrace ()
    3. GPUInstancer.GPUInstancerUtility:DispatchCSInstancedVisibilityCalculation<GPUInstancer.GPUInstancerRuntimeData> (UnityEngine.ComputeShader,int,GPUInstancer.GPUInstancerRuntimeData,bool,int,int) (at Assets/Assets/GPUInstancer/Scripts/Core/Static/GPUInstancerUtility.cs:570)
    4. GPUInstancer.GPUInstancerUtility:UpdateGPUBuffer<GPUInstancer.GPUInstancerRuntimeData> (UnityEngine.ComputeShader,int[],UnityEngine.ComputeShader,int[],GPUInstancer.GPUInstancerRuntimeData,GPUInstancer.GPUInstancerCameraData,bool,bool,bool,bool) (at Assets/Assets/GPUInstancer/Scripts/Core/Static/GPUInstancerUtility.cs:360)
    5. GPUInstancer.GPUInstancerUtility:UpdateGPUBuffers<GPUInstancer.GPUInstancerRuntimeData> (UnityEngine.ComputeShader,int[],UnityEngine.ComputeShader,int[],System.Collections.Generic.List`1<GPUInstancer.GPUInstancerRuntimeData>,GPUInstancer.GPUInstancerCameraData,bool,bool,bool,bool) (at Assets/Assets/GPUInstancer/Scripts/Core/Static/GPUInstancerUtility.cs:319)
    6. GPUInstancer.GPUInstancerManager:UpdateBuffers (GPUInstancer.GPUInstancerCameraData) (at Assets/Assets/GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:556)
    7. GPUInstancer.GPUInstancerManager:LateUpdate () (at Assets/Assets/GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:265)
    8. GPUInstancer.CrowdAnimations.GPUICrowdManager:LateUpdate () (at Assets/Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:266)
    I never had it when I work with humanoid models, but that was caused by a model generic with animation. However, in tested, I am able to see model and animations. Is anyone know how I can fix that? Model are invisible and throw errors every frame. Thanks
     
  49. ushakovn

    ushakovn

    Joined:
    Mar 7, 2021
    Posts:
    2
    In addition, when I regenerate shaders , in console it start throw addtional error

    Code (CSharp):
    1. Shader error in 'CSInstancedRenderingVisibilityKernel': Couldn't open include file 'Include/PlatformDefines.compute'. at kernel CSInstancedRenderingVisibilityKernelLOD0 at CSInstancedRenderingVisibilityKernel.compute(1)
    BTW, I added './' to the line with path to Include/PlatformDefines.compute and it fixed. Is all shaders might require that fix ?
     
    Last edited: Apr 2, 2021
  50. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,

    From the error, this looks like the compute shaders are not imported correctly (or maybe their files have been moved). In any case, please try re-importing the /GPUInstancer folder first and then the /GPUInstancer-CrowdAnimations folder.

    This error seems to not be related to the horsemen collection.
     
    Abbrew likes this.