Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Can I attach particeattachment in script?
#1
Hello! I'm currently trying to add particle attachment component through the script before obi skinnedcloth asset is enabled during play.
The issue that I'm struggling is if I add particle attachment into cloth asset during the play using my script(below), particle attachment doesnt work, just falls until it reaches at pelvis, 
but! if I add particle attachment into same cloth asset before play, particle attachment works well!

both of the cases particle attachment is added into cloth asset well, but the problem is particle attachment doesnt work only if I add it on the cloth asset(object that has obi skinnedcloth component) through the script

<add particle attachment component through inspector before play>
   

<add particle attachment during the play through script>
   

and this is the script I wrote. I tried same part on "OnEnable","Start","Awake" and all of this didnt work.
I tried to add particle attachment component on disabled cloth, then I enable cloth asset, it didnt work. 
Particle attachment worked only I added that component on cloth asset through inspector whether it was play runtime or not. 
 
Code:
  obiSkinnedCloth.gameObject.AddComponent<ObiParticleAttachment>();
            obiSkinnedCloth.GetComponent<ObiParticleAttachment>().target = _clothEnabler._obiSolver.transform.GetChild(1);
//this is the part that I set body as particle attachment's target, and the body has mesh collider and obi collider.
            try
            {
                obiSkinnedCloth.GetComponent<ObiParticleAttachment>().attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
                obiSkinnedCloth.GetComponent<ObiParticleAttachment>().compliance = _clothEnabler._particleCompliance;

            }


is particle attachment something that I cannot add in script during play runtime? Thank you.
Reply
#2
Hi!

Your code doesn't do anything, since it's incomplete: you're not providing a particle group for the attachment to attach. As a result, the attachment doesn't know which part(s) of the cloth it should act upon.

See the manual's page on scripting attachments:
http://obi.virtualmethodstudio.com/manua...ments.html

As a side note, calling GetComponent() every time you want to access a component in Unity is quite expensive. Since you're adding the component yourself, a much better option is to just store it in a variable when you add it.

kind regards
Reply
#3
(12-09-2024, 07:45 AM)josemendez Wrote: Hi!

Your code doesn't do anything, since it's incomplete: you're not providing a particle group for the attachment to attach. As a result, the attachment doesn't know which part(s) of the cloth it should act upon.

See the manual's page on scripting attachments:
http://obi.virtualmethodstudio.com/manua...ments.html

As a side note, calling GetComponent() every time you want to access a component in Unity is quite expensive. Since you're adding the component yourself, a much better option is to just store it in a variable when you add it.

kind regards
Hello! thank you for your reply. I understood the part that you saying the particle attachment component wont work cause there's no blueprint particle group at all. But I cannot understand why there's a difference between adding particle attachment into cloth gameobject through inspector, and just cloth gameobject. 

And about the Getcomponent() dont worry, we just call get component only when we enable cloth. and that happens only few times happends in whole playtime.
Reply
#4
(12-09-2024, 09:20 AM)gahyun11 Wrote: Hello! thank you for your reply. I understood the part that you saying the particle attachment component wont work cause there's no blueprint particle group at all.

Attachments simply won't work without a particle group: you can't attach point A to point B if you don't have point B.

(12-09-2024, 09:20 AM)gahyun11 Wrote: But I cannot understand why there's a difference between adding particle attachment into cloth gameobject through inspector, and just cloth gameobject. 

There's no difference at all, but I don't understand how the attachment can possibly work when added trough the inspector if there's no particle groups defined for the cloth. Can you share a screenshot of the attachment component in the inspector? Does it show a group name in the "particle group" dropdown?

kind regards,
Reply
#5
(12-09-2024, 09:58 AM)josemendez Wrote: Attachments simply won't work without a particle group: you can't attach point A to point B if you don't have point B.


There's no difference at all, but I don't understand how the attachment can possibly work when added trough the inspector if there's no particle groups defined for the cloth. Can you share a screenshot of the attachment component in the inspector? Does it show  a group name in the "particle group" dropdown?

kind regards,
Hello! We are currently controlling StretchScale of distance constraints and Stretch Compliance in runtime. My guess is that is the reason why there 's a diffrence betweem two environments - controlling StretchScale of distance constraints and compliace of obiSkinnedcloth that has no particle attachment in runtime, controlling StretchScale of distance constraints and compliace of obiSkinnedcloth that has no particle attachment in runtime. I tried this two cases with adding particle attachment component before runtime. 

both of cases, StretchScale and stretchCompliance are changed in 1 to 2 seconds after cloth gameobject is enabled. 

this is the screenshot of obi Skinned cloth simulation with adding particle attachment in script during runtime. as you can see, part of waistline of skirt is tugged on pelvis. 
   

this is the screenshot of obi Skinned cloth simulation with adding particle attachment "before runtime".
     



I just tried a little experiment that enabling cloth during runtime, seting their distance constraints with 0.15f. then cloth started to fall , then I added obi particle attachment component to cloth, then cloth stopped falling
   
