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

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #11701
    Gongy Bongy
    Level 1
    Participant
    Helpful?
    Up
    0
    ::

    the code is giving null error in CheckAndSpawnChunk method just for diagonal movements i cant fix it

    #11702
    Xavier Lee
    Level 16
    Keymaster
    Helpful?
    Up
    0
    ::

    Hi Gongy! There are a few reason why your CheckAndSpawnChunk method may be giving an error.

    1. Your currentChunk may be null. Please check if you have assigned it in the ChunkTrigger script. If you have, make sure you have assigned it on the Trigger GameObject that should be under your Terrain Chunk prefab.
    2. The transform.Find(direction) call may be returning null. This would happen if there is no child object under currentChunk 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 the ChunkChecker method.
    3. 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.

    #11721
    Gongy Bongy
    Level 1
    Participant
    Helpful?
    Up
    0
    ::

    error
    70th line
    48th line
    31th line

    i got these errors on these lines . and i notice one more thing when i start the game first 8 chunks for 8 directions work fine but after that when i try to spawn new chunk it gaves me to this error for only diagonal directions . thanks for your help

    #11720
    Gongy Bongy
    Level 1
    Participant
    Helpful?
    Up
    0
    ::

    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

    #11750
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    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 access currentChunk.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

    #12123
    gamedev50
    Level 10
    Participant
    Helpful?
    Up
    0
    ::

    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!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: