Search Unity

Question Problem processing bones from Skinned Mesh Renderer

Discussion in 'Graphics for ECS' started by AMeyers624, Apr 5, 2023.

  1. AMeyers624

    AMeyers624

    Joined:
    Oct 4, 2016
    Posts:
    2
    Hello,

    I'm stumped by something right now. It may not be ECS related, but I don't know any better place to seek advice.

    In a nutshell, I'm trying to animate a character I've imported from a third party tool. I was inspired by something I noticed in the HDRP Samples, specifically the MeshDeformations scene. They have a process in a baking system where they take the root-bone of a skinned mesh render and use that to create components to slap onto the entities that make up the bones. It comes down to one method they call, SystemBase.GetEntity().

    In the example, they call that method several times.

    Code (CSharp):
    1.         var bakingSystem = World.GetExistingSystemManaged<BakingSystem>();
    2.         var ecb = new EntityCommandBuffer(Allocator.TempJob);
    3.  
    4.         Entities.ForEach((Entity entity, in DeformationSampleData deformMesh) =>
    5.         {
    6.             // Only execute this if we have a valid skinning setup
    7.             var renderer = deformMesh.SkinnedMeshRenderer.Value;
    8.             var bones = renderer.bones;
    9.             var hasSkinning = bones.Length > 0 && renderer.sharedMesh.bindposes.Length > 0;
    10.             if (hasSkinning)
    11.             {
    12.                 // Setup Reference to root
    13.                 var rootBone = renderer.rootBone ? renderer.rootBone : renderer.transform;
    14.                 var rootEntity = bakingSystem.GetEntity(rootBone);
    15.                 ecb.AddComponent(entity, new RootEntity { Value = rootEntity });
    16.  
    17. ....
    18.  
    I've started a project in 2022.2.13f1, added the ECS packages as suggested by the HDRP sample page, imported my character, and now I'm trying to make my bakers. I've basically wanted to go line for line with sample, but when I try to call the systemBase.GetEntity(), it's inaccessible due to the protection level.

    Now, I'm not an expert at programming, and I can muttle my way through some problems with references and dependencies, but this has got me confused. Even the documentation on the website doesn't clearly list GetEntity as a method for SystemBase.

    What magic trickery they pulling here? How are they able to use this method in the samples but I can't use it myself?

    Now, if I'm just barking up the wrong tree, could someone provide me a suggestion or example of how I could start slapping some components on all the bones to this character. At this point, I was debating on writing an authoring script for each bone, but I still need an effective way to put them in a buffer for that character.

    Please and thank you.
     
  2. LeFlop2001

    LeFlop2001

    Joined:
    Jan 30, 2020
    Posts:
    11
    Im no expert but this looks like rather old code when runtime authoring was still supported. I see no other explanation for getting a bakingsystem inside a system. You can hower access all data of a gameobject (including its children) inside an authoring component (no need for per child component) and add them to an entity buffer.