So I wanted to make a simple sprite snapping script to make sprite placing easier.
I first made a Editor Window script so that the user can select the sprite size and if snapping should be enabled, which worked. But since the Update function a Editor Window class only runs when the actual window is open, I needed to make a second class which handles the actual snapping, and is of type “ExecuteInEditMode”.
So I made a script, did everything but it doesn’t seem to call the Update function in my script.
This is how the editor script looks like :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[ExecuteInEditMode]
public class EditorTileAlign : MonoBehaviour
{
private void Update()
{
Debug.Log("Ran");
if (!Application.isPlaying && EditorTileAlignWindow.IsAlignerEnabled())
{
GameObject[] selected = Selection.gameObjects;
for (int i = 0; i < selected.Length; i++)
{
if (EditorTileAlignWindow.GetTileSize().x != 0)
selected<em>.transform.position = new Vector3(Mathf.Round(selected<em>.transform.position.x * (1 / EditorTileAlignWindow.GetTileSize().x)) / (1 / EditorTileAlignWindow.GetTileSize().x), selected_.transform.position.y, selected*.transform.position.z);*_</em></em>
if (EditorTileAlignWindow.GetTileSize().y != 0)
selected.transform.position = new Vector3(selected.transform.position.x, Mathf.Round(selected_.transform.position.y * (1 / EditorTileAlignWindow.GetTileSize().y)) / (1 / EditorTileAlignWindow.GetTileSize().y), selected*.transform.position.z);*_
if (EditorTileAlignWindow.GetTileSize().z != 0)
selected.transform.position = new Vector3(selected.transform.position.x, selected.transform.position.y, Mathf.Round(selected_.transform.position.z * (1 / EditorTileAlignWindow.GetTileSize().z)) / (1 / EditorTileAlignWindow.GetTileSize().z));
}
}
}_
}
—
The line Debug.Log("Ran");
never actually prints out anything in the console, which is how I know that Update is never being called.
I do know that Update should only call when there’s a change in the scene, but I have tried moving my tiles in the scene view, and nothing prints to the console anyways.