BlackthornProd / Random-Dungeon-Generation

The Random Dungeon Generation project !
45 stars 62 forks source link

templates is null in RoomSpawner's OnTriggerEnter2D #1

Open alialacan opened 5 years ago

alialacan commented 5 years ago

The project is throwing null pointer exception for RoomSpawner, Row:53 because of template reference is being null, when it detects collision. Normally, physics functions are called after the initialization functions (and it does find the reference of templates in start when I debug) but I still got that error in Unity3D 2019.1.3f1 Simply, adding null check for templates does the trick if anyone having this issue.

void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("SpawnPoint"))
        {
            if (other.GetComponent<RoomSpawner>().spawned == false && spawned == false && templates != null)
            {
                Instantiate(templates.closedRoom, transform.position, Quaternion.identity);
                Destroy(gameObject);
            }
            spawned = true;
        }
    }
carvrodrigo commented 4 years ago

just remove the SpawnPoint tag for destroyer object and it is good to go.

ghost commented 3 years ago

The project is throwing null pointer exception for RoomSpawner, Row:53 because of template reference is being null, when it detects collision. Normally, physics functions are called after the initialization functions (and it does find the reference of templates in start when I debug) but I still got that error in Unity3D 2019.1.3f1 Simply, adding null check for templates does the trick if anyone having this issue.

void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("SpawnPoint"))
        {
            if (other.GetComponent<RoomSpawner>().spawned == false && spawned == false && templates != null)
            {
                Instantiate(templates.closedRoom, transform.position, Quaternion.identity);
                Destroy(gameObject);
            }
            spawned = true;
        }
    }

Yes it will remove the error but in return there's a chance that the boss room will spawn with no entrance any chance to fix it in other way i will wait for response thank you

berk-efe commented 3 years ago

void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("SpawnPoint")) { if (other.GetComponent().spawned == false && spawned == false && templates != null) { Instantiate(templates.closedRoom, transform.position, Quaternion.identity); Destroy(gameObject); } spawned = true; } }

my instantiate line gives this error :

NullReferenceException: Object reference not set to an instance of an object RoomSpawner.OnTriggerEnter2D (UnityEngine.Collider2D collision) (at Assets/RoomSpawner.cs:63)

@carvrodrigo also I did what you said but it just solved another bug in if(collision.GetComponent).

martinbojovnik commented 2 years ago

Is easy to fix it only increase a number in Invoke methode

AlessioPoggi99 commented 2 years ago

Simply add this statement:

private void Awake() { templates = GameObject.FindGameObjectWithTag("Rooms").GetComponent<RoomTemplates>(); }

and remove it from Start function

Pasha1oooo commented 9 months ago

PLS Help!!!How i can repeat process of generation