Variable initialization in the Editor script

I’m having a problem with initializing a value in the unity editor.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;

[CustomEditor(typeof(CombatAbility))]
public class CombatAbilityEditor : Editor
{
    private static List<Type> combatAbilityComponentTypes = new List<Type>();

    private CombatAbility combatAbilityData;

    private bool showAddCombatAbilityComponentsButtons;

    private void OnEnable()
    {
        combatAbilityData = target as CombatAbility;
    }

    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        showAddCombatAbilityComponentsButtons = EditorGUILayout.Foldout(showAddCombatAbilityComponentsButtons, "Add Combat Ability Components");

        if (showAddCombatAbilityComponentsButtons)
        {
            foreach (Type combatAbilityComponentType in combatAbilityComponentTypes)
            {
                if (GUILayout.Button(combatAbilityComponentType.Name))
                {
                    CombatAbilityComponent combatAbilityComponent = Activator.CreateInstance(combatAbilityComponentType) as CombatAbilityComponent;

                    if (combatAbilityComponent == null)
                    {
                        Debug.LogError($"Tried to add Combat Ability Component of type \"{combatAbilityComponentType.Name}\", but failed to create instance.");
                    }
                    else
                    {
                        combatAbilityComponent.pertainedCombatAbility = combatAbilityData;
                        combatAbilityData.AddComponent(combatAbilityComponent);

                        EditorUtility.SetDirty(combatAbilityData);
                    }
                }
            }
        }
    }

    [DidReloadScripts]
    private static void OnRecompile()
    {
        Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
        IEnumerable<Type> types = assemblies.SelectMany(assembly => assembly.GetTypes());
        IEnumerable<Type> filteredTypes = types.Where(type => type.IsSubclassOf(typeof(CombatAbilityComponent)) && type.IsClass && !type.ContainsGenericParameters);
        combatAbilityComponentTypes = filteredTypes.ToList();
    }
}

I wrote a code like above, but the line 44(combatAbilityComponent.pertainedCombatAbility = combatAbilityData;) does not seem to work.
The above code actually runs, but the value is not initialized-probably gets reset- when the game starts running.
The value of ‘pertainedCombatAbility’ remains null.
To be more precise, each CombatAbility has CombatAbilityComponent such as DamageComponent, KnockbackComponent, StatusEffectComponent etc.
What I want to do in Line 44 is that I want each CombatAbilityComponents to have the information of what CombatAbility does they belong to.
When I write ‘Debug.Log("Pertained to: " + combatAbilityComponent.pertainedCombatAbility);’ below the Line 44, it prints out correct value in the console, but when the game starts, the value resets to null.
I can’t figure out what’s wrong with my code. Can anybody help? Thank you in advance.

What does that mean? Is the code running? What was the value before setting it? What is the value after? Breakpoint it and find out, or at least print it out!

What about adding the CombatAbility instance as the second argument to a Debug.Log() so you can click on it? Is it the one you think it is?

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.

What I meant was the above code runs, but the value is not initialized when the game starts running.
The value of ‘pertainedCombatAbility’ remains null.
To be more precise, each CombatAbility has CombatAbilityComponent such as DamageComponent, KnockbackComponent, StatusEffectComponent etc.
What I want to do in Line 44 is that I want each CombatAbilityComponents to have the information of what CombatAbility does they belong to.
When I write ‘Debug.Log("Pertained to: " + combatAbilityComponent.pertainedCombatAbility);’ below the Line 44, it prints out correct value in the console, but when the game starts, the value resets to null.
Sorry for not providing enough information of the question.
I editted the question.