Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

FLOW ️➖ Fast Fluids

Discussion in 'Assets and Asset Store' started by Darkcoder, Jul 10, 2021.

  1. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,466
    Hi DarkCoder,
    Can I ask for some help, I am using FlowFloat, it works, but how can I via script know if the object is float mode/floating? Is there some built in feature/flag/variable that will tell me that? I want to control if a player needs to change animation or not if floating..
     
  2. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    FLOW doesn't simulate rain drops or anything of this small scale. Maybe in the future I will add some kind of rain drop effect to the fluid surface, but it will never be suitable for rain on characters.

    When I say 'add colliders', I'm referring to the ground. e.g. you can add a sphere to your scene, add a collider to it, and then fluid will flow over the sphere (but not under it).

    The fluid surface shader was developed using the Better Shaders asset. If you have this asset then you can easily extend the FLOW fluid surface shader to add additional effects. I have no plans to support Shader Graph because this shader is too complex for it.


    The FlowFloat component itself just applies forces to your object based on the FlowSample(s) that you specify (Samples list). If you access the FlowSample component then you can read the Submersion 0..1 value, which should be what you want.
     
    eaque likes this.
  3. geff

    geff

    Joined:
    Mar 3, 2013
    Posts:
    28
    Hello, I am interested in purchasing Flow, however I have a few questions:

    * Have the performances been tested on Oculus Quest (1/2)?
    * Is it possible to simulate sand?
    * Is it possible to make the sand flow in an indoor room (20m*20*3m) with some static objects?
    * If yes, is it possible to make the sand flow if the whole room rotates slowly?

    Can we dynamically modify the heightmap so that it reflects the dynamic changes of the room (rotation)?
     
  4. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    1 - I've only tested it via Oculus Link on my Quest 2, not on device.

    2,3,4 - What do you mean by sand? Like ground that can erode and get deposited when water flows? If no, no.

    The ground height data is currently generated using racyasts only. If you move objects within the simulation boundary then the modified areas will be updated with new height values. This isn't recommended for very large objects like rotating the whole level though, can't you just rotate the camera around the level instead?
     
  5. hm2337

    hm2337

    Joined:
    Jun 9, 2019
    Posts:
    9
    - Does FLOW water respond to gravity? Example: If you put Flow water on a rigidbody and tilt the rigidbody realtime, will the water fall off?

    - Can player hold/collect FLOW water in any way?
     
  6. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    Yes, FLOW will react to the tilt of your Rigidbody as long as you add the FlowObject component to it. However, the fluid has no 'weight' system. For example, if your model was some kind of see-saw and your poured fluid particles on the high end, the see-saw would not react at all. There is a buoyancy system though, so the low end could be made to rise when it gets submerged.

    Also keep in mind this is a height based fluid simulation (i.e. heightmap), so you can't represent all kinds of rigidbodies reacting with the fluid. If your Rigidbody is made so water flows on it, then it will be treated as 'ground', kind of like if you laid a large cloth over the top, and then the fluid flows on top of it.
     
    hm2337 likes this.
  7. TheGamery

    TheGamery

    Joined:
    Oct 14, 2013
    Posts:
    92
    Is FLOW capable of handling flooding like on a sinking ship, so there would be a hole in the side in a bottom compartment and then the fluid will fill up the compartments and work it's way around the ship respecting the (mesh) collider of the ship?

    I've tried an other assets (Obi Fluid / Voxel Play) and the built in Particle System but it can't handle much beyond a very small test case before lagging.
     
  8. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,466
    Just having some fun with some NPC's, hope they can swim:
     
    Haxel0rd, ml785 and Darkcoder like this.
  9. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    Yes, as long as you keep in mind the fluid flows on a heightmap, so you cannot have fluid flow to multiple decks or underneath solid objects (unless the overhead object is not part of the sim at all).

    Looks great! Maybe some splash particles would spice things up a bit :D
     
  10. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    272
    Thanks for answer my questions! So i see this asset is great for big water body, like when we want to do boat battles!
     
    Darkcoder likes this.
  11. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    36
    Maybe I'm missing something obvious, but is there any way to change the overall speed of the simulation? Low-viscosity fluids like water appear to move too fast for my liking, but simply upping the viscosity has undesirable side effects ("sticking" to terrain, for example). Scaling the overall game time looks better, but of course I don't want to scale everything else in my scene to accommodate the water simulation.
     
  12. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    The simulation speed is tied to the resolution, since each simulation step the fluid can only move to its surrounding columns. Increasing the viscosity changes how fast it can spread to the surrounding columns per frame. You can open FLOW\Shaders\Resources\FLOW\Simulation_FluidForces.shader and comment out line 64 to stop fluid sticking. I will add more settings in the future to change the fluid simulation behavior.
     
  13. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    36
    Thanks, but I'm looking for the ability to adjust the simulation rate independently of those variables. Apologies if I was unclear. I need the ability to have high-viscosity fluids stick to the terrain, which is why using viscosity as a workaround for "simulation speed" is undesirable. Same with resolution, changing it too much to get the appearance I want will have dramatic affect on the performance characteristics, and vice versa.

    After posting I saw an example in your demos that updates the simulation at half the framerate, which I could build on to create an adjustable simulation rate, but a speed variable built into the simulation would be far better if that's something that's on your agenda to add.
     
  14. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,466
    Hi, could/would it be possible to request short demo / tutorial video on how to make the water look more realistic, also if the camera goes under the water line can fog/mist be applied to make it look like you are in water? In the asset store video it seems possible but I am not clear on how to.
     
  15. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    36
    • How do I disable foam entirely?
    • Why does adding force max out at barely a ripple no matter how high I set the strength property? It seems the only way to get any sizable waves is to add large amounts of fluid, but then I have to worry about removing the added fluid to keep a consistent amount in my simulation if all I want is big waves.
    • Speaking of, is there any way to easily track the total amount of fluid in the simulation and/or drain it uniformly to a baseline overall volume?
     
  16. Falke-3D

    Falke-3D

    Joined:
    Jun 1, 2020
    Posts:
    6
    Hi,

    Ich habe den Eintrag in der Dokumentation verwendet.
    Habe aber noch keine Simulation gesehen.

    Gibt es eine Videoanleitung, die den Anfang, also die ersten Schritte zeigt?
     
  17. Falke-3D

    Falke-3D

    Joined:
    Jun 1, 2020
    Posts:
    6
    Hi,

    Ich habe den Eintrag in der Dokumentation verwendet.
    Habe aber noch keine Simulation gesehen.

    Gibt es eine Videoanleitung, die den Anfang, also die ersten Schritte zeigt ?
     
  18. Minimilian

    Minimilian

    Joined:
    Jan 19, 2021
    Posts:
    23
    Hello I have a weird issue, where following the instructions step by step I cannot make Flow work in any of my scenes. I've even tried copy-pasting (and replacing) the elements from the demo scenes (where everything works correctly) and I'm confused.

    I think I'm missing something obvious, but I cannot say what. Any help please?
     

    Attached Files:

  19. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    For the next version I've added a new PhysicsModel/Spread setting to the FlowSimulation component, which allows you to control the strength of the viscosity sticking. I've also added an experimental Speed setting, though it may not be possible to make it behave the same as just a lower framerate. More settings are better though so I'll keep it.



    More realistic in what way? If you can find some reference images/videos of actual fluid surfaces in game and not flat planes then I can try replicating it. The underwater rendering is handled by the FlowUnderwater component + FLOW/Underwater material. Demo scenes like "Island" and "Large" use this with different material settings. This material's TRANSPARENCY/RangeMax setting + the fluid's Color.a/opacity are used to control how far the underwater fog reaches.



    1 - You currently can't unless you crank the FlowSimulation.FoamClearRate up. I'll add a proper setting to the material in the next version.

    2 - The actual strength of a wave depends entirely on its amplitude, which is limited by the amount of fluid in a fluid column. If you add an AddForce modifier then it can push fluid into columns to make fairly big waves, and you can run it for a few frames to make them stack. However, even with a massive Strength value they are limited by the fluid in the adjacent columns which quickly reaches a limit. To make truly massive waves there would need to be a new component or modifier that doesn't just add force, but actually drains fluid from certain columns and deposits it in another. This is a little tricky to do though, so I'll add it to the to-do list.

    3 - You can use a scene-sized FlowModifier with Mode = RemoveFluidAbove to do this. There's currently no way to read the total fluid volume. I have an idea of how to do this, but it will probably be a little slow so I recommend you to avoid having to require it.



    There's no tutorial video. To get started you can read the tutorial text HERE. If you have/get the asset, then the scenes take you step by step through how to set it up. The "01 Basic Setup" demo scene shows you a very simple scenario.



    It's hard to say with so little information. Maybe you can send me a private message or email of a package of a really simple scene with FLOW that doesn't work? Also let me know the exact version of Unity and render pipeline you use.
     
    khos likes this.
  20. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,466
    Hey there, thanks, I'll check out the underwater bit. If I look at this kind of water as an example, is there a way to reach that kind off effect in terms of the surface/water? youtube url:
     
    Haxel0rd likes this.
  21. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    Thanks! Their foam and water detail rendering appears to be much smoother than FLOW. They also implement caustics, and underwater refraction which I haven't added yet. I'll use this as a reference and see what I can do for the next-next version.
     
  22. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,466
    Cool, your asset is really awesome and I am extremely pleased so far, if you can add to it then wow even better :) Thanks for considering this.
     
    Darkcoder likes this.
  23. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    36
    Thank you for the responses.

    I see. My simulation is quite shallow in comparison to the size of waves I'm aiming for. I am using an AddForce modifier and the Sphere_Normal texture from your ripple example. The resulting wave looks the same whether the strength property is 5 or 5 million:

    Honeycam 2022-01-27 15-44-47.gif

    A component to remove the water from the impact site and push it out to the surrounding columns sounds like exactly what I need, but since I'd still be displacing a relatively small volume of water then adding fluid might still be the better choice for me.

    That's fair, I was already using the RemoveFluidAbove trick but it unfortunately it means any flooding from fluids already in the scene gets removed as well:

    Honeycam 2022-01-27 15-42-34.gif

    Ideally I'd be able to designate "permanent" and "temporary" fluids, and selectively remove the temporary. Would it be possible to use the custom properties to accomplish this? Use a visually identical fluid for temporary effects but with a Custom1 of 1, and then have RemoveFluidAbove only remove fluids with Custom1 > 0? Though if mixing fluids dilutes the custom value that wouldn't work like I'm imagining.
     
  24. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    Creating temporary fluids as you describe is technically possible, but it would be difficult due to all the fluid mixing code and such.

    A possible solution that I thought of is to allow the fluid flow rate to exceed the fluid volume in a column, and to allow that value to propagate. If this were implemented then setting very high force values would actually work, even if the fluid volume were relatively low. I'd rather not mess with the core fluid physics right now though. I plan to release a big update to all my assets within 7 days, so after that I will look into this.
     
  25. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    Hey everyone,

    Version 2.0.0 of FLOW is now out!
    • NOTE  This is a massive update. To update you must first back up your project, delete the root FLOW folder, then install the new version.
    • Changed folder structure to be inside Plugins/CW/FLOW.
    • Updated inspector code to support third party assets that implement nested inspectors.
    • Replaced FlowModifierSpeed.Angle setting with Rotation.
    • Improved "Island" demo scene ship wake.
    • Added FlowSimulation.PhysicsModel setting.
    • Added FlowSimulation.PhysicsModel / Instability setting.
    • Added FlowSimulation.PhysicsModel / Damping setting.
    • Added FlowSimulation.PhysicsModel / Spread setting.
    • Added FlowSimulation.PhysicsModel / Speed setting.
    • Replaced FlowDepthMode component with CwDepthTextureMode.
    This is mainly structural changes to the code that I will soon be rolling out to all of my assets to make them easier to update.

    There are also some new settings for the fluid physics which can be fun to play with. I will expand these in the future and add some demo scenes to better show the differences.

    Enjoy :)
     
    lukasynthetic, Auraion and khos like this.
  26. Auraion

    Auraion

    Joined:
    Aug 31, 2021
    Posts:
    6
    Congratulations on the update!

    I have a couple questions for (hopefully before) the lightning deal passes me by:

    Can fluids be moved and displaced by something like a shovel?
    Can fluids block interactions such as raycasts in any way?

    I ask as I'd like to create some means of hiding objects in something approximating sand pits (speed and damping look promising for simulating a very slow fluid perfomantly), with the objective to discover and dig objects up with a shovel or trowel before they can be interacted with. This would be with a fairly realistic aesthetic as well.

    I'd also like to say this looks like a fluid asset with a very promising future, given your approach to it! It's always good to see that.
     
    Last edited: Feb 10, 2022
  27. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    You 'could' create a shovel digging game, just keep in mind this is a fluid simulation that is constantly running, so it might be overkill to use this since digging can typically be done with a normal terrain by just reducing the height at the dig spot.

    The digging could be implemented using the same system as the ship wake in the Island example. This adds force to the fluid around the ship based on the ship velocity.

    There's currently no method to raycast the fluid, so you couldn't make raycasts block. You can detect the fluid height at a specific location though.
     
    Auraion likes this.
  28. MarcopoloR

    MarcopoloR

    Joined:
    Feb 4, 2015
    Posts:
    114
    Hi, I purchased your asset and in the store page it said it was HDRP compatible. However, when I open the asset I cannot find any HDRP shaders. I cannot seem to find it in when I scanned over the documentation either. Am I missing something?
     
  29. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    The shaders automatically switch based on the current pipeline.
     
  30. MarcopoloR

    MarcopoloR

    Joined:
    Feb 4, 2015
    Posts:
    114
    Okay thanks I will try it again and see if I can get it to work.
     
    Darkcoder likes this.
  31. dequevedo

    dequevedo

    Joined:
    May 31, 2013
    Posts:
    8
    Hi!

    I recently purchased this asset,

    I was wondering if it's possible to render the water double sided. I have two scenarios where this could be useful:

    1st: Underwater. When my camera is underwater, I'm unable to see the water surface above me, therefore I have no sense of depth (I don't know if I'm close to the surface or not). Like in this example:


    2nd: Let's say I have a waterfall, however, the camera is behind the waterfall. In the actual implementation I'm unable to see the water if I'm behind it.
     
  32. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    36
    Thank you so much, the new Damping and Speed properties make it much easier to dial in on the look I'm going for, and seem to work beautifully so far.

    That sounds like it's worth a shot. Already with the tweakable physics model I can get waves that look very good if I add a large volume of water all at once. I'll keep working on that approach for now, but I'd be happy to test drive this feature if you get around to it.
     
    Darkcoder likes this.
  33. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    The Underwater feature (see the example scene by the same name) allows you to do this. This isn't the same as double sided rendering though, because it uses different code. It would be possible to make the surface double sided, but then you wouldn't be able to see any water effect on the ground that's underwater, which may not look how anyone expects. Maybe in some stylized scenarios this would be intended?

    Glad you like the new settings! I've almost finished updating all my other assets with this new project structure and shared codebase, so I should be able to experiment with this idea next week.
     
  34. dequevedo

    dequevedo

    Joined:
    May 31, 2013
    Posts:
    8
    Thanks for the reply! I understand your point.

    This is the effect I was hoping to get.
    ex1.PNG

    But this is the effect I have so far. (Objects outside the water are not distorted, and I can't see the water surface)
    ex2.PNG

    Am I doing something wrong? Is there a way to achieve this?
     
  35. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    36
    Sounds great!

    After spending some time working with adding/removing fluids though, the biggest thing I'm missing is visibility into how much fluid is actually added or removed by a modifier.

    Right now it seems the only feedback is the OnApplied event, which just returns the multiplier. Preferably I'd like to be able to, for example, detect how much fluid a modifier removes so I know how much to add to return to base level, or can put an in-game value on it, or whatever.

    Would that be feasible, or would it be similar to measuring the total volume of the scene in terms of performance impact and not practical?
     
  36. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    That's mostly color tint + refraction + caustics. FLOW currently doesn't render any of those from underwater, but it's high on my priority list to add.


    Being able to detect how much fluid is removed is on my to-do list. With this it would be possible to convert them back into particles, and lots more interesting things. Since it's in a limited area it wouldn't be that performance intensive, it would basically work the same as when you sample fluid data currently.
     
    dequevedo likes this.
  37. tianlinzhang

    tianlinzhang

    Joined:
    Mar 18, 2021
    Posts:
    8
    Hello! I have just bought the Flow asset and plays for two days, looks very good! I have a question on how to adjust Water transparency. I have follow the steps in the document to adjust Mode, Range and Step but can not make Water transparent or even half transparent using the Flow/Surface_Transparent Shader. But in your demo, there is a picture which has water half transparent and is good enough for my game, can you tell me how to configure its Water Transparency? Please check the attached screenshot. thank you
     

    Attached Files:

    • Flow.png
      Flow.png
      File size:
      398.5 KB
      Views:
      264
  38. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    Which exact version of Unity and render pipeline are you using? If it's URP, make sure you enable the Opaque Texture in your pipeline settings asset.
     
  39. tianlinzhang

    tianlinzhang

    Joined:
    Mar 18, 2021
    Posts:
    8
    I am using Unity 2020.3.20f1, I have tried both Standard built-in render pipeline first and URP. For Standard render pipeline, I have added wDepthTextureMode component to main camera and set the Mode to Depth and also tried other mode. For URP I have enable Opaque Texture and Depth Texture. For the Surface material, I have switch different Modes: Depth, Vertical, March Depth, March Fluid and Depth and don't see any transparency changes on the Water. Do I miss anything? thank you
     
  40. giving_up_unity

    giving_up_unity

    Joined:
    Sep 17, 2016
    Posts:
    235
    Can we get another simple type of floating object for flow which disable all rotation in water?
     
  41. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    Can you send me an email or private message of your project so I can replicate the issue? As long as your simulation has a transparent fluid, you added CwDepthTextureMode to your camera, and you used the "Surface" material which is already configured for transparency, then it should work.


    Can't you just increase the FlowFloat component's AngularDrag to a very high value?
     
    giving_up_unity likes this.
  42. tianlinzhang

    tianlinzhang

    Joined:
    Mar 18, 2021
    Posts:
    8
    I used Water material and don't realize you have one called Clear Water, after switch materials, It works now. thank you so much!
     
    Darkcoder likes this.
  43. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    Hey everyone,

    Version 2.0.1 of FLOW is now out!
    • Script assembly reload fix for materials.
    • Added FlowModifier.MonitorFluidDepth setting.
    • Added FlowModifier.OnFluidDepthDelta event.
    • Added Sample Deepest Point demo scene.
    • Added Sample Fluid Volume demo scene.
    • Improved FlowModifier scene view gizmos.
    • Removed FlowModifier.HeightMin/Max settings from existing modes.
    • Added new FlowModifier modes for HeightMin/Max range.

    Lots of changes to FlowModifier, and the new LeanSampleArea + LeanSampleTrigger components add many new possibilities!

    Here's what the modifiers now look like in the Scene view:

    upload_2022-4-21_18-28-41.png

    This should make things much easier to configure.

    Enjoy :)
     
    CrazyCode_ likes this.
  44. Haxel0rd

    Haxel0rd

    Joined:
    May 20, 2021
    Posts:
    49
    I bought FLOW yesterday and am extremely happy with it already!

    Recently, i disabled the foam, but now i have the water on step angles to be not transparent.

    It currently looks like this:

    ** Note: the water reaches into the bottom right corner, which may not be seen in the image preview.

    I would want to reverse this effect, so the the water being clear on places where it runs downhill or as river,
    and the place where it collects and forms deeper pools it should be more blueish. I tried to use -minus values
    but this didnt reverse the effect.

    Any tips on how to achieve this would be great, thank you.

    Cheers!
     
    Last edited: Apr 28, 2022
  45. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    The final opacity of the fluid is based on the opacity of the fluid itself multiplied by the optical thickness (distance between surface and ground). This is more or less how fluid color works in real life. Why would making the sloped parts more transparent be desirable?
     
  46. Ensortainment

    Ensortainment

    Joined:
    Dec 19, 2020
    Posts:
    14
    For anyone else strugling with FLOWSnapshot making the water darker/changing colour each time it gets saved and loaded. I found the solution to be to change UpdateReadable in FlowSnapshotData.

    Just had to set "linear" to true in this constructor:
    Code (CSharp):
    1. ReadableData = new Texture2D(size.x, size.y, format, false, true);
    I don't know enough about textures to know why this works, (seems like something to do with Gamma correction), just hope this saves someone some time. ;)
     
    Last edited: May 18, 2022
    Darkcoder likes this.
  47. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,337
    Aha, thanks for pointing this out. This will be fixed in the next version!
     
    hopeful and Ensortainment like this.
  48. Ensortainment

    Ensortainment

    Joined:
    Dec 19, 2020
    Posts:
    14
    Also, for anyone else wanting to use FLOWSnapshot for synchronizing Clients in a Network but are put off by the long load/save times. The best solution I've found is using background threads to do the actual serialization and deserialilzation (just JsonUtility.ToJson and FromJsonOverwrite since they seemed to be what took all the time). That might be super obvious, and certainly applies to more than just this case, but was first time I've really had to use it so thought I'd share because it would've been nice for me to find here myself.

    I added these functions to the FlowSnapshot script provided.
    Saving in seperate thread:
    Code (CSharp):
    1. private string currentPath;
    2.  
    3. public void MySaveToFile()
    4.         {
    5.             if (simulation != null)
    6.             {
    7.                 snapshotData.SimulationToRaw(simulation);
    8.                 snapshotData.ConvertRawToReadable();
    9.                 snapshotData.ConvertReadableToPng();
    10.                 // have to get final path now, since can't access persistant data path from new thread
    11.                 currentPath = FinalPath;
    12.                 Thread t = new Thread(SaveFiles);
    13.                 t.Start();
    14.             }
    15.         }
    16.  
    17.         private void SaveFiles()
    18.         {
    19.             var json = JsonUtility.ToJson(snapshotData);
    20.             System.IO.File.WriteAllText(currentPath, json);
    21.         }
    Loading in seperate thread:
    Code (CSharp):
    1. private bool loadReady=false;
    2.  
    3.         /// <summary>This method reverts the fluid data to the previously stored snapshot.</summary>
    4.         public void MyLoadFromFile()
    5.         {
    6.             if (simulation != null)
    7.             {
    8.                 // have to get final path now, since can't access persistant data path from new thread
    9.                 currentPath = FinalPath;
    10.                 if (System.IO.File.Exists(currentPath))
    11.                 {
    12.                     Thread t = new Thread(LoadFiles);
    13.                     t.Start();
    14.                     StartCoroutine(AsyncLoad());
    15.                 }
    16.             }
    17.         }
    18.  
    19.         private void LoadFiles()
    20.         {
    21.             // don't proceed if there is already a loaded version waiting to be put in snapshotData
    22.             if (!loadReady)
    23.             {
    24.                 var json = System.IO.File.ReadAllText(currentPath);
    25.                 JsonUtility.FromJsonOverwrite(json, snapshotData);
    26.                 loadReady = true;
    27.             }
    28.         }
    29.  
    30.         IEnumerator AsyncLoad()
    31.         {
    32.             yield return new WaitUntil(()=>loadReady);
    33.             loadReady = false;
    34.             snapshotData.ConvertCompressedToReadable();
    35.             snapshotData.ConvertReadableToRaw();
    36.             snapshotData.RawToSimulation(simulation);
    37.         }
    Note: this works fine for me right now but probably doesn't guarantee thread safety. If anyone has recommendations for how to set that up I'd be down to learn. :)
     
    Last edited: Jun 6, 2022
    Haxel0rd likes this.
  49. Ensortainment

    Ensortainment

    Joined:
    Dec 19, 2020
    Posts:
    14
    Does FLOW make use of Unity's physics system, or does it handle that internally? I'm worried about performance on a large terrain using AR. I'm considering scaling down so 1unity unit is only something like 0.5m so the simulation area can be decreased. Will I run into unnexpected concequences down the line if not treating 1unit=1m as is custom?
     
    Last edited: Jun 7, 2022
  50. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,457
    Prebuy question: Does this work on WebGL and how is the performance?