Reply
#6
(13-09-2024, 02:37 AM)gahyun11 Wrote: guess is that is the reason why there 's a diffrence betweem two environments - controlling StretchScale of distance constraints and compliace of obiSkinnedcloth that has no particle attachment in runtime, controlling StretchScale of distance constraints and compliace of obiSkinnedcloth that has no particle attachment in runtime. I tried this two cases with adding particle attachment component before runtime. 


Hi,

I'm extremely confused now. In your screenshot, the attachment is applied to a particle group named "all". So there clearly are particle groups defined in your cloth blueprint? however you mentioned multiple times that none of your blueprints had particle groups defined?

(06-09-2024, 09:30 AM)gahyun11 Wrote:
All cloth assets blueprints that we have have no particle groups, same as body asset blueprints.

(06-09-2024, 10:56 AM)gahyun11 Wrote:
Like I mentioned, none of them and body blueprint do have particles in thier blueprint but they dont hav any particle groups

(13-09-2024, 02:37 AM)gahyun11 Wrote:
I just tried a little experiment that enabling cloth during runtime, seting their distance constraints with 0.15f. then cloth started to fall , then I added obi particle attachment component to cloth, then cloth stopped falling

This behavior you describe doesn't make any sense to me. When you create an attachment manually in the editor, the default value for the particle group field is "None", and the target object is set to none too. So adding an attachment via the editor interface at runtime should do absolutely nothing unless you set these fields afterwards. You have to set both a target and a particle group for the attachment to work, regardless of it being created in the editor or programmatically. If this is not the behavior you're getting, could you please share a project that reproduces this issue so that I can take a closer look?

kind regards
Reply
#7
(13-09-2024, 07:59 AM)josemendez Wrote:
Hi,

I'm extremely confused now. In your screenshot, the attachment is applied to a particle group named "all". So there clearly are particle groups defined in your cloth blueprint? however you mentioned multiple times that none of your blueprints had particle groups defined?
Hi, I just wrote a code to print how many groups are existing in each cloth blueprints. And except one, every cloth asset has particle groups.... What I heard from our 3d designer, they said there are no particle group in every cloth blueprint assets, and I wrote codes thinking there's no particle group in every asset. it looks like there actually are.... Sorry for misunderstanding. I just started to use obi cloth about lesser than 2 months ago and our 3d designer, they've never used unity or no obi before. 

now I have 3 questions.

1. How can I see generated obi skinned blueprint's groups through unity editor inspector?
I know I can just click "Edit"Button in the generated obi skinned blueprint inspector
   


