Nothing I try works

Hi, this is my first time writing here but I just don’t know what to do atp.

I’m making a game for a college project. It generates a map out of a pool of prefabs. Each instantiated prefab has a DungeonEntrance that has a special material that will change color depending on the difficulty. For this I have three scripts IntersectionManager (generates the map), DungeonEntrancePreset (a scriptable object that holds a color, and a difficulty), and DungeonEntrance (generates a difficulty, and based on it, takes the correct preset and loads it to the material). All of this works fine, but I want to take the difficulty generation from DungeonEntrance to IntersectionManager, and it just won’t load the preset for some reason.

1st image is the block of code in IntesrsectionManager that generates and assigns the difficulty to the street. Second is the DungeonEntrance code. Fourth is the DungeonEntrancePreset Scriptable Object code.

using UnityEngine;
using UnityEngine.Rendering.Universal;
using UnityEngine.Tilemaps;

namespace SystemMiami
{
    public class DungeonEntrance : MonoBehaviour
    {
        [SerializeField] private DungeonEntrancePreset[] _presets;
        [SerializeField] private Material _material;

        private DungeonEntrancePreset _currentPreset;

        private void Awake()
        {
            _material = new Material(_material);
            TilemapRenderer tilemapRenderer = GetComponent<TilemapRenderer>();
            tilemapRenderer.material = _material;
        }
        
        public void SetDifficulty(DifficultyLevel difficulty)
        {
            foreach (DungeonEntrancePreset preset in _presets)
            {
                if (preset.Difficulty == difficulty)
                {
                    LoadPreset(preset);
                    break;
                }
            }
            Debug.Log($"Set Difficulty for {gameObject.name} to {difficulty}");
        }

        public void LoadPreset(DungeonEntrancePreset preset)
        {
            _currentPreset = preset;
            ApplyPreset();
        }

        public void ApplyPreset()
        {
            _material.SetColor("_Color", _currentPreset.DoorOffColor);
        }

        public void TurnOnDungeonColor()
        {
            if (_currentPreset == null)
            {
                Debug.LogError("No preset loaded");
            }
            _material.SetColor("_Color", _currentPreset.DoorOnColor);
            Debug.Log("Applying color!");
        }

        public void TurnOffDungeonColor()
        {
            _material.SetColor("_Color", _currentPreset.DoorOffColor);
        }
    }
}
using UnityEngine;
using UnityEngine.Tilemaps;

namespace SystemMiami
{
    public enum DifficultyLevel { EASY, MEDIUM, HARD }

    [CreateAssetMenu(fileName = "New Dungeon Entrance Preset", menuName = "Eviron/Dungeon Entrance Preset")]
    public class DungeonEntrancePreset : ScriptableObject
    {
        [SerializeField] private DifficultyLevel _difficulty;
        
        //Color for the door states
        [SerializeField] private Color _doorOffColor = Color.black;
        
        [ColorUsage(true, true)]
        [SerializeField]  Color _doorOnColor;

        //setters
        public DifficultyLevel Difficulty => _difficulty;
        public Color DoorOffColor => _doorOffColor;
        public Color DoorOnColor => _doorOnColor;
    }
}

Code is cute but debugging is where problems get solved.

It sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.