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
    Thank you for the feedback. CA uses a light version of the HDRP Lit shader that is made in ShaderGraph. This shader reads the smoothness and metallic values directly from the mask map without support for custom float values. And the default texture value is set to white so it would create that effect as you described without a texture.

    We will fix this, but for now, you can edit the ShaderGraph for this shader to modify it / create your custom version which connect your intended value to the metallic and smoothness outputs:

    GPUInstancer-CrowdAnimations\Shaders\Crowd_Animations_LIT_SG.shadergraph
     
  2. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    @LouskRad can I somehow jobify GPUICrowdAnimator? I mean I could just write my own solution, but currently, I'm using provided class. Are there any plans for making it a struct that can be used in jobs?
     
  3. VirtusH

    VirtusH

    Joined:
    Aug 18, 2015
    Posts:
    95
    You can reference classes in non-burst jobs with GCHandles if you're careful.
     
    Krajca likes this.
  4. namdo

    namdo

    Joined:
    Feb 23, 2015
    Posts:
    200
    Im getting this error.

    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:524)
    GPUInstancer.CrowdAnimations.GPUICrowdManager.LateUpdate () (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:243)



    It doesnt work anymore. If I turn off the crowd manager gameobject the characters appear but if its on the characters dissappear.

    NullReferenceException: Object reference not set to an instance of an object
    GPUInstancer.CrowdAnimations.GPUICrowdManager.OnEnable () (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:88)
    System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <695d1cc93cca45069c528c15c9fdd749>:0)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.


    Another error I'm getting is this one.

    NullReferenceException: Object reference not set to an instance of an object
    GPUInstancer.CrowdAnimations.GPUICrowdManager.OnEnable () (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:88)
    System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <695d1cc93cca45069c528c15c9fdd749>:0)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.



    I have root motion enabled on the animator and the GPU crowd instancer.
     
    Last edited: Sep 28, 2021
  5. SOSolacex

    SOSolacex

    Joined:
    Jan 10, 2018
    Posts:
    121
    Hey, I seem to have this issue and I don't know how to fix it.

    ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <695d1cc93cca45069c528c15c9fdd749>:0)
    System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <695d1cc93cca45069c528c15c9fdd749>:0)
    GPUInstancer.CrowdAnimations.GPUICrowdUtility.SetAnimationData (GPUInstancer.CrowdAnimations.GPUICrowdRuntimeData runtimeData) (at Assets/GPUInstancer-CrowdAnimations/Scripts/Core/Static/GPUICrowdUtility.cs:114)
    GPUInstancer.CrowdAnimations.GPUICrowdRuntimeData.InitializeData () (at Assets/GPUInstancer-CrowdAnimations/Scripts/Core/DataModel/GPUICrowdRuntimeData.cs:72)
    GPUInstancer.GPUInstancerUtility.InitializeGPUBuffer[T] (T runtimeData) (at Assets/GPUInstancer/Scripts/Core/Static/GPUInstancerUtility.cs:132)
    GPUInstancer.GPUInstancerUtility.InitializeGPUBuffers[T] (System.Collections.Generic.List`1[T] runtimeDataList) (at Assets/GPUInstancer/Scripts/Core/Static/GPUInstancerUtility.cs:32)
    GPUInstancer.GPUInstancerPrefabManager.InitializeRuntimeDataAndBuffers (System.Boolean forceNew) (at Assets/GPUInstancer/Scripts/GPUInstancerPrefabManager.cs:184)
    GPUInstancer.CrowdAnimations.GPUICrowdManager.InitializeRuntimeDataAndBuffers (System.Boolean forceNew) (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:325)
    GPUInstancer.GPUInstancerEditorSimulator.EditorUpdate () (at Assets/GPUInstancer/Scripts/GPUInstancerEditorSimulator.cs:135)
    UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at <7587a42c8322471cbc42b27c9b8eab3c>:0)
     
  6. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    By design GPUICrowdAnimator class is not suitable to be converted to a struct or used within jobs as a collection. However we store animator data in a NativeArray which can be found at GPUICrowdRuntimeData.crowdAnimatorControllerData. This might be useful depending on what you are trying to accomplish.

    Hi there,
    Please follow these three steps and see if it solves the issue:
    - Make sure you are using the latest version of GPU Instancer (v1.5.4) and Crowd Animations (v1.0.2).
    - Re-bake your prototypes by clicking "Bake Animations For All" button.
    - Click on the "Register Instances in Scene" button to update referenced instances in the scene, and if you are adding/removing instances at runtime make sure to enable "Auto. Add/Remove Instances" option.

    If the issue continues after these steps, please email us a bug report following this guide.

    Hi there,

    Looks like you are using an older version, can you please make sure to update to the latest version of GPU Instancer (v1.5.4) and Crowd Animations (v1.0.2). If the issue continues after updating, please email us a bug report following this guide.
     
  7. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    I just want to set weights in animators, calculated in job.

    Currently using:
    Code (csharp):
    1. animators[i].SetAnimationWeights(runtimeData, i, weights[i]);
     
  8. SOSolacex

    SOSolacex

    Joined:
    Jan 10, 2018
    Posts:
    121
    Uninstalled, reimported and it worked (was already on latest but some older files must've been mixed up)
    However, currently having this issue.


    ArgumentNullException: Value cannot be null.
    Parameter name: shader
    UnityEngine.Material..ctor (UnityEngine.Shader shader) (at <9baebf9af86541678fd15bfdbf5f26eb>:0)
    GPUInstancer.CrowdAnimations.GPUICrowdShaderBindings.GetInstancedMaterial (System.Collections.Generic.List`1[T] shaderInstances, UnityEngine.Material originalMaterial) (at Assets/GPUInstancer-CrowdAnimations/Scripts/Core/DataModel/GPUICrowdShaderBindings.cs:75)
    GPUInstancer.GPUInstancerShaderBindings.GetInstancedMaterial (UnityEngine.Material originalMaterial, System.String extensionCode) (at Assets/GPUInstancer/Scripts/Core/DataModel/GPUInstancerShaderBindings.cs:125)
    GPUInstancer.CrowdAnimations.GPUICrowdRuntimeData.GenerateLODsFromLODGroup (GPUInstancer.GPUInstancerPrototype prototype) (at Assets/GPUInstancer-CrowdAnimations/Scripts/Core/DataModel/GPUICrowdRuntimeData.cs:161)
    GPUInstancer.GPUInstancerRuntimeData.CreateRenderersFromGameObject (GPUInstancer.GPUInstancerPrototype prototype) (at Assets/GPUInstancer/Scripts/Core/DataModel/GPUInstancerRuntimeData.cs:254)
    GPUInstancer.CrowdAnimations.GPUICrowdManager.InitializeRuntimeDataForPrefabPrototype (GPUInstancer.GPUInstancerPrefabPrototype p, System.Int32 additionalBufferSize) (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:356)
    GPUInstancer.GPUInstancerPrefabManager.InitializeRuntimeDataRegisteredPrefabs (System.Int32 additionalBufferSize) (at Assets/GPUInstancer/Scripts/GPUInstancerPrefabManager.cs:225)
    GPUInstancer.GPUInstancerPrefabManager.InitializeRuntimeDataAndBuffers (System.Boolean forceNew) (at Assets/GPUInstancer/Scripts/GPUInstancerPrefabManager.cs:183)
    GPUInstancer.CrowdAnimations.GPUICrowdManager.InitializeRuntimeDataAndBuffers (System.Boolean forceNew) (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:325)
    GPUInstancer.GPUInstancerEditorSimulator.EditorUpdate () (at Assets/GPUInstancer/Scripts/GPUInstancerEditorSimulator.cs:135)
    UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at <7587a42c8322471cbc42b27c9b8eab3c>:0)


    In case it matters, I often use the standard texture variation shader that was shared with me here a month or two/three ago.

    However, as soon as I start the game it creates an unlimited amount of TempGO objects; and just as many of those shader errors.
     
    Last edited: Sep 30, 2021
  9. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    For weights you can use runtimeData.animationData which is a NativeArray.
    Before you schedule your job make sure to call:
    Code (CSharp):
    1. runtimeData.dependentJob.Complete();
    and then inside the job edit weights using:
    Code (CSharp):
    1. animationData[i * 2 + 1] = weights[i];
    and after the job is completed let GPUI know that there have been a modification with:
    Code (CSharp):
    1. runtimeData.animationDataModified = true;
    From the error it looks like some required shader files are missing. You can import the required packages for the shaders by selecting from the top menu Tools->GPU Instancer->Reimport Crowd Packages.
     
    Krajca likes this.
  10. WaqasGameDev

    WaqasGameDev

    Joined:
    Apr 17, 2020
    Posts:
    118
    Hi, I am targeting webGL and currently want to target 20 unique humanoid models with clothing and all using skinned mesh rendererers. The biggest overhead for my game is MESHSKINNING.UPDATE function which I traced using profiler. Is this something your tool can help me in optimizing this function for WebGL? I read this function uses SIMD and WebGL does not support this.
     
  11. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    Unfortunately GPU Instancer does not support WebGL. You can see the minimum requirement from here.
     
  12. IanNicolades

    IanNicolades

    Joined:
    Oct 1, 2016
    Posts:
    40
    Hi there, probably a silly question but I've read the entirety of the docs and the forum thread and haven't seen an obvious answer to it. :D

    In a no game object workflow, I need an example of how to set up and manage multiple prototypes simultaneously. In other words, imagine 3 different animated characters, each of which have 1000 instances being rendered - I would like to see what the best practice is to set this up from code. All of the examples only use a single prototype/animated mesh at a time from what I can see.

    Am I correct that I simply keep a reference to the Prototype, and calls to GPUInstancerAPI (e.g. InitializeWithMatrix4x4Array, SetInstanceCount, etc) only affect data relating to that Prototype? Or are they shared, and will I need a separate GPUICrowdManager for each skinned mesh? And how do I properly link
    GPUICrowdAnimator objects to each instance?

    Thanks!
     
  13. dearsky

    dearsky

    Joined:
    Jan 27, 2019
    Posts:
    10
    upload_2021-10-25_11-52-1.png bug report, the "activeClipCount" cumulates in the loop which will cause transition bug.
     
    GurhanH likes this.
  14. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    You can use multiple prototypes with one Crowd Manager and use the API calls with a specific prototype. Only the prototype used for the API call will get effected.
    There are different ways to use the GPUICrowdAnimator, but simplest way is to have one animator for each instance. So you can have an array of animators per prototype.

    Mainly you duplicate everything for other prototypes except the Crowd Manager. Here is an example partial code:
    Code (CSharp):
    1.  
    2. ...
    3. public GPUICrowdManager gpuiCrowdManager;
    4. public GPUICrowdPrototype firstCrowdPrototype;
    5. public GPUICrowdPrototype secondCrowdPrototype;
    6. private Matrix4x4[] firstInstanceDataArray;
    7. private Matrix4x4[] secondInstanceDataArray;
    8. private GPUICrowdAnimator[] firstAnimators;
    9. private GPUICrowdAnimator[] secondAnimators;
    10. private GPUICrowdRuntimeData firstRuntimeData;
    11. private GPUICrowdRuntimeData secondRuntimeData;
    12. ...
    13.  
    14. GPUInstancerAPI.InitializeWithMatrix4x4Array(gpuiCrowdManager, firstCrowdPrototype, firstInstanceDataArray);
    15. GPUInstancerAPI.InitializeWithMatrix4x4Array(gpuiCrowdManager, secondCrowdPrototype, secondInstanceDataArray);
    16.  
    17. firstRuntimeData = (GPUICrowdRuntimeData)gpuiCrowdManager.GetRuntimeData(firstCrowdPrototype);
    18. secondRuntimeData = (GPUICrowdRuntimeData)gpuiCrowdManager.GetRuntimeData(secondCrowdPrototype);
    19.  
    20. GPUIAnimationClipData clipData = firstCrowdPrototype.animationData.clipDataList[firstCrowdPrototype.animationData.crowdAnimatorDefaultClip];
    21. for (int i = 0; i < firstRuntimeData.instanceCount; i++)
    22. {
    23.     firstAnimators[i].StartAnimation(firstRuntimeData, i, clipData, UnityEngine.Random.Range(0.0f, clipData.length));
    24. }
    25.  
    26. clipData = secondCrowdPrototype.animationData.clipDataList[secondCrowdPrototype.animationData.crowdAnimatorDefaultClip];
    27. for (int i = 0; i < secondRuntimeData.instanceCount; i++)
    28. {
    29.     secondAnimators[i].StartAnimation(secondRuntimeData, i, clipData, UnityEngine.Random.Range(0.0f, clipData.length));
    30. }
    31. ...
    Thank you for the feedback. We will make the necessary change with the next update.
     
  15. TheGamery

    TheGamery

    Joined:
    Oct 14, 2013
    Posts:
    94
    I upgraded my project to 2021.2 (just came out), to get the shaders (mostly) working instead of pink, I had to resave the "Crowd_Animations_LIT_SG" shader in the ShaderGraph editor, I tried the same for the "Crowd_Animations_Test_SG" but the debugger won't play the animations (drag slider to play it), any ideas how to fix?

    Also got these errors spammed in console by "Crowd_Animations_Test_SG":

    Code (csharp):
    1.  
    2. Material 'GPUInstancer/CrowdAnimations/HDRP/Crowd_Animations_Test_SG' with Shader 'GPUInstancer/CrowdAnimations/HDRP/Crowd_Animations_Test_SG' doesn't have a float or range property '_RenderQueueType'
    3. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    4.  
    Code (CSharp):
    1. Material 'GPUInstancer/CrowdAnimations/HDRP/Crowd_Animations_Test_SG' with Shader 'GPUInstancer/CrowdAnimations/HDRP/Crowd_Animations_Test_SG' doesn't have a float or range property '_ConservativeDepthOffsetEnable'
    2. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    Code (CSharp):
    1. Material 'GPUInstancer/CrowdAnimations/HDRP/Crowd_Animations_Test_SG' with Shader 'GPUInstancer/CrowdAnimations/HDRP/Crowd_Animations_Test_SG' doesn't have a float or range property '_RequireSplitLighting'
    2. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    Code (CSharp):
    1. Material 'GPUInstancer/CrowdAnimations/HDRP/Crowd_Animations_Test_SG' with Shader 'GPUInstancer/CrowdAnimations/HDRP/Crowd_Animations_Test_SG' doesn't have a float or range property '_StencilRefDistortionVec'
    2. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    3.  
    Code (CSharp):
    1. Material 'GPUInstancer/CrowdAnimations/HDRP/Crowd_Animations_Test_SG' with Shader 'GPUInstancer/CrowdAnimations/HDRP/Crowd_Animations_Test_SG' doesn't have a float or range property '_StencilWriteMaskDistortionVec'
    2. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
     
  16. IanNicolades

    IanNicolades

    Joined:
    Oct 1, 2016
    Posts:
    40
    Awesome, thank you so much for this - this gets me almost all of the way there! One more question - I need to know where rendering is actually performed so that I can manually control its order in my scene. I have an extremely complex render pipeline that basically overrides all of Unity's built-in ordering systems, so I just need to see where the draw calls are actually performed so that I can call them at the appropriate point from my engine. I couldn't find this in the docs - any chance you could save me a bunch of time and point me in the right direction? :D
     
  17. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    I have made some tests with 2021.2 and HDRP, but the animation tests worked without issue. Please try right clicking and selecting Reimport on the GPUInstancer-CrowdAnimations folder, and see if you it solves the issue, or if you are getting any errors while the shaders are reimported.

    The errors you mentioned are thrown by the editor when a non-asset material (created from code and not saved as an asset) is selected. It is an issue with the Unity Editor with HDRP materials and should not effect the rendering and normally you do not need to see or edit this test material.

    You can find the draw calls by searching for Graphics.DrawMeshInstancedIndirect inside GPUInstancerUtility.cs.
     
  18. niflying

    niflying

    Joined:
    Jul 11, 2012
    Posts:
    108
    Hi, I bought GPUInstancer 1.5.4 and Crowd Animations 1.0.2.
    But, why my animation plays so shake?
    1.gif
    the origin animation is 2.gif .

    unity 2021.1.2 + HDRP 11.

    Cloud you please help?
     
  19. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    If possible can you please email us a sample project so that we can investigate the issue? There might be something special with the character rig and we will need to look into it to figure out what went wrong.
     
  20. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi everyone,

    GPU Instancer - Crowd Animations v1.1.0 is now available on the Asset Store.

    This version adds Mobile Support to Crowd Animations. It is designed for high-end devices and currently at an experimental stage. Meaning it has not been tested in a wide range of devices/settings yet and it might require further improvements. Please send us a report if you encounter any issues.

    This version requires GPU Instancer v1.6.0 or later. Please make sure to download the latest GPU Instancer version beforehand.

    Here is the full changelog:

    New: Support for Mobile platforms

    Changed: Test Animations feature now works with original shader as long as the shader has the "#pragma shader_feature_vertex GPUI_CA_TEXTURE" defined
    Changed: ASE shader setup no longer requires include and pragma definitions on the shader file (they are loaded from the function node)

    Fixed: While applying multiple events at a single frame, wrong clip count is used when the first event changes the active clip count
     
    nemeth-regime likes this.
  21. Latheeb

    Latheeb

    Joined:
    Jun 27, 2016
    Posts:
    21
    Hello! I'm trying to test out GPU Instancer: Crowd Animations to see if it could work for my project, but I've run into a problem getting it to work.

    I'm using Unity 2021.2.1f1 and HDRP 12.1.0. When I import GPU Instancer I get six instances of the following error:

    Code (CSharp):
    1. State comes from an incompatible keyword space
    2. UnityEditor.AssetPostprocessingInternal:PostprocessAllAssets (string[],string[],string[],string[],string[],bool)
    No errors when importing Crowd Animations but when I try to add a prefab to GPUI Crowd Manager I get one instance of this error:

    Code (CSharp):
    1. InvalidCastException: Specified cast is not valid.
    2. GPUInstancer.CrowdAnimations.GPUICrowdUtility.GenerateCrowdPrototype (UnityEngine.GameObject go, System.Boolean forceNew, System.Boolean attachScript, GPUInstancer.CrowdAnimations.GPUICrowdPrototype copySettingsFrom) (at Assets/GPUInstancer-CrowdAnimations/Scripts/Core/Static/GPUICrowdUtility.cs:356)
    3. GPUInstancer.CrowdAnimations.GPUICrowdUtility.SetCrowdPrefabPrototypes (UnityEngine.GameObject gameObject, System.Collections.Generic.List`1[T] prototypeList, System.Collections.Generic.List`1[T] prefabList, System.Boolean forceNew) (at Assets/GPUInstancer-CrowdAnimations/Scripts/Core/Static/GPUICrowdUtility.cs:314)
    4. GPUInstancer.CrowdAnimations.GPUICrowdManager.GeneratePrototypes (System.Boolean forceNew) (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:269)
    5. GPUInstancer.CrowdAnimations.GPUICrowdManagerEditor.AddPickerObjectCrowd (GPUInstancer.CrowdAnimations.GPUICrowdManager _crowdManager, UnityEngine.Object pickerObject, GPUInstancer.GPUInstancerPrototype overridePrototype) (at Assets/GPUInstancer-CrowdAnimations/Scripts/Editor/GPUICrowdManagerEditor.cs:230)
    6. GPUInstancer.CrowdAnimations.GPUICrowdManagerEditor.AddPickerObject (UnityEngine.Object pickerObject, GPUInstancer.GPUInstancerPrototype overridePrototype) (at Assets/GPUInstancer-CrowdAnimations/Scripts/Editor/GPUICrowdManagerEditor.cs:89)
    7. GPUInstancer.GPUInstancerManagerEditor+<>c__DisplayClass35_0.<DrawGPUInstancerPrototypeAddButton>b__1 (UnityEngine.Object o) (at Assets/GPUInstancer/Scripts/Editor/GPUInstancerManagerEditor.cs:484)
    8. GPUInstancer.GPUInstancerEditorConstants.DrawColoredButton (UnityEngine.GUIContent guiContent, UnityEngine.Color backgroundColor, UnityEngine.Color textColor, UnityEngine.FontStyle fontStyle, UnityEngine.Rect buttonRect, UnityEngine.Events.UnityAction clickAction, System.Boolean isRichText, System.Boolean dragDropEnabled, UnityEngine.Events.UnityAction`1[T0] dropAction, UnityEngine.GUIStyle style) (at Assets/GPUInstancer/Scripts/Editor/GPUInstancerEditorConstants.cs:570)
    9. GPUInstancer.GPUInstancerManagerEditor.DrawGPUInstancerPrototypeAddButton () (at Assets/GPUInstancer/Scripts/Editor/GPUInstancerManagerEditor.cs:474)
    10. GPUInstancer.GPUInstancerManagerEditor.DrawGPUInstancerPrototypesBox () (at Assets/GPUInstancer/Scripts/Editor/GPUInstancerManagerEditor.cs:412)
    11. GPUInstancer.GPUInstancerPrefabManagerEditor.OnInspectorGUI () (at Assets/GPUInstancer/Scripts/Editor/GPUInstancerPrefabManagerEditor.cs:54)
    12. GPUInstancer.CrowdAnimations.GPUICrowdManagerEditor.OnInspectorGUI () (at Assets/GPUInstancer-CrowdAnimations/Scripts/Editor/GPUICrowdManagerEditor.cs:55)
    13. UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <5cd53c58cab44054a1ac592b0da25132>:0)
    14. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    Then this error about 100 times per second afterwards:

    Code (CSharp):
    1. InvalidCastException: Specified cast is not valid.
    2. GPUInstancer.CrowdAnimations.GPUICrowdUtility.GenerateCrowdPrototype (UnityEngine.GameObject go, System.Boolean forceNew, System.Boolean attachScript, GPUInstancer.CrowdAnimations.GPUICrowdPrototype copySettingsFrom) (at Assets/GPUInstancer-CrowdAnimations/Scripts/Core/Static/GPUICrowdUtility.cs:356)
    3. GPUInstancer.CrowdAnimations.GPUICrowdUtility.SetCrowdPrefabPrototypes (UnityEngine.GameObject gameObject, System.Collections.Generic.List`1[T] prototypeList, System.Collections.Generic.List`1[T] prefabList, System.Boolean forceNew) (at Assets/GPUInstancer-CrowdAnimations/Scripts/Core/Static/GPUICrowdUtility.cs:314)
    4. GPUInstancer.CrowdAnimations.GPUICrowdManager.GeneratePrototypes (System.Boolean forceNew) (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:269)
    5. GPUInstancer.CrowdAnimations.GPUICrowdManager.CheckPrototypeChanges () (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:317)
    6. GPUInstancer.GPUInstancerManager.LateUpdate () (at Assets/GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:265)
    7. GPUInstancer.GPUInstancerPrefabManager.LateUpdate () (at Assets/GPUInstancer/Scripts/GPUInstancerPrefabManager.cs:81)
    8. GPUInstancer.CrowdAnimations.GPUICrowdManager.LateUpdate () (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:254)
    9.  
    I've tried redownloading and reimporting both assets multiple times, as well as the "Reimport Packages" and "Reimport Crowd Packages" in Tools/GPU Instancer.

    Any idea what my issue could be?


    Update: Ok, after trying again from scratch I've managed to get past this point, but cannot bake the animations because of the following errog:

    Code (CSharp):
    1. System.IndexOutOfRangeException: Index was outside the bounds of the array.
    2.   at GPUInstancer.CrowdAnimations.GPUICrowdAnimationBaker.AnimationBakerStart () [0x003f0] in D:\Unity Projects\Crowd Test\Assets\GPUInstancer-CrowdAnimations\Scripts\Editor\GPUICrowdAnimationBaker.cs:239
    3. UnityEngine.Debug:LogError (object)
    4. GPUInstancer.CrowdAnimations.GPUICrowdAnimationBaker:AnimationBakerStart () (at Assets/GPUInstancer-CrowdAnimations/Scripts/Editor/GPUICrowdAnimationBaker.cs:369)
    5. GPUInstancer.CrowdAnimations.GPUICrowdAnimationBaker:AnimationBakerInitialize () (at Assets/GPUInstancer-CrowdAnimations/Scripts/Editor/GPUICrowdAnimationBaker.cs:134)
    6. UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
    7.  
     
    Last edited: Nov 9, 2021
  22. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,

    I have tested Unity 2021.2.1f1 and HDRP 12.1.0 and did not see these issues. The issue might be specific to the prefab you are trying to add. Please check if there are any GPU Instancer components (GPU Instancer Prefab or GPUI Crowd Prefab) already added to the prefab and if so remove them from the prefab. Then try adding the prefab to the Crowd Manager and see if it solves the issue.

    If the issue persists, please email us more detailed information (and if possible a sample project) following this guide, so we can investigate the issue.
     
  23. dearsky

    dearsky

    Joined:
    Jan 27, 2019
    Posts:
    10
    bug report, if I turn on "Apply Root Motion" in IL2CPP mode, it will crash.
     
    PutridEx likes this.
  24. dearsky

    dearsky

    Joined:
    Jan 27, 2019
    Posts:
    10
    GurhanH likes this.
  25. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    and thank you for reporting the issue.

    I have investigated it and found out that the issue was caused by the non-blittable boolean fields inside GPUIRootMotion and GPUIAnimationClipData structs. We will release an update soon to solve the issue.
     
  26. dearsky

    dearsky

    Joined:
    Jan 27, 2019
    Posts:
    10
    upload_2021-11-16_9-15-18.png
    Hello, this loop should be changed to reverse for loop, because the prefabInstanceList will change when I use events (in death animations) to destroy instance.
     
    Last edited: Nov 16, 2021
    chadfranklin47 likes this.
  27. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Thank you for the feedback. We will make the necessary change with the next update.
     
    chadfranklin47 likes this.
  28. dearsky

    dearsky

    Joined:
    Jan 27, 2019
    Posts:
    10
    By the way, is there any ways(like jobs) to improve the performance of Crowd Animator Events? I have added several events in my prefabs and it cost nearly 5ms(about 2000 instances). It seems that you have tried to solve it. Wish you can make it soon.
     
  29. Shimrod_

    Shimrod_

    Joined:
    Oct 18, 2017
    Posts:
    7
    Hi, I have a strange bug with the Crowd Manager.

    I had to upgrade a project from 2019.3.6f1 to 2020.3.6f1 (LTS), everything worked fine in 2019 version.
    I upgraded GPUI and GPUI Crowd to the latest versions.

    Basically, after a few seconds, the script "GPUI Crowd Manager" content disappears in the inspector...



    The console then throws a lot of these messages (which make sense) :

    "MissingReferenceException : The variable clipList of GPUICrowdProtoype doesn't exist anymore.
    You probably need to reassign the clipList variable of the 'GPUICrowdProtoype' script in the inspector."

    "ArgumentException: Getting control 5's position in a group with only 5 when doing repaint
    Aborting"


    I've been able to work a few hours with no issues before this bug appeared.
    The protoypes have animations baked and use Crowd Animator. They also use the TextureVariationShader in HDRP.

    Thanks for your help !

    EDIT : the issue seems related to the 2 last prefabs I drop into the Manager. I'm investigating them...
     
    Last edited: Nov 19, 2021
  30. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Thank you for the feedback. We will look into possible optimizations for the event system. If you can email us the profiler data (saved as a binary file with Deep Profile enabled), it would help us identify the issue better.

    Hi there,

    The Unity versions after 2019.4.0 uses a different package and the issue is probably caused by the old baked data which is inconsistent with the new version. You can try the "Bake Animations For All" button to re-create the animation data. If that does not help, you can delete the previously created files under GPUInstancer/PrototypeData/Crowd and then add the prefabs to the Crowd Manager and Bake Animations.
     
    Shimrod_ likes this.
  31. TheGamery

    TheGamery

    Joined:
    Oct 14, 2013
    Posts:
    94
    Would it possible to have a clipName string added to GPUIAnimationClipData (struct in GPUICrowdAnimationData.cs) with animation name set?

    It would be handy for searching by name using Linq etc.
     
    Last edited: Nov 19, 2021
    tcz8 likes this.
  32. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    This struct is used in Jobs so it can not contain strings. But you can use the clipList to find the corresponding data. For example:
    Code (CSharp):
    1. public static GPUIAnimationClipData GetClipDataByName(GPUICrowdPrototype prototype, string clipName)
    2. {
    3.     AnimationClip clip = prototype.clipList.Find(c => c.name == clipName);
    4.     if (clip != null)
    5.         return prototype.animationData.clipDataList[prototype.clipList.IndexOf(clip)];
    6.     return default;
    7. }
     
    tcz8 and TheGamery like this.
  33. Shimrod_

    Shimrod_

    Joined:
    Oct 18, 2017
    Posts:
    7
    Hi, thanks for this. I managed to clean my project and rebake everything.
    As a request, it would be cool to update the documentation about the Texture Variation system (the fishes ^^). I apologize if I missed it, but I couldn't find informations about this.
    While converting my project, around 1,500 instances lost their TextureVariation handler and the values I previously set. I finally managed to get them back (through additively opening and slowly cleaning both scenes), but it would be a nice addition to have a randomizer tool for the UV coordinates of instances already set up in a scene.
    Thanks again for your swift answer. ;)
     
  34. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    I've been coding our AI system for GPUI Crowd and realized you are storing our animations in a SINGLE TEXTURE? /mind blown

    How do you store values? PLEASE run that by me because the tests I ran showed that the precision of png images dies after the first decimal on any colour channel. Does unity's internal texture format have a higher precision?

    Also, MaterialPropertyBlock /poke :p /poke Is there anything in your code preventing us from implementing it? Anything I should know before embarking on this adventure?

    Thank you.:D
     
    Last edited: Nov 25, 2021
  35. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Thank you for the feedback. We will look into adding a more detailed explanation and extra tools for texture variations.

    Hi there,
    We store the textures as a .asset file, so they are not converted to png to prevent data loss. Data is stored as 16bit float per channel (RGBAHalf). You can see the source code from GPUICrowdAnimationBaker.cs file, method name AnimationBakerFinish.

    GPU Instancer uses indirect GPU instancing and this only allows for single MaterialPropertyBlock. So for variations on instances we use a custom solution. You can check the TextureVariationDemo to see an example, and also read the Material Variations documentation here.
     
    Shimrod_ likes this.
  36. VirtusH

    VirtusH

    Joined:
    Aug 18, 2015
    Posts:
    95
    Hi!
    Wanted to share an easy optimization that made our animation baking 10-15x faster. We were waiting 20-30 minutes, now rebaking all the animation data takes about 1 minute 30 seconds.

    Currently the baking process does 1 frame, and then has to wait for unity's editor loops, inspector updates, etc.
    By adding a loop here, that chunks the updates, the progress bar is still very responsive, but baking is very zippy!

    upload_2021-11-29_14-34-27.png
     
    tcz8 likes this.
  37. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    513
    Hi there we're having a strange issue. Our FPS suddenly dropped and we don't know why, any hint ? We don't recall having changed a setting, we tried deactivating bones, tried both Mecanim and Crowd animator but we can't replicate the FPS boost.

    Yesterday vs Today's
    upload_2021-12-1_15-3-4.png

    Here is what we've got in the profiler
    upload_2021-12-1_15-6-29.png
     
  38. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    thank you for the feedback.
    Before, we were required to wait for editor loop for bones to update correctly. But there may have been changes on the Unity editor since then, so it might not be required on the newer versions. We will test this and make the necessary changes.

    Hi there,
    All I can tell is that make sure the instances are registered on the Crowd Manager and there are no errors on the console. Otherwise, I would suggest to make comparisons with the previous version of your project if you are using source control or a backup. Especially check if you changed any project settings or added new assets that might effect GPU performance.
     
    tcz8, Whatever560 and VirtusH like this.
  39. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    513
    Thanks, right now it's working again. One question should animator baking also bake the transitions? Because things work fine but there are no transition between states. Should we use the other workflow and perform transition manually ?
    Thanks for your answer.
     
  40. Plnda

    Plnda

    Joined:
    Nov 23, 2016
    Posts:
    14
    Hi, i have some pre-purchase questions

    (Scenario: i have an rts game that i would like to draw loads of units in)

    - Does it support a simple blend tree ? i have a velocity parameter that just blends between idle, walking and running
    - The character holds a weapon mesh in the animation, (No IK) its just a child of the right hand is this supported
    - Can i just move the character by transform? and the animation keeps on playing correctly?
    - In this case i will assume if the above will work it will work with any pathfinding solution aslong as it modifies the transform data / rotation

    Thanks
     
    Last edited: Dec 10, 2021
  41. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    We are looking into reading transition states from Macanim without causing performance impact. However if possible we recommend to use the Crowd Animator workflow. It works much faster than Mecanim Animator.

    Hi there,
    - Blend Trees are supported. For Macanim workflow, it is read from the animator. For Crowd Animator, you use the StartBlend API method.
    - You can have bone attachments such as weapons. You need to select which bones need to be exposed (e.g. right hand) under Animator Settings.
    - Transform changes can be applied automatically by enabling Auto. Update Transform Data option.
    - Pathfinding solutions will also work with it. There is a demo scene called NavMeshDemo in the package which exemplify this.
     
  42. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    513
    Thanks, we are using this workflow now, we found a better animation pack that works well with the current linear transitions. We had to fix the following in GPUICrowManager L.470, otherwise the UI was crashing when a clip was missing, we couldn't then access baking and other settings :

    Code (CSharp):
    1.                         for (int i = 0; i < optionsList.Length; i++)
    2.                         {
    3.                             var    clip            = prototype.clipList[i];
    4.                             if(clip == null) continue;
    5.                             string clipName        = clip.name;
     
  43. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    226
    Hello again, I created a shader in ShaderGraph for my instanced characters, but should I use that same shader for rendering the characters in a non-GPUI context?

    For example, I Instantiate many characters with the GPUI-compatible shader assigned to the skinned mesh material. When I disable the CrowdAnimator, the characters are still rendered with the GPUI-compatible shader instead of a non-compatible one.

    I see in GPUICrowdShaderBindings.cs that something similar is done for the default Lit shaders. Is it possible to add a custom "original shader - instanced shader" duo to GPUICrowdShaderBindings? When I click the add button to the list in the editor, nothing happens.

    Thanks.
     
    Last edited: Dec 29, 2021
  44. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Thank you for the feedback. We will add this null check on the next update.
    Hi there,
    You can use the shaders with GPUI setup in a non-GPUI context as long as you do not use it with DrawMeshInstancedIndirect call.

    Shader Bindings are not designed to be added manually, it is handled automatically. When your material's shader already has the GPUI setup, the "Is Original Instanced" value will be set to true and the original shader will be used at runtime. If the "Is Original Instanced" is false, the shader from the "Instanced Shader" field will be used.
     
    chadfranklin47 likes this.
  45. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    226
    Thanks for your response. I'm concerned about the performance of using the GPUI supported shader on normal skinned mesh renderers even if the cost may be minimal as the position is still being passed through the GPUI nodes. I was hoping to avoid that if possible.

    But when you say it is handled automatically, does that mean there is no way to add an "original" shader (created via ShaderGraph) and an "instanced" shader to the shader bindings? If there is, please let me know the best workflow for that.

    Currently, I have an original material and a GPUI supported material (both created via shader graph). It is my current understanding that if I add a prefab to the manager with the GPUI supported material on the SkinnedMeshRenderer that the shader will get added to the shaderBindings with "Is Original Instanced" set to true. But this is what I don't want, I would like to set it to false and set the original (non-GPUI supported) shader as the one on the SkinnedMeshRenderer.
     
  46. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    In that case you can have two shaders one without GPUI setup (e.g. Custom/MyOriginalShader) and one with GPUI setup (e.g. Custom/MyGPUIShader). And edit the shader bindings like this:
    upload_2021-12-30_16-49-49.png

    Make sure to edit the shader bindings after opening a new scene with no GPUI managers, otherwise the managers might override it while editing.
     
    chadfranklin47 likes this.
  47. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    226
    Thanks, that did work. It would be nice though if there were a workflow to manually add to the shader bindings rather than having to make a prefab and add it to the manager to get it to show up.
     
  48. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    226
    Another issue I am having is that after adding a prototype to the CrowdManager at runtime using DefineGameObjectAsCrowdPrototypeAtRuntime(), I must use:
    GPUInstancerAPI.InitializeGPUInstancer(gPUICrowdManager, true);
    which (with the true parameter) reinitializes all prototypes, not only the one I just added. How can I reinitialize only the most recent prototype added to the manager, or only initialize prototypes that haven't yet been initialized?

    When I set the "forceNew" parameter to false, I get the error "Can not find runtime data for prototype".

    I tried
    GPUInstancerAPI.InitializeGPUInstancer(gPUICrowdManager, addedPrototype);
    , but this doesn't initialize the GPU Buffers as well as other things so I get a different set of errors.

    GPUInstancerAPI.InitializePrototype() doesn't work for me either as it overwrites the prototype settings. For example, it disables runtime modifications.

    As of now, I am forced to reinitialize all existing prototypes when adding a new one, then I have to re-add all my events for each one. This seems wasteful and I hope there is a better solution I am missing. Please let me know if there is a better way to do things, or if this area can be improved. Thanks.


    Edit:
    I made my own method which seems to work fine, but I'm sure it can be improved.

    After calling:
    GPUICrowdPrototype addedPrototype = gPUICrowdManager.DefineGameObjectAsCrowdPrototypeAtRuntime(character.gameObject, prototypeToClone.animationData, true, prototypeToClone);


    Instead of needing to call:
    GPUInstancerAPI.InitializeGPUInstancer(gPUICrowdManager, true);


    I am now calling my custom method:
    gPUICrowdManager.InitializeRuntimeDataAndBuffersForPrototype(addedPrototype, false);


    Here is the custom method (in GPUInstancerPrefabManager.cs):

    Code (CSharp):
    1. public virtual void InitializeRuntimeDataAndBuffersForPrototype(GPUInstancerPrefabPrototype prototype, bool forceNew = true)
    2.         {
    3.             if (_registeredPrefabsRuntimeData == null)
    4.                 _registeredPrefabsRuntimeData = new Dictionary<GPUInstancerPrototype, List<GPUInstancerPrefab>>();
    5.  
    6. #if UNITY_EDITOR
    7.             if (Application.isPlaying)
    8.             {
    9. #endif
    10.                 if (registeredPrefabs != null && registeredPrefabs.Count > 0)
    11.                 {
    12.                     foreach (RegisteredPrefabsData rpd in registeredPrefabs)
    13.                     {
    14.                         if (!_registeredPrefabsRuntimeData.ContainsKey(rpd.prefabPrototype))
    15.                             _registeredPrefabsRuntimeData.Add(rpd.prefabPrototype, rpd.registeredPrefabs);
    16.                         else
    17.                             _registeredPrefabsRuntimeData[rpd.prefabPrototype].AddRange(rpd.registeredPrefabs);
    18.                     }
    19.                     registeredPrefabs.Clear();
    20.                 }
    21.  
    22.                 if (_registeredPrefabsRuntimeData.Count != prototypeList.Count)
    23.                 {
    24.                     foreach (GPUInstancerPrototype p in prototypeList)
    25.                     {
    26.                         if (!_registeredPrefabsRuntimeData.ContainsKey(p))
    27.                             _registeredPrefabsRuntimeData.Add(p, new List<GPUInstancerPrefab>());
    28.                     }
    29.                 }
    30. #if UNITY_EDITOR
    31.             }
    32. #endif
    33.  
    34.             if (runtimeDataList == null)
    35.                 runtimeDataList = new List<GPUInstancerRuntimeData>();
    36.             if (runtimeDataDictionary == null)
    37.                 runtimeDataDictionary = new Dictionary<GPUInstancerPrototype, GPUInstancerRuntimeData>();
    38.  
    39.             GPUInstancerRuntimeData runtimeData = InitializeRuntimeDataForPrefabPrototype(prototype);
    40.             GPUInstancerUtility.InitializeGPUBuffer(runtimeData);
    41.         }
    And an override in GPUICrowdManager.cs:

    Code (CSharp):
    1.  
    2. public override void InitializeRuntimeDataAndBuffersForPrototype(GPUInstancerPrefabPrototype prototype, bool forceNew = true)
    3.         {
    4.             base.InitializeRuntimeDataAndBuffersForPrototype(prototype, forceNew);
    5.  
    6.             GPUICrowdPrototype crowdPrototype = prototype as GPUICrowdPrototype;
    7.  
    8.             if (!crowdPrototype.animationData)
    9.                 return;
    10.             GPUICrowdRuntimeData runtimeData = (GPUICrowdRuntimeData)GetRuntimeData(prototype);
    11.             foreach (GPUICrowdPrefab instance in _registeredPrefabsRuntimeData[prototype])
    12.             {
    13.                 if (instance != null)
    14.                 {
    15.                     instance.SetupPrefabInstance(runtimeData, forceNew);
    16.  
    17.                     if (instance.childCrowdPrefabs != null)
    18.                     {
    19.                         foreach (GPUICrowdPrefab childInstance in instance.childCrowdPrefabs)
    20.                         {
    21.                             childInstance.SetupPrefabInstance(GetRuntimeData(childInstance.prefabPrototype));
    22.                         }
    23.                     }
    24.                 }
    25.             }
    26.         }
    27.  
     
    Last edited: Jan 3, 2022
  49. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    513
    Hello,
    So we're getting close. We still have some artifacts happening though, I hoped you could direct us here.
    The most problematic is that we have a strange high frequency flickering that alternate between normal renders and upside down ones.
    crowdUpsideDownFlicker.JPG

    Secondly if we enable frustrum culling then there is a high delay (from several seconds to a minute) before the crowd get updated. Here for instance the camera looks at the crowd, it then appears as in the previous screenshot several seconds later.

    FrustrumDelay.JPG

    Also we deactived the probes because the crowd is a bit around the place. However regardless of that the crowd seems very dark and unlit.

    Thanks for your answers.
    Best,
     
  50. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi Chan,
    and thank you for the feedback.
    We will look into adding an example for runtime prototype definition, and make improvements on the API methods related to this.

    Hi there,
    I was unable to understand the issue from the screenshots and the description. Can you please email us a sample project showing these issues so that we can investigate?
     
    chadfranklin47 likes this.