Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[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 *