New Coder having a scoping issue i think

hi guys I’m very new to unity and C# and I’m having what I’m sure is a simple scoping issue and would like some advice.

this is my code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Example : MonoBehaviour
{
    public GameObject Map;
    public GameObject MapPinPrefab;
       
    private class Thing
    {
        Vector3 location;
        GameObject mapPin;

        public Thing(Vector3 l)
        {
            location = l;
            CreateMapPin();
        }

        public void CreateMapPin()
        {
            mapPin = Instantiate(MapPinPrefab, location, Quaternion.identity);
        }
    }

    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {       
    }
}

that gives this error

Error CS0120 An object reference is required for the non-static field, method, or property ‘Example.MapPinPrefab’ Example.cs 23

so i get that in my instantiate call MapPinPrefab must not be in scope but i don’t understand why or how to get a global in scope here.

i realize I’m probably being very dumb but any help/advise would be appreciated

Did you drag a GameObject into the field MapPinPrefab in your Inspector? This is the object reference that is required according to the error message.

before i wrote the instantiate line i did yes (a prefab)
with the instantiate line the code wont compile so you cant

MapPinPrefab belongs to an instance of Example. Thing does not have an instance of Example so it can’t get MapPinPrefab.

You could try:

public void CreateMapPin(Example example)
{
    mapPin = Instantiate(example.MapPinPrefab, location, Quaternion.identity);
}

or maybe

public void CreateMapPin(GameObject prefab)
{
    mapPin = Instantiate(prefab, location, Quaternion.identity);
}

MapPinPrefab would be reachable if it was static, but static fields do not work with the inspector. Something like the code above is most likely what you are after.

yea i thought this was the answer which means ill have to create my mappins not in the constructor or i have to pass the prefab into the thing constructor which i was trying to avoid because it seemed unnecessary.

your help is much appreciated thank you