Posts: 11
Threads: 2
Joined: Nov 2018
Reputation:
0
Hi All,
I bought this asset a few days ago and everything was going well until I tried to count particles
I know this page: http://obi.virtualmethodstudio.com/tutor...sions.html and spent time there but I couldn't manage to "count" particles. It would be amazing if someone give hand about that.
I have my box collider and script on my Solver object. There is a counter in the script, but it counts as soon as 1 collision happens BETWEEN the fluid particles (not the collider) and it never stops increasing.
Here is my code;
Code: using Obi;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(ObiSolver))]
public class Fill : MonoBehaviour
{
ObiSolver solver;
public int counter = 0;
public Collider2D targetCollider = null;
ObiSolver.ObiCollisionEventArgs collisionEvent;
void Awake()
{
solver = GetComponent<ObiSolver>();
}
void OnEnable()
{
solver.OnCollision += Solver_OnCollision;
}
void OnDisable()
{
solver.OnCollision -= Solver_OnCollision;
}
void Solver_OnCollision(object sender, ObiSolver.ObiCollisionEventArgs e)
{
foreach (Oni.Contact contact in e.contacts)
{
// this one is an actual collision:
if (contact.distance < 0.01)
{
Component collider;
if (ObiCollider.idToCollider.TryGetValue(contact.other, out collider))
{
counter++;
}
}
}
}
}
Second thing is, I only see pink screen when I export my game to the Android. I found a similar issue on the forum, did the suggestion (It was something like changing current shader to simple shader) and it didn't work.
Thanks in advance.
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
15-11-2018, 06:44 PM
(This post was last modified: 15-11-2018, 06:46 PM by josemendez.)
(15-11-2018, 06:39 PM)Tuna.Y Wrote: Hi All,
I bought this asset a few days ago and everything was going well until I tried to count particles
I know this page: http://obi.virtualmethodstudio.com/tutor...sions.html and spent time there but I couldn't manage to "count" particles. It would be amazing if someone give hand about that.
I have my box collider and script on my Solver object. There is a counter in the script, but it counts as soon as 1 collision happens BETWEEN the fluid particles (not the collider) and it never stops increasing.
Here is my code;
Code: using Obi;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(ObiSolver))]
public class Fill : MonoBehaviour
{
ObiSolver solver;
public int counter = 0;
public Collider2D targetCollider = null;
ObiSolver.ObiCollisionEventArgs collisionEvent;
void Awake()
{
solver = GetComponent<ObiSolver>();
}
void OnEnable()
{
solver.OnCollision += Solver_OnCollision;
}
void OnDisable()
{
solver.OnCollision -= Solver_OnCollision;
}
void Solver_OnCollision(object sender, ObiSolver.ObiCollisionEventArgs e)
{
foreach (Oni.Contact contact in e.contacts)
{
// this one is an actual collision:
if (contact.distance < 0.01)
{
Component collider;
if (ObiCollider.idToCollider.TryGetValue(contact.other, out collider))
{
counter++;
}
}
}
}
}
Second thing is, I only see pink screen when I export my game to the Android. I found a similar issue on the forum, did the suggestion (It was something like changing current shader to simple shader) and it didn't work.
Thanks in advance.
Hi,
You're counting how many particles are there in the collider every frame, completely disregarding particle IDs when counting. So if a particle was already inside the collider the previous frame, it will be counted again next frame. That's why the counter will never stop increasing as long as there's any particle inside of it.
There's several solutions for counting particles in the forum, here's one:
http://obi.virtualmethodstudio.com/forum...=collision
As for the pink screen in Android, check what the ADB log says. Your particular device isn't capable of running one or more of the default fluid shaders, so you might have to modify them.
Posts: 11
Threads: 2
Joined: Nov 2018
Reputation:
0
(15-11-2018, 06:44 PM)josemendez Wrote: Hi,
You're counting how many particles are there in the collider every frame, completely disregarding particle IDs when counting. So if a particle was already inside the collider the previous frame, it will be counted again next frame. That's why the counter will never stop increasing as long as there's any particle inside of it.
There's several solutions for counting particles in the forum, here's one:
http://obi.virtualmethodstudio.com/forum...=collision
As for the pink screen in Android, check what the ADB log says. Your particular device isn't capable of running one or more of the default fluid shaders, so you might have to modify them.
Thank you very much for your fast reply Jose.
Let's put aside the Android issue since I haven't spent much time on that issue, yet.
About counting particles. I have already found that topic and tried the same sample code, but couldn't get it worked. I set the collider but counter is not increasing when particles collide with collider that I've set up.
The only change I made was changing public Collider to public Collider2D, since my game is 2D.
Which part do you think should I edit on the sample code that you've provided to make it work on 2D game?
Thank you.
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(15-11-2018, 08:12 PM)Tuna.Y Wrote: Thank you very much for your fast reply Jose.
Let's put aside the Android issue since I haven't spent much time on that issue, yet.
About counting particles. I have already found that topic and tried the same sample code, but couldn't get it worked. I set the collider but counter is not increasing when particles collide with collider that I've set up.
The only change I made was changing public Collider to public Collider2D, since my game is 2D.
Which part do you think should I edit on the sample code that you've provided to make it work on 2D game?
Thank you.
Hi,
It works fine both in 2D and 3D for me. Which kind of 2D collider are you using?
Posts: 11
Threads: 2
Joined: Nov 2018
Reputation:
0
(15-11-2018, 08:36 PM)josemendez Wrote: Hi,
It works fine both in 2D and 3D for me. Which kind of 2D collider are you using?
Hi,
It was a standard Box Collider 2D. I have an object which includes obi solver, Collider script and box collider 2d.
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(15-11-2018, 08:43 PM)Tuna.Y Wrote: Hi,
It was a standard Box Collider 2D. I have an object which includes obi solver, Collider script and box collider 2d.
Works for me. Make sure you're indexing the correct collider map in the for loop, ie ObiCollider2D instead of ObiCollider. I'm pasting the 2D version just in case:
Code: using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;
[RequireComponent(typeof(ObiSolver))]
public class CollisionCounter : MonoBehaviour {
ObiSolver solver;
public int counter = 0;
public Collider2D targetCollider = null;
Obi.ObiSolver.ObiCollisionEventArgs frame;
HashSet<int> particles = new HashSet<int>();
void Awake(){
solver = GetComponent<Obi.ObiSolver>();
}
void OnEnable () {
solver.OnCollision += Solver_OnCollision;
}
void OnDisable(){
solver.OnCollision -= Solver_OnCollision;
}
void Solver_OnCollision (object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
{
HashSet<int> currentParticles = new HashSet<int>();
for(int i = 0; i < e.contacts.Count; ++i)
{
if (e.contacts.Data[i].distance < 0.001f)
{
Component collider;
if (ObiCollider2D.idToCollider.TryGetValue(e.contacts.Data[i].other,out collider)){
if (collider == targetCollider)
currentParticles.Add(e.contacts.Data[i].particle);
}
}
}
particles.ExceptWith(currentParticles);
counter += particles.Count;
particles = currentParticles;Debug.Log(counter);
}
}
Posts: 11
Threads: 2
Joined: Nov 2018
Reputation:
0
(15-11-2018, 09:40 PM)josemendez Wrote: Works for me. Make sure you're indexing the correct collider map in the for loop, ie ObiCollider2D instead of ObiCollider. I'm pasting the 2D version just in case:
Code: using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;
[RequireComponent(typeof(ObiSolver))]
public class CollisionCounter : MonoBehaviour {
ObiSolver solver;
public int counter = 0;
public Collider2D targetCollider = null;
Obi.ObiSolver.ObiCollisionEventArgs frame;
HashSet<int> particles = new HashSet<int>();
void Awake(){
solver = GetComponent<Obi.ObiSolver>();
}
void OnEnable () {
solver.OnCollision += Solver_OnCollision;
}
void OnDisable(){
solver.OnCollision -= Solver_OnCollision;
}
void Solver_OnCollision (object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
{
HashSet<int> currentParticles = new HashSet<int>();
for(int i = 0; i < e.contacts.Count; ++i)
{
if (e.contacts.Data[i].distance < 0.001f)
{
Component collider;
if (ObiCollider2D.idToCollider.TryGetValue(e.contacts.Data[i].other,out collider)){
if (collider == targetCollider)
currentParticles.Add(e.contacts.Data[i].particle);
}
}
}
particles.ExceptWith(currentParticles);
counter += particles.Count;
particles = currentParticles;Debug.Log(counter);
}
}
Ahhh! I was not using Obi Collider at all as a component... I just added the Obi Collider 2D and it works. Thank you very much Jose!
Posts: 11
Threads: 2
Joined: Nov 2018
Reputation:
0
(15-11-2018, 09:40 PM)josemendez Wrote: Works for me. Make sure you're indexing the correct collider map in the for loop, ie ObiCollider2D instead of ObiCollider. I'm pasting the 2D version just in case:
Code: using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;
[RequireComponent(typeof(ObiSolver))]
public class CollisionCounter : MonoBehaviour {
ObiSolver solver;
public int counter = 0;
public Collider2D targetCollider = null;
Obi.ObiSolver.ObiCollisionEventArgs frame;
HashSet<int> particles = new HashSet<int>();
void Awake(){
solver = GetComponent<Obi.ObiSolver>();
}
void OnEnable () {
solver.OnCollision += Solver_OnCollision;
}
void OnDisable(){
solver.OnCollision -= Solver_OnCollision;
}
void Solver_OnCollision (object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
{
HashSet<int> currentParticles = new HashSet<int>();
for(int i = 0; i < e.contacts.Count; ++i)
{
if (e.contacts.Data[i].distance < 0.001f)
{
Component collider;
if (ObiCollider2D.idToCollider.TryGetValue(e.contacts.Data[i].other,out collider)){
if (collider == targetCollider)
currentParticles.Add(e.contacts.Data[i].particle);
}
}
}
particles.ExceptWith(currentParticles);
counter += particles.Count;
particles = currentParticles;Debug.Log(counter);
}
}
Hi Jose,
I have checked the ADB logs. This is the error that I'm getting when I open the scene.
CommandBuffer: temporary render texture _FluidDepthTexture not found while executing Render fluid (SetGlobalTexture)
Tried with 2 different shaders. Obi/ParticleShader and Obi/FluidColorsOpaque
Thanks
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(16-11-2018, 09:15 AM)Tuna.Y Wrote: Hi Jose,
I have checked the ADB logs. This is the error that I'm getting when I open the scene.
CommandBuffer: temporary render texture _FluidDepthTexture not found while executing Render fluid (SetGlobalTexture)
Tried with 2 different shaders. Obi/ParticleShader and Obi/FluidColorsOpaque
Thanks
This means your device does not support floating point render textures.
Try using the SimpleFluidRenderer instead of the default FluidRenderer. This one is optimized for mobile and does not perform depth testing.
See:http://obi.virtualmethodstudio.com/tutorials/customparticlerendering.html
Posts: 11
Threads: 2
Joined: Nov 2018
Reputation:
0
(16-11-2018, 11:55 AM)josemendez Wrote: This means your device does not support floating point render textures.
Try using the SimpleFluidRenderer instead of the default FluidRenderer. This one is optimized for mobile and does not perform depth testing.
See:http://obi.virtualmethodstudio.com/tutorials/customparticlerendering.html
Thank you Jose.
I have already tried to change Simple Fluid Renderer, and just tried again but nothing changed.
Is there anything that I should change except Obi Particle Renderer component's Shader in the Emitter object?
|