Help Set Cloth Properties with script - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Cloth (https://obi.virtualmethodstudio.com/forum/forum-2.html) +--- Thread: Help Set Cloth Properties with script (/thread-2853.html) |
Set Cloth Properties with script - orestissar - 08-04-2021 Hello, Im currently trying to create and assign a skinned cloth blueprint to some cloth parts i have in my scene. I have succesfully managed to do this but im having some issues setting the cloth properties values with the script (skin backstop, backstopradius, radius). Code: blueprint.inputMesh = mesh; I found this relevant topic: http://obi.virtualmethodstudio.com/forum/thread-2405.html but i cant make it work. So, how do i manage that? thanks beforehand! RE: Set Cloth Properties with script - josemendez - 09-04-2021 Hi! Only change needed for newer versions is that the first batch is accessed like this: Code: var skinBatch = skinConstraints.batches[0]; instead of Code: var skinBatch = skinConstraints[0]; Other than that, everything is exactly the same, it should just work. Keep in mind that you have to iterate trough all constraints, if you wish to set the values for *all* of them: Code: for (int i = 0; i < skinBatch.constraintCount; ++i) Let me know if you have trouble with it. cheers! RE: Set Cloth Properties with script - orestissar - 09-04-2021 Hey again, and thanks for the reply. The code below gives me this error in console: NullReferenceException: Object reference not set to an instance of an object CreateObiBP.Start () (at Assets/Shirt and Pants/Shirt/CreateObiBP.cs:36) Code: var skinBatch = skinConstraints.batches[0]; Also, im not sure i understand the exactly logic behind the iteration below. Code: for (int i = 0; i < skinBatch.constraintCount; ++i) RE: Set Cloth Properties with script - josemendez - 09-04-2021 (09-04-2021, 11:07 AM)orestissar Wrote: Hey again, and thanks for the reply. If line 36 in your script is that one, it means skinConstraints is null. This can only be null if: a) your blueprint hasn't been generated yet. Not initialized --> no constraints. b) your blueprint is not a ObiSkinnedClothBlueprint. Check the manual for info on how to create and generate a blueprint at runtime: http://obi.virtualmethodstudio.com/tutorials/scriptingactors.html (09-04-2021, 11:07 AM)orestissar Wrote: Also, im not sure i understand the exactly logic behind the iteration below. Cloth is made of particles, generally one per vertex. Each particle in the cloth has one skin constraint, that restricts its range of movement relative to the skinned mesh. If you don't iterate trough them all, you're setting values just for one of them. RE: Set Cloth Properties with script - orestissar - 09-04-2021 (09-04-2021, 11:14 AM)josemendez Wrote: Cloth is made of particles, generally one per vertex. Each particle in the cloth has one skin constraint, that restricts its range of movement relative to the skinned mesh. If you don't iterate trough them all, you're setting values just for one of them.ok i understand now, tnx. regarding the other thing: my code is this: Code: public class CreateObiBP : MonoBehaviour RE: Set Cloth Properties with script - josemendez - 09-04-2021 Code: blueprint.Generate(); This is a coroutine (as evidenced by its IEnumerator return type). Like all coroutines, you need to use StartCoroutine() and wait for it to finish. Calling it directly like in your code does nothing. From the code samples found in the manual page I linked to in the previous message: Code: yield return StartCoroutine(blueprint.Generate()); Also, see: https://docs.unity3d.com/Manual/Coroutines.html cheers, RE: Set Cloth Properties with script - orestissar - 09-04-2021 (09-04-2021, 11:39 AM)josemendez Wrote:oooh! thanks! i think i fixed it ! thank you so much! im kind of new to unity so i do this kind of mistakes. Is there a way to actually save the generated blueprint ? RE: Set Cloth Properties with script - josemendez - 09-04-2021 (09-04-2021, 11:54 AM)orestissar Wrote: oooh! thanks! i think i fixed it ! thank you so much! im kind of new to unity so i do this kind of mistakes. No worries! Keep in mind that Obi is quite complex, so it might take you a while to get used to it. (09-04-2021, 11:54 AM)orestissar Wrote: Is there a way to actually save the generated blueprint ? Yes, blueprints are just assets (ScriptableObjects) so you can save the usual way it's done in Unity. See: https://docs.unity3d.com/ScriptReference/AssetDatabase.CreateAsset.html https://docs.unity3d.com/ScriptReference/AssetDatabase.SaveAssets.html RE: Set Cloth Properties with script - orestissar - 09-04-2021 (09-04-2021, 11:58 AM)josemendez Wrote: No worries! Keep in mind that Obi is quite complex, so it might take you a while to get used to it.i think i made it work! thank you again so much! RE: Set Cloth Properties with script - josemendez - 09-04-2021 You're welcome . Don't hesitate to ask if you need help. |