Help Generating emitters on scene programatically - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Fluid (https://obi.virtualmethodstudio.com/forum/forum-3.html) +--- Thread: Help Generating emitters on scene programatically (/thread-730.html) |
Generating emitters on scene programatically - ddematheu - 29-10-2018 Hello, I have been playing around with ObiFluids for a game I am making. I am having some trouble being able to programatically create emitters actors on the scene. I followed the procedure found here: (http://obi.virtualmethodstudio.com/tutorials/scriptingactors.html) Using the procedure in that link I am running a co-routine inside my Update function to create an emitter at certain points in time (checking for previous co-routine to finish before starting next) The only additional step I added to the procedure in the link is: Array.Resize<ObiParticleRenderer>(ref Camera.main.GetComponent<ObiFluidRenderer>().particleRenderers, Camera.main.GetComponent<ObiFluidRenderer>().particleRenderers.Length+1); Camera.main.GetComponent<ObiFluidRenderer>().particleRenderers[Camera.main.GetComponent<ObiFluidRenderer>().particleRenderers.Length-1] = emitterCreated.GetComponent<ObiParticleRenderer>(); to add the particle renderer to the camera. The emitter is created on the scene yet no fluid are emitted. I get the following error: NullReferenceException: Object reference not set to an instance of an object Obi.ObiActor.PushDataToSolver (Obi.ParticleData data) (at Assets/Obi/Scripts/Actors/ObiActor.cs:385) Obi.ObiActor.AddToSolver (System.Object info) (at Assets/Obi/Scripts/Actors/ObiActor.cs:278) Obi.ObiEmitter.AddToSolver (System.Object info) (at Assets/Obi/Scripts/Actors/ObiEmitter.cs:125) Obi.ObiActor.Start () (at Assets/Obi/Scripts/Actors/ObiActor.cs:150) I am reusing the same solver for all the emitters created. I can post full code but it is basically the one from the link. Any help is appreciated. RE: Generating emitters on scene programatically - josemendez - 29-10-2018 (29-10-2018, 08:02 AM)ddematheu Wrote: Hello, Hi there, That's a bug, thanks for reporting it. In ObiActor line 385, add the following check: && restPositions != null So that it looks like: Code: if ((data & ParticleData.REST_POSITIONS) != 0 && restPositions != null && i < restPositions.Length) Here's the runtime emitter creation code we tested, with the previous change it works properly. Note that you still should add these lines: Array.Resize<ObiParticleRenderer>(ref Camera.main.GetComponent<ObiFluidRenderer>().particleRenderers, Camera.main.GetComponent<ObiFluidRenderer>().particleRenderers.Length+1); Camera.main.GetComponent<ObiFluidRenderer>().particleRenderers[Camera.main.GetComponent<ObiFluidRenderer>().particleRenderers.Length-1] = emitterCreated.GetComponent<ObiParticleRenderer>(); if you want to use a fluid renderer, instead of the default particle renderer. Code: public class CreateEmitter : MonoBehaviour |