Simple Fish Logic — project available on Epic Games Store
An Unreal Engine Blueprint with simple logic based on random variables and tracers.
Very realistic looking fish behavior based on simple variables and tracers, a simple and beautiful solution to most simple, realistic underwater environments.
Warning! In version 1.1 is small ssue, appears when migrating fish into project without water plugin. To solve this disable from logics or delete «Water body preset name set» in BP_FishMain blueprint funcion named «WaterVolumesAddToTraceIgnore», see screenshot for details.
Video how it looks on my own project — https://youtu.be/tw5zSm4N4y8
For my game, I needed a simple blueprint with the logic of fish to fill the empty underwater spaces with life. Completing the development, I thought that it would not be bad to share this with you! Blueprint organizes a variety of fish behavior based on three basic presets: Koi, Cyprinus, Sprat. These presets roughly reflect the behavior of the fish whose name they bear, but at any time you can switch this setting to Custom, and edit the behavior in the direction you like.
In addition, the blueprint is able to track the player’s location and remove fish when they are not visible to the player in order to conserve resources. At the first start, the pond is filled with fish at a rate and quantity according to the setting.
At the same time, in those reservoirs where the first fish is installed, the filling starts from it, along its paths so that the fish does not appear outside the lake. But the blueprint is able to fill fish and lakes in which the first fish were not installed, in such cases the first fish appears at the player’s place when he is in the water, invisible, and sailing some distance — appears.
Blueprint saves all fish locations in all water bodies in a special FishesData array. Accordingly, it is desirable to save it when saving the game, so that when the game is loaded, the fish will immediately have the coordinates of the appearance, otherwise the lake will fill up at the initial speed.
Attention! Demo scene starts on 30FPS limit. You can disable this limit by binding button “3”. To enable-disable VSync, bind button “2”. Showing FPS stats toggles by “1” button. All those options is just for demo, configured in Event Graph in “./Demo/ThirdPersonBP/Blueprints/ThirdPersonCharacter”.
- In downloaded progect content folder find «/SimpleFishLogic/Blueprints» folder
- Rightclick «BP_FishMain» to open context menu, select «Assets Actions» and there select «Migrate…»
- Click Ok to apply selection of related assets and point to your project «Сontent» folder. (if you in UE5 have warning message «Some selected assets don’t have a corresponding content root in the destination. /Niagara», just answer «no», asset will migrate and work just fine)
- Close this project and open Yours, find «BP_FishMain» and place it whatever you want it on the scene
- Make sure «Pawn Relative» flags in all «BP_FishMain» actors placed on scene are all disabled. Otherwise, fish will not spawn more without more advanced settings.
- If fish act strange, like in this video(2:05:28), most likely water volume is solid actor, so we need to add it to all it actors to «Start Ignore Сlasses» array in all fish BP_FishMain actors placed on scene like in this video(2:08:37)
Advanced settings, customisation
- If You use UE Water, make sure WaterBodyPreset option is equal water‘s Collision Profile Name, to fish can detect water body and surface level correctly. (Usually it is by default, if wasn’t changed)
- If Yours project allready has mechanics to detect if playes pawn is in water, just add interface «BPI_Fish» and add in interface’s function «Is Player in Water» some boolian that must be true if player in water. Othervise, place and resize «BP_InWaterDetect» actor in every water under surface to it can overlap pawn only if it is in water, then add in your character interface «BPI_Fish» and copy in it’s event graph nodes from «BPI_Fish» feame commented «Thit must be placed in your character to detect if he is in water of near«, create all needed variables, do not forget to connect InWater and isNearWater boolian variables in BPI_Fish‘s mentioned earlier functions. Same for «BP_NearWaterDetect«, but this volume must overlap all water, previous volume and end around water on that positions where you want to fish start spawn and move when player on the way to the water. If Yours project allready has some near water detectors, just connect some boolian in «Is Player Near Water» interfaces «BPI_Fish» function.
- By placing «BP_NearWaterDetect» and adding and chosing it in BP_FishMain‘s, «Volumes Options» properties, there You can define fishes count to spawn in this water volume. So you can set to each lakes or water volumes needed fishes count to spawn.
- Fish spawning is handled automatically by timers delay setted in «Spawn Timer Min» BP_FishMain‘s properties. This time is in seconds, not in munutes! It defines minimum seconds to that timer. Spawned fish data stores in «FishesData» array in each BP_FishMain placed on scene, so if You want to fish spawn fast on it places when player return to the water, this array must be stored in Yours game’s save game data, and loaded in each BP_FishMain on load game respectively.
How to add fish on this logic can be see in this video, not in english, but can be helpful — https://youtu.be/GlUalktC8is?t=3483 (from 58:00)
Same video can help to add this asset into your project —https://youtu.be/GlUalktC8is?t=278 (from 4:38)
v1.5(actual) — Fixed not critical orphan references in material instance.
v1.4 — Fixed fish not spawning after visiting an area set to 0 fish. Added custom event «FushesCountRetrigger» to BP_FishMain which returns the original number of fish to spawn. Calling this is already written in BP_NearWaterDetect, but for the best work it is better to call the «FushesCountRetrigger» event on each BP_FishMain added to the game loading mechanism (if your game has one), after actually moving the character to the place where he will continue the game.
v1.3 — Fixed some bugs with crowd speeds, and added options for possibility to set small scales and speed by factor, for extra slow speeds when needed. This can be usefull when implementing someting like aquarium from this video.
v1.2 — Removed automative Water Body Preset logic, because it make compile error in progects without water plugin. (water plugin is non necessary for fish, asset designed to work in any kind of water with small options manipulation if needed)
v1.1 — Added better FPS independense mechanism, and option to disable old by setting variable FPSindependense in BP_FishMain details Fish settings section to 0. This settings now is default.
Also added logic to set Water Body Preset option automatically, but it was not good idea..