Trying to get access to variables in the editor script

I am trying to get my script to run in the editor when i press a button, but i have 4 variables which which is not public so i don’t have access to them in editor script. These 4 variables are checked by the update function, and they are used by the TerrainManagerStart function. I am new to editor scripting and a semi noob in C#


The affected varibles:

            CustomTerrainValues customTerrainValues;
            TerrainThreadContainer terrainThreadContainer;
            ConcurrentQueue<TileData> tileCQ = new ConcurrentQueue<TileData>();
            Vector3[] tilePos;

public class TerrainManager : MonoBehaviour
{


    //the max tileMeshSize is close to 250
    public int tileMeshSize = 250;
    [Range(5, 1000)]
    public int tileCount = 20;

    public int continentMassModifier = 10;
    public int continentDistanceMax = 250;
    public int continentAmount = 1;

    public int tileSizeScaleModifier = 1;
    public int perlinNoiseScale = 1;
    public int perlinNoiseHeigh = 1;

    public int settelmentCount = 0;
    public int cityCount = 0;
    public int miningCount = 0;


    bool terrainGenerationStarted = false;

    //Add Biomes 
    //Terrain characteristics for diffrent areas examples hills ,canyon, plains, sanddunes.

    CustomTerrainValues customTerrainValues;
    TerrainThreadContainer terrainThreadContainer;
    ConcurrentQueue<TileData> tileCQ = new ConcurrentQueue<TileData>();
    Vector3[] continetArray;
    Vector3[] tilePos;

    void Start()
    {
        tilePos = new Vector3[tileCount * tileCount];
        terrainThreadContainer = new TerrainThreadContainer(tileCount);

        customTerrainValues = TerrainVariblesAssembly
                    (
                    tileMeshSize, 
                    tileCount, 
                    tileSizeScaleModifier,

                    continentMassModifier,
                    continentDistanceMax,
                    continentAmount, 

                    perlinNoiseScale,perlinNoiseHeigh, 

                    settelmentCount, 
                    cityCount, 
                    miningCount 
                    );

        TerrainManagerStart(tilePos, customTerrainValues, terrainThreadContainer, tileCQ);
    }

Editor script

    public class TerrainGeneratorEditor : Editor
    {
    
        public override void OnInspectorGUI()
        {
            TerrainManager terrainManager = (TerrainManager)target;
            base.OnInspectorGUI();
    
    
    
            if (GUILayout.Button("Generate world"))
            {
    
                terrainManager.TerrainVariblesAssembly(terrainManager.tileMeshSize,terrainManager.tileCount, terrainManager.tileSizeScaleModifier, terrainManager.continentMassModifier, terrainManager.continentDistanceMax, terrainManager.continentAmount, terrainManager.perlinNoiseScale, terrainManager.perlinNoiseHeigh,
terrainManager.settelmentCount, terrainManager.cityCount,terrainManager.miningCount);
    
                terrainManager.TerrainManagerStart(tilePos, customTerrainValues, terrainThreadContainer, tileCQ);
                
            }
            
        }
    
    }

I could solve this by using a while loop that would replace the update().
Do need to rethink how i approach the code? Do i need to try in bake these 4 variables in the function? preferable i don’t want to make those variables public.

Why do you pass variables that are stored in the same class where the method is located as parameters? Why don’t you just use the variables inside the method directly? That’s the point of having instance methods. Instance methods work on the instance and have access to everything inside that instance.

Since we don’t know what the TerrainVariblesAssembly actually looks like and what it does it’s kinda pointless to speculate about that.

The whole point of using public variables is to access them from other scripts, if you want to access them from other scripts but don’t want to make them public then you need public methods to get and set the variable, or use a property. If you want to access the variable from the editor without making it public then you have to add [SerializedField]

As others have commented, you have to expose something for it to be used externally.

I would encapsulate that logic inside a public instance method on the original class (public void GenerateWorld()), so I wouldn’t have to expose ‘sensitive’ members outside.

I solved my problem on my own, by rewrite my scripts to not check thread tasks against the MonoBehaviour update() and instead use a while loop. These include 3 different C# files with around 150 lines of code so its too much to share, so that would became a wall of text. But the 4 variables have all been baked into TerrainManagerStart() and some other script.

Script

    public int tileMeshSize = 250;
    [Range(5, 1000)]
    public int tileCount = 20;

    public int continentMassModifier = 10;
    public int continentDistanceMax = 250;
    public int continentAmount = 1;

    public int tileSizeScaleModifier = 1;
    public int perlinNoiseScale = 1;
    public int perlinNoiseHeigh = 1;

    public int settelmentCount = 0;
    public int cityCount = 0;
    public int miningCount = 0;


    void Start()
    {
        CustomTerrainValues customTerrainValues = TerrainVariblesAssembly ( tileMeshSize, tileCount, tileSizeScaleModifier, continentMassModifier, continentDistanceMax, continentAmount,  perlinNoiseScale, perlinNoiseHeigh, settelmentCount, cityCount, miningCount );

        TerrainManagerStart(customTerrainValues);
    }

Editor

public class TerrainGeneratorEditor : Editor
{

    public override void OnInspectorGUI()
    {
        TerrainManager terrainManager = (TerrainManager)target;
        base.OnInspectorGUI();



        if (GUILayout.Button("Generate world"))
        {
            CustomTerrainValues customTerrainValues = terrainManager.TerrainVariblesAssembly
                        (
                        terrainManager.tileMeshSize,
                        terrainManager.tileCount,
                        terrainManager.tileSizeScaleModifier,

                        terrainManager.continentMassModifier,
                        terrainManager.continentDistanceMax,
                        terrainManager.continentAmount,

                        terrainManager.perlinNoiseScale, terrainManager.perlinNoiseHeigh,

                        terrainManager.settelmentCount,
                        terrainManager.cityCount,
                        terrainManager.miningCount
                        );


            terrainManager.TerrainManagerStart(customTerrainValues);
            
        }

        
    }
    

}