Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding ObiEmmitor gameObject in code
#1
Hello! Thank you for the wonderful asset
Can you help me with the problem of creating an emitter in the code? The object is created on the scene, all obi objects are configured, but the render does not work.


[Image: -o3QSG2tnohlkRdAU6fe4bzLjCN7hFBsL7ufMg94...=2048x2048]

Here is my code:



public void Init()

        {

            GameObject emitterObject = new GameObject("emitter",

                typeof(ObiEmitter),

                typeof(ObiParticleRenderer));



            emitterObject.transform.position = gameObject.transform.position;

            emitterObject.transform.parent = gameObject.transform;



            _emitter = emitterObject.GetComponent<ObiEmitter>();

            _emitter.Solver = GameControllerObjects.Instance.ObiSolver;

            _emitter.NumParticles = 1000;

            _emitter.emissionMethod = ObiEmitter.EmissionMethod.STREAM;

            _emitter.speed = ((Liquid)VRAObject.Type).Speed;

            _emitter.lifespan = ((Liquid)VRAObject.Type).Lifespan;

            _emitter.randomVelocity = ((Liquid)VRAObject.Type).RandomVeloncity;

            _emitter.EmitterMaterial = GameControllerObjects.Instance.ObiEmitterMaterial;



            Color newCol = new Color();

            string htmlValue = "#" + ((Liquid)VRAObject.Type).ParticleColor;

            ObiParticleRenderer particleRenderer = emitterObject.GetComponent<ObiParticleRenderer>();

            if (ColorUtility.TryParseHtmlString(htmlValue, out newCol))

                particleRenderer.particleColor = newCol;

            particleRenderer.radiusScale = ((Liquid) VRAObject.Type).RadiusScale;

            GameControllerObjects.Instance.ObiFluidRenderer.particleRenderers.Add(particleRenderer);



            StartCoroutine(OnFinish());


        }

IEnumerator OnFinish()

        {

            yield return _emitter.StartCoroutine(_emitter.GeneratePhysicRepresentationForMesh());

            _emitter.AddToSolver(null);
        }


Also I have Exeption!
NullReferenceException: Object reference not set to an instance of an object
Obi.ObiActor.PushDataToSolver (ParticleData data) (at Assets/Obi/Scripts/Actors/ObiActor.cs:369)
Obi.ObiActor.AddToSolver (System.Object info) (at Assets/Obi/Scripts/Actors/ObiActor.cs:276)
Obi.ObiEmitter.AddToSolver (System.Object info) (at Assets/Obi/Scripts/Actors/ObiEmitter.cs:137)
Obi.ObiActor.Start () (at Assets/Obi/Scripts/Actors/ObiActor.cs:148)

Thank you!
Reply


Messages In This Thread
Adding ObiEmmitor gameObject in code - by shtolyan - 16-03-2018, 02:16 PM