Forum begins after the advertisement:
[part 2] Error Unity
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [part 2] Error Unity
- This topic has 10 replies, 2 voices, and was last updated 9 months, 3 weeks ago by Terence.
-
AuthorPosts
-
February 22, 2024 at 4:26 am #13380::
Hello, I rewrote the code several times, redid it several times, even copied the code, but I can’t understand why this error appears when we bind to Up Down Left Right
February 22, 2024 at 4:28 am #13383::void ChunkChecker() { if (!currentChunk) { return; } if (pm.moveDir.x > 0 && pm.moveDir.y == 0) //right { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Right").position, checkerRaduis, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Right").position; SpawnChunk(); } } else if (pm.moveDir.x < 0 && pm.moveDir.y == 0) //left { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Left").position, checkerRaduis, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Left").position; SpawnChunk(); } } else if (pm.moveDir.x == 0 && pm.moveDir.y > 0) //up { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Up").position, checkerRaduis, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Up").position; SpawnChunk(); } } else if (pm.moveDir.x == 0 && pm.moveDir.y < 0) //down { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Down").position, checkerRaduis, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Down").position; SpawnChunk(); } } else if (pm.moveDir.x > 0 && pm.moveDir.y > 0) //right up { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Right Up").position, checkerRaduis, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Right Up").position; SpawnChunk(); } } else if (pm.moveDir.x > 0 && pm.moveDir.y < 0) //right down { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Right Down").position, checkerRaduis, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Right Down").position; SpawnChunk(); } } else if (pm.moveDir.x < 0 && pm.moveDir.y > 0) //left up { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Left Up").position, checkerRaduis, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Left Up").position; SpawnChunk(); } } else if (pm.moveDir.x < 0 && pm.moveDir.y < 0) //left down { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Left Down").position, checkerRaduis, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Left Down").position; SpawnChunk(); } } }
February 22, 2024 at 5:03 am #13385::Is it possible that I didn’t distribute the area correctly?, but before making a change to the code, and when there were just cordianates, everything worked well, after I changed, here’s the error :(
February 22, 2024 at 10:40 pm #13386::It says that there is a NullReferenceException in line 67. I have to see line 67 of your code to pinpoint the issue to you specifically, but a NullReferenceException means that some object is not populated in your script.
Take this line for e.g.:
noTerrainPosition = currentChunk.transform.Find("Up").position;
If
currentChunk
is null, it becomesnull.transform.Find("Up")
which will cause a NullReferenceException.February 22, 2024 at 10:57 pm #13388::And I sent it to you, he swore at right down, but a little later I can send the full code because I’m not at home. And I’ll try what you wrote! But what’s strange is that even though I completely copied your code that you left under the lesson, it still caused this problem
February 23, 2024 at 2:53 am #13389::I came home, I’ll send you a pack of screenshots, see what could be wrong, but it’s very strange that I’m the only one who encountered such an error :D
View post on imgur.com
February 23, 2024 at 11:03 am #13394::It seems like your “Right Up” GameObject cannot be found in line 76. So:
currentChunk.transform.Find("Right Up").position
becomes:
null.position
Check if your Right Up GameObject is spelt correctly, with the same case and everything.
February 24, 2024 at 2:38 am #13409::<code> else if (pm.moveDir.x > 0 && pm.moveDir.y > 0) //right up { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Right Up").position, checkerRaduis, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Right Up").position; SpawnChunk(); } } </code>
What could be wrong with this code? It’s just your written code, I took it ctrl + c ctrl +v, and I still don’t understand what it doesn’t like
February 24, 2024 at 2:45 am #13410::The funny thing is, I removed the capital letter Right Up, but I still don’t want a square to appear on the left side, but the console doesn’t write anything, I tried to remove this capital letter from everyone, he started swearing at this line. In general, I don’t understand anything, but without that capital letter, it doesn’t write anything to the console, but it also doesn’t create endless locations for me, that is, I come to a gray surface
Could this be a problem because I’m using Unity 2022?
February 24, 2024 at 2:46 am #13411February 24, 2024 at 12:51 pm #13413::It’s very unlikely that this is a Unity 2022 issue. Can you show a screenshot of one of your Terrain Chunk prefabs?
You can also try looking at this post and see if the tip here helps: https://blog.terresquall.com/community/topic/part-2-map-generation/#post-12273
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: