I am currently making a system where i can easily asign points where my AI pathfinding will move between, like a route… This is for the editor so i can make the AI work better… BUT i am currently having a problem with [ExecuteInEditMode]…
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[ExecuteInEditMode]
public class Route : MonoBehaviour
{
public bool EditMode;
public Vector3[] routes;
public List<GameObject> routes_obj = new List<GameObject>();
void Update()
{
if (Application.isPlaying && !EditMode)
{
foreach (Transform obj in transform)
{
if(obj.transform.name != "Cube")
Debug.Log(obj.transform.name);
if (obj.tag == "RN")
if (Application.isPlaying)
Destroy(obj.gameObject);
else
DestroyImmediate(obj.gameObject);
}
routes_obj = new List<GameObject>();
}
}
}
This is just a part of the code as pasting it all in would take alot of space… my problem is that the foreach loop only returns every second object (i have 7 objects… “#0” → “#5” and “Cube”…) All the numbered once have the “RN” tag… but only #1, #3, #5 get’s deleted… What am i doing wrong? i amde the exact same piece of code (modified slightly but nothing that changes the actual code) without the “[ExecuteInEditMode]” and it works totally fine,… Is it an error with Unity? should i do this another way? i really don’t know what’s going on…
I hope this is enough information…