![]() |
GeneratePhysicRepresentationForMesh causing slow down - 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: GeneratePhysicRepresentationForMesh causing slow down (/thread-1355.html) |
GeneratePhysicRepresentationForMesh causing slow down - BetaJester - 09-09-2019 Hi there I've got a simulation where we create Obi Cloth balloons which move around the screen. However, whenever we spawn a new bubble and use GeneratePhysicRepresentationForMesh we're getting significant slow down. For reference we call: Code: yield return balloon.GetComponent<ObiCloth>().GeneratePhysicRepresentationForMesh(); I've tried threading the code, but GeneratePhysicRepresentationForMesh needs to be on the main thread. Is there a way it is meant to be used which means it has a minimal performance hit? - BetaJester RE: GeneratePhysicRepresentationForMesh causing slow down - josemendez - 09-09-2019 (09-09-2019, 07:45 AM)BetaJester Wrote: Hi there Hi! GeneratePhysicRepresentationForMesh is a coroutine that returns a completion percentage. As such, at runtime it is supposed to be used together with some sort of "loading bar" or UI feedback. It is a very resource intensive process that can take quite a while to get done. If you want to create balloons at runtime, best approach is to either have them pre-generated as prefabs, or if you need to use procedural generation, generate one (or several variations) at the beginning of your scene, then instantiate copies of them. RE: GeneratePhysicRepresentationForMesh causing slow down - BetaJester - 09-09-2019 (09-09-2019, 07:52 AM)josemendez Wrote: Hi! Right okay If I create an object in the Scene view, initialise the Obi Cloth, and then create it as a prefab, if I instantiate the prefab at runtime, will the physics work if I don't call GeneratePhysicRepresentationForMesh? RE: GeneratePhysicRepresentationForMesh causing slow down - josemendez - 09-09-2019 (09-09-2019, 10:52 AM)BetaJester Wrote: Right okay Of course, that's what prefabs are meant to be used for. What GeneratePhysicRepresentationForMesh() does is re-create the entire particle-and-constraint representation of a mesh from scratch. This is very expensive and generally not supposed to be done at runtime unless you're generating entirely procedural actors. A prefab already contains all this information in serialized form. So you simply instantiate it, assign it to a solver, and you're done. Excerpt from the manual: Quote:Most of the time actors can be created in the editor, turned into a prefab and instantiated at runtime. However there are situations where creating actors entirely trough code is needed (e.g. procedural level generation). [...goes on to explain how this is done...]http://obi.virtualmethodstudio.com/tutorials/scriptingactors.html RE: GeneratePhysicRepresentationForMesh causing slow down - BetaJester - 09-09-2019 (09-09-2019, 11:41 AM)josemendez Wrote: Of course, that's what prefabs are meant to be used for. What GeneratePhysicRepresentationForMesh() does is re-create the entire particle-and-constraint representation of a mesh from scratch. This is very expensive and generally not supposed to be done at runtime unless you're generating entirely procedural actors. Great stuff, I was trying to do this with in-scene prototypes, but that was causing an issue where the physics wouldn't work. I will try this and report back |