Looking for direction | Insects crawling on floors/walls | Performance, modularity, help me make insects crawl on the floor/walls

Hello.

I am just looking for a direction.

I want to create tiny insects crawling on the floor and/or walls.
It would be great if the insects would react to player and avoid or run away from him, but if not, its ok too. Depends on the performance cost.

What would be the most modular and optimized way to make that?
Because the game is in production It HAS to be optimized and it has to be made in a way that level designers can place or determine in levels where they want insects and where they don’t want them.

Looking forward to see some ideas and/or directions and/or suggestions and/or tips!

I suggest you use particle emitter for this, either Particle-System or VFX-Graph. Spawn mesh particles on a plane and make them move randomly in local space so designers can resize & rotate this plane. Particle systems comes with plenty of tools to fake this and make it look good, although require some basic fx skills to setup. What’s more you can generate an additional textures with position normals or other custom data.

([181563-generatevisualeffectdata.zip|181563]) To implement this as VFX Graph you may want to think about it as two separate subjects:

Script that generates path data

This script can do raycasts, navmesh generation and sampling etc. - whatever you need to generate a valid path.

Here is a most basic example you can start from:

GenerateVisualEffectData.cs

using UnityEngine;
using UnityEngine.VFX;
[ExecuteAlways]
public class GenerateVisualEffectData : MonoBehaviour
{
	[SerializeField] VisualEffect _visualEffect = null;
	Texture2D _texture;
	void OnEnable ()
	{
		if( _visualEffect==null ) return;
  
		const int pathLength = 128;
		const int numPaths = 32;
		_texture = new Texture2D( width:pathLength , height:numPaths , TextureFormat.RGBAHalf , 0 , true );
		_texture.wrapMode = TextureWrapMode.Clamp;
		for( int y=0 ; y<numPaths ; y++ )
		for( int x=0 ; x<pathLength ; x++ )
		{
			Vector4 vec = Random.insideUnitSphere;
			_texture.SetPixel( x:x , y:y , new Color{ r=vec.x , g=vec.y , b=vec.z , a=vec.w } );
		}
		_texture.Apply();
  
		const string k_paths_param = "my point cache";
		if( _visualEffect.HasTexture( k_paths_param ) )
			_visualEffect.SetTexture( k_paths_param , _texture );
		else
			Debug.LogWarning($"no \"{k_paths_param}\" texture param",_visualEffect.gameObject);
	}
	void OnDisable ()
	{
		if( _texture!=null )
		{
			if( Application.isPlaying ) Destroy( _texture );
			else DestroyImmediate( _texture );
		}
	}
}

Vfx Graph

Vfx Graph that moves particles along pre-generated paths + all the special effects fx artists would add (mesh shader animation etc)