Search Unity

[RELEASED] GPU Instancer - Crowd Animations

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

  1. gekidoslair

    gekidoslair

    Joined:
    Sep 7, 2012
    Posts:
    128
    Just bought both GPU instancer and the crowd animations packs and I'm getting the 'specified cast is not valid' exception that some others have mentioned on the demo scenes for the crowd system:

    I'm in 2021.2.7f1 / HDRP 12.1.2 - just opening the CrowdAnimationsDemoScene.unity scene throws this:

    Code (CSharp):
    1. InvalidCastException: Specified cast is not valid.
    2. GPUInstancer.CrowdAnimations.GPUICrowdManager.Start () (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:68)
    With this scene open if I click 'Bake Animations for All' I get additional exceptions, one per prototype it seems - it runs through the prototype, and it seems like when it tries to save the animation bake it throws an exception:

    Code (CSharp):
    1. System.InvalidCastException: Specified cast is not valid.
    2.   at GPUInstancer.CrowdAnimations.GPUICrowdAnimationBaker.AnimationBakerFinish () [0x0000e] in D:\projects\WideAwake-SourceAssets\Lookdev\Lookdev.CrowdTest\Assets\GPUInstancer-CrowdAnimations\Scripts\Editor\GPUICrowdAnimationBaker.cs:488
    3. UnityEngine.Debug:LogError (object)
    4. GPUInstancer.CrowdAnimations.GPUICrowdAnimationBaker:AnimationBakerFinish () (at Assets/GPUInstancer-CrowdAnimations/Scripts/Editor/GPUICrowdAnimationBaker.cs:564)
    5. GPUInstancer.CrowdAnimations.GPUICrowdAnimationBaker:AnimationBakerUpdate () (at Assets/GPUInstancer-CrowdAnimations/Scripts/Editor/GPUICrowdAnimationBaker.cs:459)
    6. UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
    If I then hit 'play' on the scene it throws this error once per frame:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. GPUInstancer.CrowdAnimations.GPUICrowdManager.UpdateAnimatorsData (GPUInstancer.CrowdAnimations.GPUICrowdRuntimeData runtimeData) (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:512)
    3. GPUInstancer.CrowdAnimations.GPUICrowdManager.LateUpdate () (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:252)
    Ideas?
     
    Last edited: Jan 7, 2022
  2. gekidoslair

    gekidoslair

    Joined:
    Sep 7, 2012
    Posts:
    128
    Just did a fresh install into a 2020.3.25f1 / HDRP 10.7 project and everything seems fine. Will try a clean 2021 project again just to dbl check that I didn't do something wrong...
     
  3. gekidoslair

    gekidoslair

    Joined:
    Sep 7, 2012
    Posts:
    128
    ok fresh import seems fine - last time I imported both at once, something must have gone wrong - did each package one at a time and tested and seems good so far!
     
  4. gekidoslair

    gekidoslair

    Joined:
    Sep 7, 2012
    Posts:
    128
    Hey there
    I'm trying to get GPU instancer to work with a custom shader written in Amplify - I have added the GPUI Crowd ASE Setup node to my graph, but when the shader compiles it throws this error:

    Code (CSharp):
    1.  
    2. Shader error in 'ActorCore': unrecognized identifier 'appdata_full' at Assets/GPUInstancer-CrowdAnimations/Shaders/Include/GPUICrowdInclude.cginc(18) (on d3d11)
    3. Compiling Vertex program with PROCEDURAL_INSTANCING_ON _ALPHATEST_ON _BLENDMODE_OFF _DOUBLESIDED_ON
    4. Platform defines: SHADER_API_DESKTOP UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_PASS_SHADOWCASTER UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS
    5. Disabled keywords: GPUI_CA_BINDPOSEOFFSET GPUI_CA_TEXTURE INSTANCING_ON SHADER_API_GLES30 UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA UNITY_ENABLE_NATIVE_SHADOW_LOOKUPS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_VIRTUAL_TEXTURING _BLENDMODE_ADD _BLENDMODE_ALPHA _BLENDMODE_PRE_MULTIPLY _SURFACE_TYPE_TRANSPARENT
    I'm in 2021.2.8f1 Unity - HDRP 12.1.13
    Amplify version: v1.8.9 rev 34
    GPU Instancer : v1.7
    GPU Instancer Crowd : v1.1.1

    Ideas?
     

    Attached Files:

    Last edited: Jan 21, 2022
  5. GurhanH

    GurhanH

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

    Can you please follow these steps and see if it solves the issue:

    1- Double click on the GPUI Crowd ASE Setup node to open it
    2- Go to "Additional Directives" under Graph Properties
    3- Change the file from the first Include directive from "GPUICrowdInclude" to "GPUICrowdSkinning"
    4- Save the changes to the node and also save your shader to apply the changes

    It should look like this:
    upload_2022-1-20_15-55-37.png
     
  6. gekidoslair

    gekidoslair

    Joined:
    Sep 7, 2012
    Posts:
    128
    That worked (to fix the shader compile error) - will report back once I get the crowd spawning! Thanks for the quick response!
     
  7. gekidoslair

    gekidoslair

    Joined:
    Sep 7, 2012
    Posts:
    128
    (sorry me again)

    Trying to bake animations, I'm getting this exception:

    Code (CSharp):
    1. System.NullReferenceException: Object reference not set to an instance of an object
    2.   at GPUInstancer.CrowdAnimations.GPUICrowdAnimationBaker.AnimationBakerStart () [0x00383] in D:\projects\OpenWorld\OpenWorld.Client\Assets\GPUInstancer-CrowdAnimations\Scripts\Editor\GPUICrowdAnimationBaker.cs:222
    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.  
    Thoughts?
     
    Last edited: Jan 22, 2022
  8. gekidoslair

    gekidoslair

    Joined:
    Sep 7, 2012
    Posts:
    128
    Does GPU instancer work with prefab variants? Or does it always need to be original prefabs?
     
  9. dearsky

    dearsky

    Joined:
    Jan 27, 2019
    Posts:
    10
    Hello, I use "DisableInstancingForInstance" to hide some models. But they will be enabled again when I use "RegisterPrefabInstanceList" to add some other new models. Is there any ways to solve it?
     
  10. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    This might be caused by a missing bone transform. Crowd Manager uses to bone transform hierarchy to bake the animations. One of the referenced bones of the Skinned Mesh might be missing.

    Yes it works with prefab variants. However you should take care not to use both the original prefab and the variant as a prototype so that the prototype references does not conflict (you can see it from the attached script on the prefab).

    Hi there,
    Try using myManager.AddPrefabInstances() instead of RegisterPrefabInstanceList, and do not re-initialize the manager afterwards. When the manager is re-initialized it will enable the disabled instances.
    Another method is to use the RemovePrefabInstance API method instead of the DisableInstancingForInstance. If you want to add it back later you can use the AddPrefabInstance method. This way they will not be re-enabled when the manager is initialized.
     
  11. dearsky

    dearsky

    Joined:
    Jan 27, 2019
    Posts:
    10
    upload_2022-1-25_9-14-14.png Hello, I tried to use AddPrefabInstances(), but that caused errors when I played animations. It seems AddPrefabInstances() doesn't initialize the crowdAnimator.
     
  12. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    thank you for reporting this issue.
    This method needs to call the prefabInstance.SetupPrefabInstance(runtimeData, true); method for each prefab instance. We fix it with the next update. If you can email us with your invoice no we can send you the modified file.
     
  13. eggsamurai

    eggsamurai

    Joined:
    Oct 10, 2015
    Posts:
    115
    seems broken in 2021.2.8 2021.2.9
     
  14. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    There is a shader compiler bug in the new Unity versions where Unity is arbitrarily stripping the procedural instancing shader variants from builds. Hopefully Unity will fix this soon.

    We are looking into providing a workaround for Crowd Animations. For now I recommend not to upgrade to Unity 2021.2.8 or newer.
     
    pdinklag and eggsamurai like this.
  15. dearsky

    dearsky

    Joined:
    Jan 27, 2019
    Posts:
    10
    upload_2022-2-7_9-13-21.png Hello, I have replace the modified file and AddPrefabInstances() runs well. But the console throws new errors when I run RemovePrefabInstances().
     
  16. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    Please use the RemovePrefabInstance method for removing, RemovePrefabInstances method expects an ordered list which is used for faster calculations on specific cases.
    You can iterate over your list and call the RemovePrefabInstance method as such:
    Code (CSharp):
    1. for (int i = 0; i < instancesToRemove.Count; i++)
    2. {
    3.     GPUInstancerAPI.RemovePrefabInstance(crowdManager, instancesToRemove[i], false);
    4. }
     
  17. eggsamurai

    eggsamurai

    Joined:
    Oct 10, 2015
    Posts:
    115
    Hi,
    2021.2.11 is still broken.. I had submit bug report but got no replay...
    Sign.. mnad
     
  18. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    229
    Hello again, when using the synchronous bone transform updating I notice a frame delay between the animation and the transform positions. I tried fixing it myself with no luck. Could you take a look at this?
     
  19. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    It will be fixed in 2021.2.12f1, according to this forum post.

    Hi Chad,
    Can you please email us a sample project where we can see this issue?
     
    chadfranklin47 and eggsamurai like this.
  20. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    229
    Absolutely, just sent the email to support@gurbu.com. Please let me know if you can see the issue on your end.
     
  21. pdinklag

    pdinklag

    Joined:
    Jan 24, 2017
    Posts:
    154
    I downgraded from 2021.2.8 to 2021.2.7 (it requires changing the package manifest according to the package changes noted in the release notes) and everything works fine in builds again. For those who absolutely need to build before 2021.2.12 (beta testing in my case), this seems like a good workaround.

    Also thanks for noting this here! I was utterly confused about things not working anymore in a build.
     
    GurhanH likes this.
  22. TaylorCaudle

    TaylorCaudle

    Joined:
    Feb 8, 2018
    Posts:
    158
    I have a question regarding this, im basically looking to find a solution for huge crowd sims, or at least big crowd Serious Sam-style battles, using some low-poly/LOD based enemies, and was wondering exactly how this can be used, or if, for enemies with lots of scripts on them.

    I'm using Invector as a base for my AI enemies, and im struggling to understand how this would work with that- for instance i have a single animator for all my enemies, and a Forward State Machine that controls AI decisions, would that still work here?

    Would it basically just disable the Skinned Mesh deformations themselves, and instance the Animations in the material shader itself? And for things like "melee weapons" in the skeleton hierachy, would the enemies still be able to use objects in the "hand bones," even if the skinned mesh vertices arent actually being deformed by the bones?
     
  23. GurhanH

    GurhanH

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

    There are 2 animator workflows you can choose from: Mecanim Animator Workflow and Crowd Animator Workflow. If you are using a custom animator system, you will need to replace it with Crowd Animator using the GPUICrowdAPI.

    Crowd Animations works by disabling the Skinned Mesh Renderer component and making DrawMeshInstancedIndirect calls instead. GPU Skinning is handled by Compute Shaders and applied inside the material shader. You can see how to make your shaders compatible from this documentation.

    Bone attachments can be used by enabling "Bone Updates" option and then selecting which bones you wish to be updated. You can select between synchronous (runs in CPU) and asynchronous (read from GPU with latency) modes.
     
  24. TaylorCaudle

    TaylorCaudle

    Joined:
    Feb 8, 2018
    Posts:
    158

    Hey thanks! My issue is that i have a ton of scripts that do trigger different animations, like Attacks, Dialogue, Mocap etc. As well as SEVERAL objects in the skeleton hierarchy, such as holders for weapons, hitboxes, flammable colliders, and a bunch of other things.

    Would this asset be compatible with all that? Or is it mostly just for very simple characters that dont have very complicated A.I., i.e. background characters. I'm looking mainly for something that will let me instance the meshes for a TON of A.I Enemies, that still work with their various scripts, etc.

    Some animations use RootMotion, others don't, and they have custom StateMachine scripts that do different things like "Trigger Sounds" at different points, etc.
    I'm basically wanting to keep the animator functions intact, but GPU instance the meshes themselves, so it would be a bunch of skeletons moving without a visible SkinnedMesh Renderer, while the GPU Instancing handles the "visible mesh shader" stuff


    EDIT: Ah, i see that Animation layers arent supported. I do have several of those, so I guess this won't work. Is there a workflow you recommend for some simple A.I. enemies that can be fought, using this asset? I'm basically trying to create a huge wave of simple enemies that can be destroyed/interacted with, even if I have to use a different A.I system for those types of enemies.
     
    Last edited: Feb 17, 2022
  25. NemesisWarlock

    NemesisWarlock

    Joined:
    Jan 21, 2017
    Posts:
    141
    Okay, this seemed to be the perfect plugin for my team's use, as we've got a bunch of animated characters we need to optimize, but, even though the system seems to support mobile, VR, Vulkan, and URP, The Oculus Quest is specifically not supported?

    Could you please elaborate as to why this is the case?
     
  26. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    This asset is solely for animation purposes so it is not related to AI and there is no limitation for which kind you can use. If you have an AI integrated with an Animator, you either need to use Mecanim Animator or you will need to edit your animator code for using Crowd Animator workflow. Because when using Crowd Animator workflow, the Animator component on the instances will also be disabled.
    The main limiting factors are the baked animation data, and procedural instancing. Because the bone positions are baked in editor, runtime bone modifications (e.g. IK) and animation layers are not supported. But there is still support for animation blending using linear interpolation. And procedural instancing makes it harder to implement instance based variations, for example you will need to write some code to add material variations.

    Yes, a plugin that works with Vulkan and VR in theory should work in Quest but there were issues in various cases which we did not know the reasons for. There are possibly some additional GPU limitations or issues with the engines Quest support and we did not have the time and resources to invest into figuring these out. So for the time being, Oculus Quest is not supported.
     
  27. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Is there some way to use the same baked animations for different variation models?

    Lets say I have a male worker wearing blue pants, and parented to this male worker I have a female worker and 2 other male workers with different appearance. But they all use the exact same animations.

    Is there some support to handle this type of scenario or do I need to bake all animations seperately for each variation? I looked at "Optional Renderers" but its not very well documented. If this is possible, how do I set it up, and can I change the visual at runtime from C#?

    Thanks!
     
  28. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there
    Crowd Animations creates a Scriptable Object that contains the baked data (GPUICrowdAnimationData). If you have multiple prototypes with same skinned meshes and animations, you can use the same animation data for them.
    upload_2022-2-23_16-52-42.png

    You can also define prototypes at runtime with this baked data by using the DefineGameObjectAsCrowdPrototypeAtRuntime API method.

    If you wish to make material variations, you can see an example scene in the package called TextureVariationDemo. And you can see more detailed explanation in this wiki page.

    Optional Renderers are used for enabling/disabling renderers on instances (e.g. having different clothes or hair). You can see an example usage in the OptionalRenderersDemo scene.
     
  29. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    So my scenario where I have several models all with same bones but different meshes:

    - Male 1
    - Male 2
    - Male 3
    - Female 1
    - Female 2

    It does not seem I can re-use the scriptable object from one to the other, is this because its not the exact same model? They share bones, proportions and size.

    Is my only option then to create one prototype for each model? This prototype has 20+ animations so my worry is that this will create a lot of baked textures that I need to keep in memory.

    EDIT: I did find one solution it seems, I simply keep all the models as children on an empty parent animator. I can then toggle between the child models using Optional renderers feature.

    The code below shows an example where I simply toggle between child 0 and 1.

    Code (CSharp):
    1. if (gpuiCrowdManager != null)
    2.             {
    3.                 Dictionary<GPUInstancerPrototype, List<GPUInstancerPrefab>> registeredPrefabsDict = gpuiCrowdManager.GetRegisteredPrefabsRuntimeData();
    4.                 List<GPUInstancerPrefab> prefabList;
    5.                 if (registeredPrefabsDict != null && registeredPrefabsDict.TryGetValue(crowdPrototype, out prefabList))
    6.                 {
    7.                     foreach (GPUICrowdPrefab crowdPrefab in prefabList)
    8.                     {
    9.                         if (crowdPrefab.childCrowdPrefabs[0].gameObject.activeSelf)
    10.                         {
    11.                             crowdPrefab.childCrowdPrefabs[0].gameObject.SetActive(false);
    12.                             crowdPrefab.childCrowdPrefabs[1].gameObject.SetActive(true);
    13.                         }
    14.                         else
    15.                         {
    16.                             crowdPrefab.childCrowdPrefabs[1].gameObject.SetActive(false);
    17.                             crowdPrefab.childCrowdPrefabs[0].gameObject.SetActive(true);
    18.                         }
    19.                     }
    20.                 }
    21.             }
    This seems to work perfectly, is there any reason I shouldnt do this?
     
    Last edited: Feb 23, 2022
  30. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    This is a valid usage. But it would be better to use your own GO references for enabling/disabling instead of the "childCrowdPrefabs". Since this is an internal reference, there might be changes in the future.
     
  31. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    yeah makes sense, thanks!
     
    Last edited: Feb 24, 2022
  32. mochenghh

    mochenghh

    Joined:
    Jun 10, 2021
    Posts:
    26
    Im using Crowd animation
    the model has hair on head and Hair is just normal Mesh render not the skinmeshRender.
    And It is still be rendered out of the camera.I find normal mesh render works correct in GPUI,How can I set the normal Mesh render being hidden (not render) like skinmeshRender
     

    Attached Files:

  33. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    Crowd Manager only renders the Skinned Mesh Renderers within a prototype. For regular (non-skinned) Mesh Renderers, you use the Prefab Manager. In your case, you can create a nested prefab for the hair and add it to a Prefab Manager, and enable Auto. Update Transform Data option. Then they will also be rendered with GPUI.
     
  34. mochenghh

    mochenghh

    Joined:
    Jun 10, 2021
    Posts:
    26
    Is there any way to Add GPUICrowdPrefab At runtime?
     
  35. mochenghh

    mochenghh

    Joined:
    Jun 10, 2021
    Posts:
    26
    Hi My friend I need your help again, I just ReWrite some of Crowd code to make it Add Skinmesh at run time
    Just Rewrite AddInstancesToPrefabPrototypeAtRuntime, There is the code
    Code (CSharp):
    1. public void AddInstancesToCrowdPrototypeAtRuntime(GPUICrowdPrototype prefabPrototype, GameObject singleInstance = null, IEnumerable<GameObject> instances = null)
    2.         {
    3.  
    4.             if (!Application.isPlaying)
    5.             {
    6.                 Debug.LogWarning("AddInstancesToPrefabPrototypeAtRuntime method is designed to use at runtime. Adding instances canceled.");
    7.                 return;
    8.             }
    9.  
    10.             if (isActiveAndEnabled)
    11.             {
    12.                 List<GPUInstancerPrefab> instanceList;
    13.                 if (!_registeredPrefabsRuntimeData.TryGetValue(prefabPrototype, out instanceList))
    14.                 {
    15.                     instanceList = new List<GPUInstancerPrefab>();
    16.                     _registeredPrefabsRuntimeData.Add(prefabPrototype, instanceList);
    17.                 }
    18.  
    19.  
    20.  
    21.                 GPUICrowdPrefab prefabInstance;
    22.                 foreach (GameObject instance in instances)
    23.                 {
    24.                     prefabInstance = instance.GetComponent<GPUICrowdPrefab>();
    25.                     if (prefabInstance == null)
    26.                     {
    27.                         prefabInstance = instance.AddComponent<GPUICrowdPrefab>();
    28.                         prefabInstance.prefabPrototype = prefabPrototype;
    29.                     }
    30.                     if (prefabInstance != null && !instanceList.Contains(prefabInstance))
    31.                         instanceList.Add(prefabInstance);
    32.  
    33.                 }
    34.                
    35.                 GPUInstancerRuntimeData runtimeData = InitializeRuntimeDataForPrefabPrototype(prefabPrototype, 0);
    36.                 Profiler.BeginSample("Mymmm");
    37.  
    38.                 GPUInstancerUtility.InitializeGPUBuffer(runtimeData);
    39.                 Profiler.EndSample();
    40.  
    41.                
    42.                 InitializeRuntimeSingleDataAndBuffers(prefabPrototype);
    43.  
    44.  
    45.  
    46.             }
    47.             else
    48.             {
    49.                 if (registeredPrefabs == null)
    50.                     registeredPrefabs = new List<RegisteredPrefabsData>();
    51.  
    52.                 RegisteredPrefabsData data = null;
    53.                 foreach (RegisteredPrefabsData item in registeredPrefabs)
    54.                 {
    55.                     if (item.prefabPrototype == prefabPrototype)
    56.                     {
    57.                         data = item;
    58.                         break;
    59.                     }
    60.                 }
    61.                 if (data == null)
    62.                 {
    63.                     data = new RegisteredPrefabsData(prefabPrototype);
    64.                     registeredPrefabs.Add(data);
    65.                 }
    66.  
    67.                 GPUICrowdPrefab prefabInstance;
    68.                 foreach (GameObject instance in instances)
    69.                 {
    70.                     prefabInstance = instance.GetComponent<GPUICrowdPrefab>();
    71.                     if (prefabInstance == null)
    72.                     {
    73.                         prefabInstance = instance.AddComponent<GPUICrowdPrefab>();
    74.                         prefabInstance.prefabPrototype = prefabPrototype;
    75.                     }
    76.                     if (prefabInstance != null && !data.registeredPrefabs.Contains(prefabInstance))
    77.                         data.registeredPrefabs.Add(prefabInstance);
    78.                 }
    79.  
    80.             }
    81.  
    82.         }
    everything works correct, but I found
    GPUInstancerUtility.InitializeGPUBuffer(runtimeData);
    cost really expensive, and It dont cost that mush in original
     AddInstancesToPrefabPrototypeAtRuntime
    ,So is there any why to fix up?
     

    Attached Files:

  36. look001

    look001

    Joined:
    Mar 23, 2017
    Posts:
    111
    Hey there, the Android Demo crashes on my phone when adding more instances (Samsung Galaxy s10). Can I expect it to work on Android?
     
  37. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    We did not see any crashes during our tests. If you can make a bug report with the crash logs we can investigate.
     
    look001 likes this.
  38. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Hello, is there a way to register character prefabs with different permutations of body parts at runtime? I have a spawner script that assembles randomized characters from different sets of body parts. For example, for ancient soldiers, there could be a
    (Naked body)(Bronze cuirass)(Bronze Greaves)
    or a
    (Naked body)(Iron chainmail)
    soldier, where each parenthesis is a mesh.
    Groups of randomized characters all share the same animation clips. If no runtime API exists for me to write a script to feed any possible permutations into the registration system, then the alternative is to manually convert every single [Mesh, Mesh, Mesh..., Animation Clip] permutation, which I'd like to avoid
     
  39. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    You can have a single prefab that contains all the skinned meshes and enable/disable required ones. For this you need to enable the Has Optional Renderers setting and select the meshes you want to enable/disable at runtime. There is also a demo scene called OptionalRenderersDemo which exemplifies this.
     
    Abbrew likes this.
  40. look001

    look001

    Joined:
    Mar 23, 2017
    Posts:
    111
    Can we register new characters that are created completelly procedurally at runtime? (Procedural Mesh)
     
  41. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Thank you. Would the runtime steps be:

    Editor
    1. Create an all-in-one prefab with all possible mesh permutations
    2. Convert it using Has Optional Renderers
    3. Store this converted prefab in the Spawner script
    Runtime
    1. The spawner spawns dozens of the all-in-one prefab
    2. The spawner then iterates through these instances and chooses which meshes to disable. The result is dozens of instances with different meshes chosen from the prefab enabled
    3. Your GPU Instancer handles everything else

    Would there be performance consequences for having a lot of different permutations at runtime? For example, you have 10 different body parts, with each body part choosing from 3 different meshes for a total of 3^10 different permutations? And that would be for a single soldier type. If there are 100 different soldier types, what would be the consequences of that?
     
  42. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Crowd Animations uses various skinned mesh information that is stored during bake and currently baking is only available in editor mode. You can use the same baked data with different prototypes if they have the same bone structure and animations. But if they are different, they need to be baked in editor mode.

    Yes, your runtime steps sounds correct.
    Since you will have a single prototype, the draw calls for every mesh will be batched. So you should not have a performance issue about rendering.
    However, your instantiation might be a bit slower because of the high amount of child GameObjects and you might have slightly more memory usage because of the disabled GameObjects in the scene. But these can be solved with object pooling and destroying unused child GOs respectively. However with only 100 instances, these optimizations might not be necessary depending on the requirements.
     
    Abbrew likes this.
  43. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417

    Is Looping keeps on being checked after I click Bake Animations even though I don't want this animation to loop. Is there something I'm doing wrong?
     
  44. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    Clip settings reset to default values when you Bake Animations, because it removes and recreates them. But I see that it is inconvenient and we will look into making the necessary changes to persist the data in a future update.
     
    Abbrew likes this.
  45. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Sounds good. In the meantime, should I simply never Bake Animations unless I've added a new AnimationClip to the model?
     
  46. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    You need to re-bake when the prefab/model is changed (e.g. modifying bone structure or adding new skinned meshes) or when the animations are changed (e.g. modifying bone positions or adding new animations).

    If your your animation clips have the same "Loop Time" setting with the GPUI's "Is Looping":
    upload_2022-4-11_18-23-28.png

    You can make the following change to set the Is Looping to default to the same value:
    GPUInstancer-CrowdAnimations\Scripts\Editor\GPUICrowdAnimationBaker.cs line 323
    from this:
    Code (CSharp):
    1. isLoopDisabled = 0,
    to this:
    Code (CSharp):
    1. isLoopDisabled = animationClip.isLooping ? 0 : 1,
     
    Abbrew likes this.
  47. aganm

    aganm

    Joined:
    Sep 25, 2019
    Posts:
    114
    Hi!

    I have a first person shooter project which needs more rendering performance, but I use colliders on bones to detect specific body parts hits.

    How one can use crowd animations GPU instancer and have collision detection on the meshes? For example, to detect a headshot, in regular unity I can put a sphere collider on the head bone to detect head shots. Because the collider is attached to the head bone, it will follow the movement of the head, and I can accurately detect a headshot by using the head collider. How could one detect headshots if the animation logic is on the GPU? (not having access to the bones to put colliders on)

    Edit: I have found the answer to my question in a response from 2 years ago. Was there any updates for this use case since then?
     
    Last edited: Apr 14, 2022
  48. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    you can use the Enable Bone Updates option and select the bones that you wish to make collision detections with. Async version reads the bone data from the GPU memory with couple frames latency. Sync version makes the bone calculations in the CPU.
     
  49. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Hello, I'm getting the same error as in [HDRP/Lit] does not support skinning. but with URP. The solution described in the link works however. Could you incorporate this fix into your asset?
     
  50. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    I was not able to reproduce the issue. It might be a version specific issue. Can you please email us detailed information following this guide?