Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug / Crash  how to change the fluid into Granular in game?
#1
Corazón 
I want to change the obi fluid to the Granular when some triggers are matched(to simulate the situation when the water meet lava), but every time when it happens, unity will crash. I wanna know how to solve this problem, or a better way to change a fluid particle to the granular.
Really thank you guys  Sonrisa Sonrisa Sonrisa Corazón

Here is my code about this change:

void LateUpdate()
{
if (!isActiveAndEnabled)
return;

for (int i = 0; i < solver.particleToActor.Length; ++i)
{
if (solver.particleToActor[i] != null)
{
if (solver.userData[i].x < 1f && solver.userData[i].x > 0.1f)
{
KillParticle(i);
}
}
}

}

private void KillParticle(int index)
{
ObiEmitter emitter = solver.particleToActor[index].actor as ObiEmitter;
emitter.GetComponent<ObiParticleRenderer>().render = true;
emitter.EmitterMaterial = new ObiEmitterMaterialGranular();
}
Reply
#2
By changing the emitter's material every time a particle is killed, you're generating an endless loop since changing the material for the whole emitter will kill all particles and replace them with granular particles. No wonder Unity crashes Gran sonrisa.

You can't change fluid into granulars at runtime or vice-versa. They're simulated in completely different ways. You can however change the properties of these fluid particles to make them resemble solid particles. For instance, you can force their position, and/or set their smoothing radius to 1.
Reply
#3
(08-01-2021, 12:20 PM)josemendez Wrote: By changing the emitter's material every time a particle is killed, you're generating an endless loop since changing the material for the whole emitter will kill all particles and replace them with granular particles. No wonder Unity crashes Gran sonrisa.

You can't change fluid into granulars at runtime or vice-versa. They're simulated in completely different ways. You can however change the properties of these fluid particles to make them resemble solid particles. For instance, you can force their position, and/or set their smoothing radius to 1.
Hey, thank you soo much  Corazón

so if I cant change it to granulars, how can I set the fluid most like the solid stone? If you can give me a set of those parameters, that would be better (I tried it before but it looks like a pile of jelly...).

thank you again !!
Reply