[ad_1]

I used to be making an attempt to create a debug view for my Water object in my Unity utility. The issue is that I generate the water at runtime, which makes it not possible to see what it appears like within the editor mode. To resolve this, I created a script that pulls a easy sprite representing my water:

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing Unity.VisualScripting;
utilizing UnityEngine;

[ExecuteInEditMode]
public class WaterEditor : MonoBehaviour
{
    [SerializeField] Sprite waterSprite;

    GameObject debugWaterObject;
    SpriteRenderer tileRenderer;
    Water water;
    
    void OnEnable() {
        water = GetComponent<Water>();
    }

    void Replace()
    {
        if (Software.isPlaying) {
            Debug.Log("Destroying debug object");
            Destroy(debugWaterObject);
            return;
        } else if (debugWaterObject == null) {
            Debug.Log("Creating debug object");
            debugWaterObject = new GameObject("Water Debug Object");
            debugWaterObject.rework.SetParent(rework);
            debugWaterObject.rework.localPosition = Vector3.zero;
            tileRenderer = debugWaterObject.AddComponent<SpriteRenderer>();
            tileRenderer.sprite = waterSprite;
            tileRenderer.drawMode = SpriteDrawMode.Sliced;
        }

        tileRenderer.dimension = new Vector2(water.width, water.peak);
    }
}

The thought is that I create a debug object in editor mode after which destroy it in play mode. Nonetheless, for some purpose, after I run my utility, I can nonetheless see the article within the editor:
Object is not destroyed

I am fairly certain that Destroy(debugWaterObject) is named, and the article shouldn’t be recreated in play mode. It appears that evidently it’s not being destroyed. I have not been capable of finding any rationalization for that. Why may this occur?

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *