Can't rename GameObjects while CoordinateLabeler is running

Hi everyone,

it’s been asked once before but the advice to restart Unity does not work for me :frowning:

When CoordinateLabeler is active I can’t rename GameObjects in the scene hierarchy. I can do it in the inspector but I am curious as to what causes this behaviour.
I can select the object in the hierarchy, press F2 and it looks like I instantly lose focus of the text field.

The script is basically what Gary is showing us in the lecture:

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

[ExecuteAlways]
public class CoordinateLabeler : MonoBehaviour {

    TextMeshPro label;
    Vector2Int coordinates = new Vector2Int();

    private void Awake() {
        label = GetComponent<TextMeshPro>();
        DisplayCoordinates();
    }

    void Update() {
        if (!Application.isPlaying) {
            DisplayCoordinates();
            UpdateObjectName();
        }
    }

    void DisplayCoordinates() {
        coordinates.x = Mathf.RoundToInt(transform.parent.position.x / UnityEditor.EditorSnapSettings.move.x);
        coordinates.y = Mathf.RoundToInt(transform.parent.position.z / UnityEditor.EditorSnapSettings.move.z);

        label.text = coordinates.x + "," + coordinates.y;
    }

    void UpdateObjectName() {
        transform.parent.name = coordinates.ToString();
    }
}

Anyone got an idea? Using Unity 2020.3.32f1

2 Likes

The issue seems to be with the Version of the Unity Editor.
I’ve noticed that a newer LTS version of Unity was available, 2021.3.1f1.
After updating to that version my problem disappeared. UI seems to be somewhat changed too but hopefully this won’t give me trouble following the lectures :slight_smile:

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms