Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add cloth and runtime
#1
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);
Reply
#2
(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.
Reply
#3
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
Reply
#4
(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.
Reply
#5
(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 ?
Reply
#6
(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.
Reply