Problem with EditorGUI.IntPopup

I’m trying to use the EditorGUI.IntPopup and the values i settled are shown, however when i choose a different value of the initial one, it doesn’t change at all

here’s the code

@CustomEditor (SpawnPoint)

class SpawnPointEditor extends Editor {

    function OnInspectorGUI () {
    
    	var targetObject : SpawnPoint = target as SpawnPoint;
    	
    	var rect : Rect = GUILayoutUtility.GetRect(1, 115);
        EditorGUI.LabelField(rect, "\nFor Players, use ID:\nPLAYER FRONT LEFT = 0,\nPLAYER FRONT CENTER = 1,\nPLAYER FRONT RIGHT = 2,\nPLAYER BACK LEFT = 3,\nPLAYER BACK CENTER = 4,\nPLAYER BACK RIGHT = 5\n");
        EditorGUILayout.Space();
        
        var intPopRect : Rect = GUILayoutUtility.GetRect(1, 20);
        
        var test : String[] = new String[3];
        test[0] = "Valor 0";
        test[1] = "Valor 1";
        test[2] = "Valor 2";
        
        var intTeste : int[] = new int[3];
        intTeste[0] = 0;
        intTeste[1] = 1;
        intTeste[2] = 2;
        
        
        targetObject.id = EditorGUI.IntPopup (intPopRect,"ID", 1, test, intTeste);
        EditorGUILayout.Space();
        DrawDefaultInspector();
        
    } // OnInspectorGUI
    
} // class

any idea what am i doing wrong ?

---- EDIT ----

i love how things aways work out as soon as i post
well, i thought the “selectedValue” argument was just to set the value the popup was going to show on the begin, but its an argument to link the value that is going to be aways shown

so i changed the “1” to “targetObject.id” and everything worked how it was supposed to
line i changed → targetObject.id = EditorGUI.IntPopup (intPopRect,“ID”, 1, test, intTeste);

new question on the same topic, EditorGUI.IntPopup …
everything was right till tried a new object
now when i change a value on the IntPopup, it states that the value changed, but when i execute my game, it changes back to the initial value
the code:

#pragma strict

@CustomEditor (SpawnPoint)

class SpawnPointEditor extends Editor {

	private var maxId = 12;

    function OnInspectorGUI () {
    
    	var targetObject : SpawnPoint = target as SpawnPoint;
    	
        EditorGUI.LabelField(GUILayoutUtility.GetRect(1, 105), "\nFor Players, use ID:\nPLAYER FRONT LEFT = 0,\nPLAYER FRONT CENTER = 1,\nPLAYER FRONT RIGHT = 2,\nPLAYER BACK LEFT = 3,\nPLAYER BACK CENTER = 4,\nPLAYER BACK RIGHT = 5");
        EditorGUILayout.Space();
        EditorGUI.LabelField(GUILayoutUtility.GetRect(1, 40), "\nFor Monsters, use any ID from 0 to 11\n");
        EditorGUILayout.Space();
       
        var possibleIds : int[] = new int[maxId];
        var options : String[] = new String[maxId];
        for(var count : int = 0; count < possibleIds.Length; count++) {
        	possibleIds[count] = count;
        	options[count] = count.ToString();
        } // for        
        
        targetObject.id = EditorGUI.IntPopup(GUILayoutUtility.GetRect(1, 20),"ID", targetObject.id, options, possibleIds);
        EditorGUILayout.Space();
        DrawDefaultInspector();
        
    } // OnInspectorGUI
    
} // class

Example
It starts on “0”. Then i change the value on the Inspector IntPopup to “3”. The changed value stays there till i execute the game, and then it changes back to 0 before the game actually execute

– EDIT –

Just found that the “0” value comes from the prefab which i settled the SpawnPoint script on
So, when i make a new GameObject from the Prefab, it doesn’t let me change the attribute value because the script is aways reading my “target” as the Prefab, and not the GameObject
how do i fix that ?

– EDIT 2 –

got the solution using SerializedObject

code working:

#pragma strict

@CustomEditor (SpawnPoint)
@CanEditMultipleObjects

class SpawnPointEditor extends Editor {

	private var maxId = 12;
	private var targetSpawnPoint : SerializedObject;
	private var idProp : SerializedProperty;
	
	function OnEnable () {
    	// Setup the SerializedProperties
        targetSpawnPoint = new SerializedObject(target);
        idProp = targetSpawnPoint.FindProperty("id");
    } // OnEnable

    function OnInspectorGUI () {
    
    	var targetObject : SpawnPoint = target as SpawnPoint;
    	
        EditorGUI.LabelField(GUILayoutUtility.GetRect(1, 105), "\nFor Players, use ID:\nPLAYER FRONT LEFT = 0,\nPLAYER FRONT CENTER = 1,\nPLAYER FRONT RIGHT = 2,\nPLAYER BACK LEFT = 3,\nPLAYER BACK CENTER = 4,\nPLAYER BACK RIGHT = 5");
        EditorGUILayout.Space();
        EditorGUI.LabelField(GUILayoutUtility.GetRect(1, 40), "\nFor Monsters, use any ID from 0 to 11\n");
        EditorGUILayout.Space();
       
        var possibleIds : int[] = new int[maxId];
        var options : String[] = new String[maxId];
        for(var count : int = 0; count < possibleIds.Length; count++) {
        	possibleIds[count] = count;
        	options[count] = count.ToString();
        } // for        
        
        idProp.intValue = EditorGUI.IntPopup(GUILayoutUtility.GetRect(1, 20),"ID", idProp.intValue, options, possibleIds);
        targetSpawnPoint.ApplyModifiedProperties();
        EditorGUILayout.Space();
        DrawDefaultInspector();
        
    } // OnInspectorGUI
    
} // class