Search Unity

Bug How to connect enemySpawner script with settingPath script?I am using DOTween library

Discussion in 'C# Job System' started by KuchurinYegor, Jan 17, 2023.

  1. KuchurinYegor

    KuchurinYegor

    Joined:
    Nov 17, 2022
    Posts:
    1
    It's my first game, so I would really appreciate if someone would help!

    I want enemies that are spawn with enemySpawner script to move with a certain path that is generated with a method in settingPath script, however after adding this method in enemySpawner coroutine it gives me a NULLReferenceExeption:

    NullReferenceException: Object reference not set to an instance of an object
    EnemySpawner+<EnemyWavesSpawner>d__7.MoveNext () (at Assets/Scripts/EnemySpawner.cs:45)

    I can't find the root of the problem.

    Here is a pathScript that has a method SetEnemyPath that takes a GameObject as a parameter and than sets a path for this GameObject to move

    sequencer.png


    Here is a enemySpawner script that has a coroutine which is spawning enemies with waves.So here I wanted every enemy in the wave to have a different path to follow.
    spawner.png


    And here is coroutine in which this method should be working, right after Instatiating enemy it should follow the path that is created by SetEnemyPath method

    enumerator.png
     
  2. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    581
    Use code tags. Screenshots don’t help anybody.
    This is the wrong place to post, as well. Questions like this go in the Scripting subforum.

    The error message in the thrown NullReferenceException means a reference to an object being used to access a member (field / property / indexer), call a method on it, etc. is not set to a valid object. That makes it impossible to go through with calling a method or getting / setting a field or property or indexer.

    Look at the line number the error message points to and figure out what variable or field / property etc. might be null.

    You can also use a debugger to set a breakpoint at that line and check objects being used in that context and see what is null among the things used in that line.
     
    Last edited: Jan 17, 2023