But if I click "edit" button I see nothing like a screenshot below. I just generated this blueprint and see nothing in screen. It happens occasionally, I still dont know reason.  I clicked "Done" button after I generated bluepriint in blueprint generating scene(I don't know if this is right term but)
   




2. Neither they or I never created any particle groups in all obi skinned cloth's obiskinned blueprint assets, but some of the cloth blueprint have no particle group or 1 particle group with name "all" randomly. Is this normal? Or is this something mistake that we made while using obi?



3. while generating obi blueprint, we need to scale stretch scale and stretch compliance to expand and shrink cloth during runtime, but while this process, cloth should be fixed on waistline(for example). And I understood that, to fix cloth on body, we need to use particle attachment on obi skinned cloth and pin constraint on body, at the same time there has to be a particle group in cloth. I wish our team can set particle group for every cloth asset that we have, but we are running out of time, so we need to figure out where the "waist line" particles are in obi skinned cloth blueprint and how to group them as particle group through the script during the runtime. I could get each particle position of obi skinned cloth blueprint through script using "skinnedClothBlueprint.positions", and stuck to figure out which particles of blueprint are top row paticles or not(please check the screenshot below) so we can set them as a particle group through the blueprint. It looks like every row of particles has same amount particles in obi skinned blueprint after generating blueprint following cloth mesh's triangles. Is there any way to figure out top row particles when obi generates blueprint of skinned cloth? 
   
Reply
#8
(13-09-2024, 09:00 AM)gahyun11 Wrote: 1. How can I see generated obi skinned blueprint's groups through unity editor inspector?
I know I can just click "Edit"Button in the generated obi skinned blueprint inspector

They're right there under "Particle groups". You can click "select" on any of them to select/visualize the particles that are part of that group. You can also select a group and click "Set" to replace the group with the currency selected particles. Here's an example where I created 2 groups:

[Image: O2J3ipS.png]

(13-09-2024, 09:00 AM)gahyun11 Wrote: But if I click "edit" button I see nothing like a screenshot below. I just generated this blueprint and see nothing in screen. It happens occasionally, I still dont know reason.  I clicked "Done" button after I generated bluepriint in blueprint generating scene(I don't know if this is right term but)

Make sure your exported cloth mesh is not extremely small. Seen this issue before with users that export their meshes with a huge scale transform value (100 or 1000) but the actual mesh data is tiny, barely visible unless the scale transform is applied. See this video on the subject:

https://www.youtube.com/watch?v=5j7k_tJUSJc


(13-09-2024, 09:00 AM)gahyun11 Wrote: 2. Neither they or I never created any particle groups in all obi skinned cloth's obiskinned blueprint assets, but some of the cloth blueprint have no particle group or 1 particle group with name "all" randomly. Is this normal? Or is this something mistake that we made while using obi?

Cloth particle groups are not automatically created. Maybe you clicked the "+" sign in the list of particle groups by mistake?

(13-09-2024, 09:00 AM)gahyun11 Wrote: 3. while generating obi blueprint, we need to scale stretch scale and stretch compliance to expand and shrink cloth during runtime, but while this process, cloth should be fixed on waistline(for example). And I understood that, to fix cloth on body, we need to use particle attachment on obi skinned cloth and pin constraint on body, at the same time there has to be a particle group in cloth.

You just need the attachment, and a particle group to specify which particles in the cloth are attached. In your case, the ones around the waist. So you must select the waist particles, and create a particle group out of them.

However since you're using skinned cloth, why not just set the skin radius for those particles to zero, instead of attaching them? this will force them to follow the body's skeletal animation with no room for movement.

(13-09-2024, 09:00 AM)gahyun11 Wrote: I wish our team can set particle group for every cloth asset that we have, but we are running out of time, so we need to figure out where the "waist line" particles are in obi skinned cloth blueprint and how to group them as particle group through the script during the runtime. I could get each particle position of obi skinned cloth blueprint through script using "skinnedClothBlueprint.positions", and stuck to figure out which particles of blueprint are top row paticles or not(please check the screenshot below) so we can set them as a particle group through the blueprint. It looks like every row of particles has same amount particles in obi skinned blueprint after generating blueprint following cloth mesh's triangles. Is there any way to figure out top row particles when obi generates blueprint of skinned cloth? 

You can just pick the particles with a position.Y value largest than the rest, or larger than a specific threshold. Then you can create the group programmatically, using the indices of these particles.

kind regards
Reply
#9
Quote:You can just pick the particles with a position.Y value largest than the rest, or larger than a specific threshold. Then you can create the group programmatically, using the indices of these particles.

kind regards



Hello. Thank you for good explanation. I checked all particles in any specific skirt asset obi skinnedcloth blueprint we have. I got the particle positions as array then arranged them by y position so I can get the hightest particles's position at first  and I realized, positions of the particles in the skirt asset are different even if they look like they are located in same y position, so I checked the skirt mesh and realized, waistline's vertices in the skirt mesh are located in all different height with tiny gap. In this situation, I think in obi skinned cloth blueprint generation process, particles are created in same height if the cloth asset's mesh's vertices are located in same height or mesh's triangles are located in same height. Is this right?

And I succeeded making a partical group adding specific particles into the particle group in script, but everytime I try to check the blueprint by clicking "Edit" button, UI of the inspector is messed! Please check a screenshot below. Did i something wrong?
   

this is my code to create a particle group and add specific indices's particles into the particle group


Code:
clothBlueprint.ClearParticleGroups();
Code:
     
Code:
        if (!clothBlueprint.groups.Find(x => x.name == "waist"))
Code:
        {
Code:
       
Code:
            _waistIndices.AddRange(_editedDemin.positions.Select((b, i) => b.y >= 1 ? i : -1).Where(i => i != -1).ToArray());
Code:
            clothBlueprint.InsertNewParticleGroup("waist", 0);
Code:
            clothBlueprint.groups[0].particleIndices.AddRange(_waistIndices);
Code:
         
Code:
        }
Reply
#10
(Yesterday, 03:03 AM)gahyun11 Wrote: Hello. Thank you for good explanation. I checked all particles in any specific skirt asset obi skinnedcloth blueprint we have. I got the particle positions as array then arranged them by y position so I can get the hightest particles's position at first  and I realized, positions of the particles in the skirt asset are different even if they look like they are located in same y position, so I checked the skirt mesh and realized, waistline's vertices in the skirt mesh are located in all different height with tiny gap.

This might be obvious, but you should *not* rely on the Y values of all waist particles being *exactly* the same. Even if whoever modeled the skirt made the wait perfectly horizontal, vertices won't have the same height due to floating point error. You should pick one representative particle (for instance the topmost one) and then compare all others with it, using a threshold.

(Yesterday, 03:03 AM)gahyun11 Wrote: In this situation, I think in obi skinned cloth blueprint generation process, particles are created in same height if the cloth asset's mesh's vertices are located in same height or mesh's triangles are located in same height. Is this right?

Initial particle positions are just copied from vertex positions. If your vertex weld distance or minimum particle distance are not zero, they might be moved around afterwards to meet these constraints.

(Yesterday, 03:03 AM)gahyun11 Wrote: And I succeeded making a partical group adding specific particles into the particle group in script, but everytime I try to check the blueprint by clicking "Edit" button, UI of the inspector is messed! Please check a screenshot below. Did i something wrong?

Quite possibly, editor UI breaking in this way usually means there's been an error while rendering the editor. Did you add any custom code to the blueprint and/or blueprint editor?

(Yesterday, 03:03 AM)gahyun11 Wrote: this is my code to create a particle group and add specific indices's particles into the particle group

When/how are you calling this code?

kind regards,
Reply