Simple fish logics

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.

Video how it looks on my own project course, parts of my project, like everything except the fish and their behavior, are not included in this asset.

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”.

Quick start guide:

    1. In downloaded progect content folder find «/SimpleFishLogic/Blueprints» folder
    2. Rightclick «BP_FishMain» to open context menu, select «Assets Actions» and there select «Migrate…»
    3. 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)
    4. Close this project and open Yours, find «BP_FishMain» and place it whatever you want it on the scene
    5. 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.
    6. 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 — (from 58:00)

Same video can help to add this asset into your project (from 4:38)


v1.9 — 2024-03-21 (actual) — 1. Hotfix on some fishes species not spawn to desired quantity when BP_FishMain settings «Life timer» is smaller then «Spawn Timer Min» + 3 seconds. If you have v1.8 quick fix is to set value of «Life timer» = 6 or more(minimum «Spawn Timer Min» + 3). In 1.9 this will not be necessary, so not need worry about it in new version.
2. Changed simple water material to work on UE 5.4 properly.
3. Added saving of spawn points on spawn when spans from main actor or player’s pawn.

v1.8 — 1. Added possibility to use static meshes for main fish actors, add wanted meshes on BP_FishMain «FishMesh»(skeletal meshes) or «FishMeshST»(static meshes) settings. Skeletal meshes has priority, so if you add both — skeletal will be selected.
2. Improved near water detection and fish quantity set by adding at life timer more overlapping tests and check matching exists volumes options.
3. Added experemental generator of spawn points for start spawning fishes even if player not entered in water volume, just by entering in any near water volume trigger. This option named «Make Spawn Places» in BP_FishMain settings, is off by default.
4. Added delay option «Presense Detection Delay», setted on 1.0 by default. Possibly can save FPS with many fishes on scene.
5. Added aquarium exemple on demo scene, some text hints.

v1.7 — Small quick update to run on UE 5.3 (if you have performance drop in 5.3, just switch on DirectX 11 in project settings Project settings -> Platforms — Windows -> Targeted RHIs -> Default RHI -> DirectX 11)

v1.6 — Fixed a possible bug with spawn in unexpected places. Cleaned up some code.

v1.5 — 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:
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.