Forum begins after the advertisement:
[part11] map generations improvements diagonal null eror
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [part11] map generations improvements diagonal null eror
- This topic has 5 replies, 4 voices, and was last updated 1 year, 1 month ago by gamedev50.
-
AuthorPosts
-
August 6, 2023 at 7:24 am #11701::
the code is giving null error in CheckAndSpawnChunk method just for diagonal movements i cant fix it
August 7, 2023 at 1:58 pm #11702::Hi Gongy! There are a few reason why your
CheckAndSpawnChunk
method may be giving an error.- Your
currentChunk
may be null. Please check if you have assigned it in theChunkTrigger
script. If you have, make sure you have assigned it on the Trigger GameObject that should be under your Terrain Chunk prefab. - The
transform.Find(direction)
call may be returning null. This would happen if there is no child object undercurrentChunk
with the name that matches the string direction. Double check the name of your static points (i.e. Up, Down, Left, Right, Right Up, Right Down, Left Up, Left Down) and make sure they are correct. Also make sure to double check the strings of the direction in theChunkChecker
method. - The OverlapCircle or SpawnChunk methods could be attempting to use a component that doesn’t exist or hasn’t been assigned. For example, if you haven’t assigned the LayerMask of terrainMask, this could cause a null reference exception.
I have this helps!
If none of these things work could you perhaps share a screenshot of the error. It should show the exact line where the error occurs and it would make debugging much easier.
August 8, 2023 at 4:28 pm #11721August 8, 2023 at 4:28 pm #11720::https://prnt.sc/CJldbKJpGqIc https://prnt.sc/u9fK9Y3pJ_FC https://prnt.sc/UH_cRadyrKvc https://prnt.sc/sCC1seN5FR4j i am getting these errors and these are the lines with errors
and i notice one more thing when i start the game first 8 chunks left , right , up , down , right down , right up , left up , left down spawns perfectly but when i try to spawn another chunk it gaves to me this error for only diagonal directions. thx for help
August 14, 2023 at 11:18 am #11750::Hi Gongy,
For the issue you are facing, it is likely that your
currentChunk
variable in line 90 is null. Hence, when you try to accesscurrentChunk.transform
, you get a NullReferenceException.These usually happen when you forget to assign variables in the Inspector, or call
GetComponent<>()
to populate your variables.We’ve made a video here on how you can fix NullReferenceExceptions: https://youtu.be/dHyksxGUYbo
October 28, 2023 at 12:34 am #12123::Just in case anyone else has the same issue, I was able to fix this by moving all of my Static Points to be a direct child of the Terrain Chunk prefab, instead of under a Location Points Game Object. After that, I double checked that the Static Points had the layerMask set to “Terrain” and verified that the names matched the strings in the code. I then deleted my old Terrain Chunk prefabs, duplicated my new Terrain Chunk prefab, plugged the new prefabs into the Map Controller script, tested to see if it worked, and it did!
- Your
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: