Forum begins after the advertisement:
[Part 2] SerializedObjectNotCreatableException: Object at index 0 is null
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [Part 2] SerializedObjectNotCreatableException: Object at index 0 is null
- This topic has 2 replies, 2 voices, and was last updated 1 week ago by
Terence.
-
AuthorPosts
-
February 13, 2025 at 4:41 am #17249::
Hi everyone!
So I have been watching this tutorial: Creating a Rogue-like (like Vampire Survivors) in Unity — Part 2: Map Generation
And about 25th minute I ran on this bug:
SerializedObjectNotCreatableException: Object at index 0 is null
Below both scripts that I changed and since that time I have this bug (I can still run the game though):
MapController:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class MapController : MonoBehaviour { public List<GameObject> terrainChunks; public GameObject player; public float checkerRadius; Vector3 noTerrainPosition; public LayerMask terrainMask; public GameObject currentChunk; PlayerMovement pm; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { pm = FindFirstObjectByType<PlayerMovement>(); } // Update is called once per frame void Update() { ChunkChecker(); } void ChunkChecker() { if (!currentChunk) { return; } if (pm.moveDir.x > 0 && pm.moveDir.y == 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Right").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Right").position; SpawnChunk(); } } else if (pm.moveDir.x < 0 && pm.moveDir.y == 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Left").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Left").position; SpawnChunk(); } } else if (pm.moveDir.x == 0 && pm.moveDir.y > 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Up").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Up").position; SpawnChunk(); } } else if (pm.moveDir.x == 0 && pm.moveDir.y < 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Down").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Down").position; SpawnChunk(); } } else if (pm.moveDir.x > 0 && pm.moveDir.y > 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Right Up").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Right Up").position; SpawnChunk(); } } else if (pm.moveDir.x > 0 && pm.moveDir.y < 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Right Down").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Right Down").position; SpawnChunk(); } } else if (pm.moveDir.x < 0 && pm.moveDir.y > 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Left Up").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Left Up").position; SpawnChunk(); } } else if (pm.moveDir.x < 0 && pm.moveDir.y < 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Left Down").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Left Down").position; SpawnChunk(); } } } void SpawnChunk() { int rand = Random.Range(0, terrainChunks.Count); Instantiate(terrainChunks[rand], noTerrainPosition, Quaternion.identity); } }
ChunkTrigger:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ChunkTrigger : MonoBehaviour { MapController mc; public GameObject targetMap; void Start() { mc = FindFirstObjectByType<MapController>(); } private void OnTriggerStay2D(Collider2D col) { if (col.CompareTag("Player")) { mc.currentChunk = targetMap; } } private void OnTriggerExit2D(Collider2D col) { if (col.CompareTag("Player")) { if (mc.currentChunk == targetMap) { mc.currentChunk = null; } } } }
I have had to use FindFirstObjectByType as I’m using Unity 6
Would you be able to help me spot the bug or do you need any other information? Thanks!
February 13, 2025 at 6:33 am #17250February 13, 2025 at 3:28 pm #17251::@piskorskeeskee glad you managed to fix your issue. Any errors with serialized objects are more likely than not issues with the editor that can be fixed by closing and reopening.
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: