Performance: Multiple asset references vs. One public asset reference

I am making a dungeon crawler where each room can spawn its own enemies. Right now I need a way to reference the enemy prefabs. One way of doing it is by having the references on the room script, like this:

public class Room : MonoBehaviour
{
	[Header("Enemies")]
	[SerializeField] Enemy enemy1;
	[SerializeField] Enemy enemy2;
	[SerializeField] Enemy enemy3;
    // etc..
}

Another way of doing it is by having a static AssetHolder class that has all references that can be queried like so:

AssetHolder.Enemy1Prefab

I honestly prefer the first one in terms of code (one less class, better structured) but I want to ask which one is better in terms of memory usage and performance.

Thanks.

Technically, static variables are more memory heavy than local variables, but in this use case, with just a few enemies, it really won’t make any difference. Generally, the main things that affect performance are spawning or destroying large amounts of objects, as well as obviously having a lot of unoptimized objects in camera view, like high poly models.

If what you are looking for is a way to reference different type of enemies, I would create a scriptable object that have references to all enemy types, and then you create a variable that holds this scriptable object. Scriptable object will only create a unique instance across all rooms so it will be performance friendly, and also it will be a clean way to look for prefabs and no static classes.

Also, 100% sure you will need a Singleton class that controlls some logic of the game, so maybe you can reference the scriptable object there, and access it fastly with the singleton class.