Search Unity

Dynamic Water Physics 2 [Released]

Discussion in 'Assets and Asset Store' started by NWHCoding, Jul 3, 2019.

  1. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Dynamic Water Physics 2 is now on sale!
     
    Vincent454, StarChick971 and Rowlan like this.
  2. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    If anyone is experiencing any issues with import of the latest version just remove both SceneInputActions files from DWP2 (not common) folder. An update has been submitted and will hopefully be live today.
     
    StarChick971 likes this.
  3. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Update v2.3.2 is on the way with the following changes:
    • Added per-object simulation settings.
    • Added multiple throttle bindings.
    • Fixed inspector entering infinite loop on Unity 2020.2 when ReorderableList is drawn.
     
    StarChick971 and Rowlan like this.
  4. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Dynamic Water Physics 2 is currently 40% off as a part of New Year sale.
     
    Vincent454 likes this.
  5. Image3d

    Image3d

    Joined:
    Jun 20, 2008
    Posts:
    155
    Still getting a infinite loop on Unity 2020.2 when clicking on any asset ( boat for example) ...
     
  6. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    First, make sure you are using the latest version. If that is the case go to the NUIDrawer.cs and find GetHeight function. Inside that function check that it looks like this:
    Code (CSharp):
    1.         public float GetHeight(string key)
    2.         {
    3.             float height = 0;
    4.             EditorCache.GetCachedValue("height", ref height, key);
    5.             return height <= 0 ? 1 : height;
    6.         }
    7.  
     
  7. Image3d

    Image3d

    Joined:
    Jun 20, 2008
    Posts:
    155
    Thanks guys...just deleted all and made the download again...Problem solved...
     
  8. garrett456

    garrett456

    Joined:
    Mar 13, 2013
    Posts:
    6
    I cannot get boats (either mine or the ones provided) to interact with the water; they are currently falling right through the water. I am using the latest version of Crest and DWP2 2.3 with Unity 2019.4.14.

    I do have multiple scenes, however the game objects with the water, water objects, and water object manager are all put into DontDestroyOnLoad. I am using the Crest Water Data Provider on the ocean, have the WaterObjectManger attached to a game object in DontDestroyOnLoad, and believe I have followed all the other steps from the documentation.

    Is there something I'm missing? Has anyone had success with using DontDestroyOnLoad with Crest and DWP2?
     
  9. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hello,
    could you please check the WaterObjectManager while in play mode. How many triangles/objects do you see there in the debug section? If you are loading the scenes with WaterObjects after the WaterObjectManager you should do:
    WaterObjectManager.Instance.Synchronize();
    to force the manager to register the objects and update all the internal arrays (NativeArrays are quite expensive to re-initialize hence this is not done automatically).
    Also, WaterObjectManager.FindSceneWaterObjects function does exactly that - finds all the WaterObjects in the current scene. To find the objects in all the loaded scenes replace it with:

    Code (CSharp):
    1.  
    2.         private void FindSceneWaterObjects(ref List<WaterObject> waterObjects, bool includeInactive)
    3.         {
    4.             waterObjects =  FindObjectsOfType<WaterObject>().ToList();
    5.         }
    I have added this to the TODO for the next update and will include it.
     
    Mark_01 likes this.
  10. garrett456

    garrett456

    Joined:
    Mar 13, 2013
    Posts:
    6
    Thanks for your reply. The change for FindSceneWaterObjects worked perfectly.
     
  11. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Glad it did. Have not tested the code :).
    I will add an option to switch between the two in the next update.
     
  12. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Update 2.3.3 is on the way with the following changes:
    • CameraMouseDrag can now be used for both 1st and 3rd person view (including rotation, panning and camera shake) and will replace other cameras in the future versions as an universal camera.
    • Reworked Submarine script and added a PID controller for better depth control.
    • Added option to synchronize WaterObjects in current scene or all loaded scenes.
    • Fixed editor division by zero when no WaterObjects present.
    • Fixed missing 'using Unity.Burst;' inside WaterTriangleJob.
    • Fixed Burst compatibility on newer versions of Unity.
     
    StarChick971 and Mark_01 like this.
  13. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    So, it seems there is quite an oversight with the current version of DWP2 I'm using. I just imported what appears to be the latest version: 2.3.3

    When WaterObjects or ships exist in the scene initially, they function as you'd expect.
    However, when you spawn them in at runtime, they are ignored and not given buoyancy.

    It appears that WaterObjectManager looks for all WaterObjects at Start() and adds them to a list. This list, however, is not repopulated or modified at runtime under normal circumstances. (I'll assume that enabling and disabling the water manager is not a "normal" circumstance.)
    I believe the correct thing to do would be for WaterObjects to add and remove themselves from the list.

    I'll attempt to make the change myself, but when I update DWP2 in the future, I'd like to know that this change will not get blown away. So, if I succeed, I can send you a copy of the code with my modifications.
     
  14. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    After looking more deeply into the situation, I noticed you are already aware of the need to resync when new water objects are created and recommend against it.

    Unfortunately the provided alternative solution of having these objects strictly pre-exist in the scene is not an option as it is not possible to know how many of these water objects will exist ahead of time.

    In cases like mine, where I need to be able to add objects at runtime, the API provided by WaterManager (Synchronize()) is suboptimal:
    • If multiple objects are added in one frame, and each object calls Synchronize(), all of the work done for each call is wasted, except for the last one.
    • Each time Synchronize() is called, it does a slow search through everything in the scene. This step can be avoided altogether if WaterObject instances manage adding and removing themselves.
    Instead, the approach I'm taking is to maintain a "public" list and a "private" list. Whenever a change is made to the public list, it is marked as dirty. At the start of the next FixedUpdate() call, it checks if the public list is dirty. If so, it will automatically resynchronize the private list and reallocate the arrays used by the water job.
    By organizing it this way it is easier to:
    • Set an resync interval: Instead of resyncing every fixed update, it'd be easy to set a schedule for how often resynchronization occurs. For example, it waits until a full second goes by since the last sync before syncing again.
    • Since synchronization is done exclusively by the manager, and is not called arbitrarily by other classes, the process of resyncing can be put on another thread. If it takes time to refresh the arrays this will not interrupt gameplay.
    • Further, if the sync process is threaded, perhaps it might be possible to create a new set of arrays and set up a new WaterTriangleJob while the other one is currently running. When the new water job and its associated arrays are finished allocating, the previous water job can quit and the new one will take its place. This could prevent resyncing from interrupting the water system itself.
     
    Last edited: Feb 27, 2021
  15. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    Another possibility:

    Use the pattern employed by the List class for managing the triangle arrays.
    By "triangle array", I am referring to the arrays, both native and managed, which have a length of _triangleData.Count.

    Start with a certain capacity for processing triangles, perhaps 1024. Whenever that capacity is exceeded, the triangle arrays' lengths are doubled.

    That way when a new water object is added, the only cost involved is with reassigning which elements of the triangle array are associated with what objects. In other words, only _dataStarts, _dataLengths, and _triangleData, would undergo possible length changes. (Of course, the p0s, p1s, p2s and localToWorldMatrices would need to be reassigned, but this doesn't require reallocation.)

    Also, simiarly to List, a Count property could be maintained so any processes using the triangle arrays can avoid processing unused elements. This might actually be *faster* than having a massive amount of preallocated triangle data in anticipation of spawned objects, since there would be less time wasted iterating through a list of inactive triangles (as identified by the _states and States arrays).

    Edit: I've just confirmed that it is possible to specify a job length that is less than the capacity of the job object. In other words, a Count is possible. Perhaps this is the intended usage.
     
    Last edited: Feb 27, 2021
  16. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Well, glad that you already noticed that Synchronize is required when adding objects. I have an update queued and will start work on it somewhere mid this upcoming week to modify the code to pre-allocated additional space and only do the re-allocation if that space becomes filled.
     
  17. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    I'll probably beat you to it. ;) I'm already starting now.

    If you like, we can keep in touch elsewhere so that I may submit my changes for my approval. It might clutter up this thread.
     
  18. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    No problem. Please do not post larger chunks of code in the thread.
    As mentioned I will be working on this so if you are not in an extreme hurry you do not need to spend time on it, it is a paid asset after all :)
     
    Mark_01 likes this.
  19. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Since all the NWH assets have been updated to use assembly definitions here is a disclaimer to avoid confusion when updating:

    This asset uses Assembly Definition (.asmdef) files. There are many benefits to assembly definitions but a downside is that the whole project needs to use them or they should not be used at all.

    • If the project already uses assembly definitions accessing a script that belongs to this asset can be done by adding an reference to the assembly definition of the script that needs to reference the asset. E.g. to access AdvancedShipController adding a NWH.DWP2.ShipController reference to MyProject.asmdef is required.

    • If the project does not use assembly definitions simply remove all the .asmdef files from the asset after import.

    Using, for example, Lux Water (which does not fature assembly definitions) will therefore require an addition of .asmdef file inside the Lux Water directory and a reference inside NWH.DWP2.WaterData or removal of all .asmdef files from the asset if you do not wish to use assembly definitions. Some assets such as Crest already feature .asmdefs and adding Crest as a reference to NWH.DWP2.WaterData is the only step needed.
     
  20. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    The updates for NVP2, DWP2 and WC3D have been submitted and will fix the issues introduced in the previous upgrade. The requirement for .NET 4.x was removed and the issue with the missing 'using' directive in DWP2 has been fixed.
    This should make upgrading easier since the .NET error was causing the import to break mid-import.
     
  21. magsoftware

    magsoftware

    Joined:
    Feb 7, 2019
    Posts:
    123
    Can I convert Water shader to be compatible with Universal Render Pipeline? Because when I upgraded my project to URP, the water turned black. Please, give me an advice ! Thanks!
     
  22. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Hello - the water in the demo scene is very simple and based on Standard Assets water and is intended for demo purposes only. Since you are not bound with licensing you can use any water shader compatible with URP.
     
  23. magsoftware

    magsoftware

    Joined:
    Feb 7, 2019
    Posts:
    123
    Ok, but I am not using a demo DWP.

    WaterFX shader from DWP :

    1. Code (CSharp):
      1. // -
      2. }
    Is it compatible with URP or not? There is any chance to make it works again if the URP is active?
    Because each material looks really bad, black or loses its texture with the URP..

    How to change it to become visible again? Do I need to convert this shader to URP/Lit or something?
     
    Last edited: Mar 15, 2021
  24. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    First of all please do not post code from paid assets on the forum.

    I have to point out that DWP2 is a physics asset and not a water shader. It is compatible with all flat water shaders. Demo water does not work with URP or HDRP (or at least reflections do not). Removing the script responsible for reflections will fix the issue but the water will not look the best without them.

    I would recommend using a shader specifically designed for URP such as this one (I have not tested it but it is free and looks about the same as the one in the demo scene or even slightly better). There are a few available on git too.

    Due to Unity introducing multiple rendering pipelines and DWP2 being a physics asset I try to distance myself from trying to support all of them. The asset is intended to be used with a 3rd party water system and hence the quite large compatibility list of free and paid assets.

    If that is an issue I can always offer a refund. I do understand that some customers do not read the description fully and I would not like to come out as trying to trick anyone. Unity is coming out with rendering pipelines left and right and it is hard to cover all the bases.
     
    Kennth and Mark_01 like this.
  25. magsoftware

    magsoftware

    Joined:
    Feb 7, 2019
    Posts:
    123
    I am sorry for doing it. I removed that script.

    Thank you for your response.
     
  26. XCoCX

    XCoCX

    Joined:
    Mar 17, 2021
    Posts:
    1
    error CS0246: The type or namespace name 'ShipInputActions' could not be found (are you missing a using directive or an assembly reference?)

    how to fix it?
     
  27. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    This is a bug introduced in v2.4 and v2.4.1 which fixes it is waiting to get approved since Sunday.
    Open ShipInputActions.cs file and note which namespace it is in. Add that namespace ('using namespaceName;') to the script throwing the error above.
    I do not have a local copy at the moment of v2.4 and can not remember which namespace it was exactly so that is why I added the instructions above. The update should be live any time now. Normally it is approved within 2 days but they probably have a backlog from the weekend to work through.
     
  28. Da-Luk

    Da-Luk

    Joined:
    Apr 25, 2017
    Posts:
    53
    Hey,
    after upgrading to the latest version i got many error messages.
    View attached image.

    Another thing -> your changelog and upgradenotes Link in the Asset Store leads to the NWH Vehicle Physics 2 Documentation and not to dynamic water physics 2.

    Have a nice day
     

    Attached Files:

  29. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    I have done an import test of the exact same package that is now on the Asset Store before submitting it and I am sure that there were no errors. Have you done a clean import as per the correct upgrade notes here: UpgradeNotes [Dynamic Water Physics Documentation] ?
    Also thank you for the spot, I copied the wrong link while making the last update and will immediately re-submit with the correct links.

    EDIT: Just did a clean import of the update released yesterday into Unity 2019.4 and no issues. If you are using 2020.x Package Manager sometimes has an issue of showing that you have the lastest version while you actually do not which can be fixed by deleting the package cache in the %appdata%/Unity folder. But I would suggest doing a clean import first.
     
    Last edited: Mar 19, 2021
  30. Da-Luk

    Da-Luk

    Joined:
    Apr 25, 2017
    Posts:
    53
    Thanks ! A clean import solved all errors. But now im missing the Lux Data provider. Have you renamed it or is there a new general solution?

    Ok i found it, sry, i had to rename the LuxWaterDataProvider.cs.txt file. But now the LuxWater namespace could not be found...

    Assets\NWH\Dynamic Water Physics 2\Scripts\WaterObject\LuxWaterDataProvider.cs(1,7): error CS0246: The type or namespace name 'LuxWater' could not be found
     
    Last edited: Mar 19, 2021
  31. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
  32. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    NWH Vehicle Physics 2 and Dynamic Water Physics 2 are currently 50% off as a part of Unity Spring Sale.
     
    Last edited: Apr 12, 2021
  33. bangoo

    bangoo

    Joined:
    Apr 25, 2015
    Posts:
    12
    Is it possible to unite two water objects in one somehow? If water object component is added to multiple childs, the parent object falls to pieces.
     
  34. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    The object falls to pieces because you have multiple Rigidbodies. If you need to physically connect separate Rigidbodies into a chain or something like that you can use joints. If you want to use multiple WaterObjects with one RIgidbody parent you can simply attach multiple WaterObjects to its children (but not Rigidbodies!). Something like this

    RigidbodyObject
    |-- WaterObject1
    |-- WaterObject2
    |-- WaterObject3

    And so on. Your object falls apart because each Rigidbody is simulated on its own. So leave just the parent Rigidbody object (only one) and it will work.
     
  35. bangoo

    bangoo

    Joined:
    Apr 25, 2015
    Posts:
    12
    Is it possible to make water object without rigidbody?
     
  36. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Of course not since then it would have no physics. Rigidbody is required for any physics to work in the first place in Unity.
    Why do you need a physics object without a Rigidbody?
     
  37. bangoo

    bangoo

    Joined:
    Apr 25, 2015
    Posts:
    12
    Thanx, it helped!
     
  38. TaylorCaudle

    TaylorCaudle

    Joined:
    Feb 8, 2018
    Posts:
    158
    How

    How exactly do I add a reference to that? I'm trying to use LUX as well, previously I just had to rename the cs.txt file, but Im not seeing instructions on how to add a reference to the .asmdf file.


    EDIT: Answer is just make a blank Assembly Definition file in the LuxWater main folder, and add that to the NWH.DWP2.asmdef list
     
    Last edited: May 17, 2021
  39. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    You got it working in the end? I believe I mentioned the sometimes required addition of empty asmdef somewhere in the docs but will have to double check. Assembly definitions are a bit of a hassle but they do improve compilation times by a lot and was one of the main reasons why I added them a few versions back.
     
  40. Da-Luk

    Da-Luk

    Joined:
    Apr 25, 2017
    Posts:
    53
    Hey,
    im using Lux water for some small lakes and a river, the "Lux water data Provider" in the scene only seems to work with the lakes, i have completely no water physics on the river. I tried to use the "Raycast Water Data Provider" only for the river but without success. The river has a height difference of 4000 units from start to end.
    Do i miss anything?
     
  41. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    I have to say that I was not aware Lux even supported rivers. The water data provider for Lux works at this point only with ocean/sea type of water.
    Assuming that the river is a mesh and it has a mesh collider attached it will work with RaycastWaterDataProvider BUT since only one water data provider can be present at one time that means that the lake will also need to have a mesh collider.
     
  42. Da-Luk

    Da-Luk

    Joined:
    Apr 25, 2017
    Posts:
    53
    Thank you! It works very nice but the buoyancy forces are not syncing with the gerstener waves anymore like with the "lux water data provider". Is there a way to add this ability to the "raycast water data provider" ? If not it would be nice to use both data providers at the same time. One for the river and the other one for the lakes.

    "Lux water" is very nice for rivers because you can use tesselation with gerstener waves which are moving down the river. In combination with DWP2 it's a lot of fun to swim downhill in a river and it would be a great bonus to use it together with waves.
     
  43. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Agreed that using two or more water data providers at the same time would be nice. The challenge is how to implement it without performance penalty and other issues such as which data provider has a priority at which point. If I were to ask the scene what the water height was at [X,Z] the response has to be one water height. This is already quite expensive when used with large number of objects and triangles but there would have to be a way to determine which water height to use and a host of other issues. What can be done right now is toggling between multiple water data providers but in that case things like overlaps from river > ocean have to be handled.
     
    Mark_01 likes this.
  44. Da-Luk

    Da-Luk

    Joined:
    Apr 25, 2017
    Posts:
    53
    Okay this evening i tried to mix both data providers but without success xD. I got no compiling errors but there are no additional gerstener wave movements on my water Object. It would be nice if i could turn on and off both data providers because i dont need any transitions. Is there something i have to look at? Turning off the "raycast water data providers" has no effect in playmode.

    I noticed another problem. I have a player which can swim and walk. Everything works fine but i have some regions on the terrain where the player behaves like in water. I dont know how thats possible because there is no water material or water mesh at this places. This kind of issue wasn't there before i used the "raycast water data provider".
     
  45. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    You could have multiple water data providers but the last to initialize will be used.

    I would check layers - make sure that the surface this happens on is not using the same layer as water.
     
  46. TaylorCaudle

    TaylorCaudle

    Joined:
    Feb 8, 2018
    Posts:
    158
    I'm actually getting some build errors preventing me from building the game, but it works fine when playing in editor.
     

    Attached Files:

  47. Da-Luk

    Da-Luk

    Joined:
    Apr 25, 2017
    Posts:
    53
    I managed to get rid of the inwater behaviour when moving on the terrain. I don't know why but that behaviour only occured when entering areas which were below the y-position smaller than zero. I liftet up the whole map above that point and im happy now.

    Can you tell me how to toggle between two "water data providers" reenabling doesn't work.
    Thank you
     
  48. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    The missing type/namespace errors are most likely due to assembly definitions. Unity expects separate, editor-only, assembly definition for editor scripts. If Lux has an editor folder (which it seems to have) create an assembly definition there called "LuxEditor" or similar and make sure that only editor is ticked under assembly options.
    Or alternatively, remove the assembly definitions from DWP2 if you do not want to bother with them.
     
  49. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    WaterDataProvider.Instance is a static field that is used to determine which water data provider is used. Since the instance is set in Awake() of each WaterDataProvider the last one that had Awake() called will be used. So instead of disabling/enabling you can simply do
    WaterDataProvider.Instance = myWaterDataProvider;
    to switch between them. Not really elegant since I did not design DWP2 around two water systems being present at the same time.
     
  50. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Update v2.4.3 is on the way with the following changes:
    • Moved WaterObject gizmos to WaterObject from WaterObjectDebug. Changes to make Gizmos more similar to the ones on the initial release.
    • Fixed center of mass creep while the Rigidbody is marked as kinematic.
    • Fixed WaterObjectWizard using legacy CenterOfMass script.
    • Fixed WaterObject trying to access shared data before being initialized resulting in an out of bounds exception.
    • Fixed DragObject NullReferenceException issue.
    • Fixed disabled triangle state getting overwritten resulting in disabled objects still being simulated.
    • Fixed multiple issues with WaterObjectManager.Synchronize().
    • Optimized WaterObjectManager.Schedule().