Obi Official Forum
Add cloth and runtime - 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: Add cloth and runtime (/thread-2319.html)



Add cloth and runtime - renderlux - 17-06-2020

I'm trying to add ObiSkinnedCloth and reference skinnedClothBlueprint 

var gameObj = meshObject.AddComponent<ObiSkinnedCloth>();
gameObj.skinnedClothBlueprint = ScriptableObject.Instantiate(SourceBlueprint.instance.sourceTop);
meshObject.AddComponent<ObiSkinnedClothRenderer>();


But I'm getting 

NullReferenceException: Object reference not set to an instance of an object

I believe the problem is:

gameObj.skinnedClothBlueprint = ScriptableObject.Instantiate(SourceBlueprint.instance.sourceTop);


RE: Add cloth and runtime - josemendez - 17-06-2020

(17-06-2020, 03:54 PM)renderlux Wrote: I'm trying to add ObiSkinnedCloth and reference skinnedClothBlueprint 

var gameObj = meshObject.AddComponent<ObiSkinnedCloth>();
gameObj.skinnedClothBlueprint = ScriptableObject.Instantiate(SourceBlueprint.instance.sourceTop);
meshObject.AddComponent<ObiSkinnedClothRenderer>();


But I'm getting 

NullReferenceException: Object reference not set to an instance of an object

I believe the problem is:

gameObj.skinnedClothBlueprint = ScriptableObject.Instantiate(SourceBlueprint.instance.sourceTop);

Well, this can only mean SourceBlueprint, SourceBlueprint.instance or SourceBlueprint.instance.sourceTop are null. I can't possibly know which one. Try debugging your code by placing a breakpoint at that line, and check what's raising the null ref exception.


RE: Add cloth and runtime - renderlux - 18-06-2020

Hi 

This looks like it works (no errors) 

Code:
myMesh.AddComponent<ObiSkinnedCloth>();
             
ObiSkinnedCloth cloth = myMesh.GetComponent<ObiSkinnedCloth>();

cloth.skinnedClothBlueprint = ScriptableObject.Instantiate(sourceTop);


and I create Solver in Start() 

Code:
GameObject solverObject = new GameObject("solver", typeof(ObiSolver), typeof(ObiFixedUpdater));
        ObiSolver solver = solverObject.GetComponent<ObiSolver>();
        ObiFixedUpdater updater = solverObject.GetComponent<ObiFixedUpdater>();

        updater.solvers.Add(solver);

But the physics don't work  Triste


RE: Add cloth and runtime - josemendez - 18-06-2020

(18-06-2020, 10:12 AM)renderlux Wrote: Hi 

This looks like it works (no errors) 

Code:
myMesh.AddComponent<ObiSkinnedCloth>();
             
ObiSkinnedCloth cloth = myMesh.GetComponent<ObiSkinnedCloth>();

cloth.skinnedClothBlueprint = ScriptableObject.Instantiate(sourceTop);


and I create Solver in Start() 

Code:
GameObject solverObject = new GameObject("solver", typeof(ObiSolver), typeof(ObiFixedUpdater));
        ObiSolver solver = solverObject.GetComponent<ObiSolver>();
        ObiFixedUpdater updater = solverObject.GetComponent<ObiFixedUpdater>();

        updater.solvers.Add(solver);

But the physics don't work  Triste

Is the cloth inside (the hierarchy of) a solver? It won't simulate otherwise.
Does it have a ObiSkinnedClothRenderer component? the cloth mesh won't be updated according to the simulation if it doesn't.


RE: Add cloth and runtime - renderlux - 18-06-2020

(18-06-2020, 10:14 AM)josemendez Wrote: Is the cloth inside (the hierarchy of) a solver? It won't simulate otherwise.
Does it have a ObiSkinnedClothRenderer component? the cloth mesh won't be updated according to the simulation if it doesn't.

Hi 

I'm adding the component :

meshObject.AddComponent<ObiSkinnedClothRenderer>();

Do I need to do anything else?

Like link ObiSkinnedCloth with ObiSkinnedClothRenderer ?


RE: Add cloth and runtime - josemendez - 18-06-2020

(18-06-2020, 02:34 PM)renderlux Wrote: Hi 

I'm adding the component :

meshObject.AddComponent<ObiSkinnedClothRenderer>();

Do I need to do anything else?

Like link ObiSkinnedCloth with ObiSkinnedClothRenderer ?

Your cloth needs to be a child of the solver object.

Can you share you entire cloth instantiation code? this way I can tell what's missing more easily.