Timeline for How can I fix this NullReferenceException error while all the references are set to specific objects?
Current License: CC BY-SA 4.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 26, 2023 at 0:48 | comment | added | DMGregory♦ | I don't recommend adding that to this answer because I don't recommend that way of accessing this data. You can post a new question about how to access boss positions from a StateMachineBehaviour if you'd like some software engineering advice about how to structure this. | |
| Jun 25, 2023 at 19:49 | comment | added | Ali |
Thank you for your help! It works very well and just needs some tweaking in Unity. I also want to mention something to future readers about the null error. They need to write their equivalent of TheSmallestStain_ShootingTriggers shootingTriggers; in another script as public and add the name of that class when they want to reference the variable. This is because it's not possible to drag objects into scripts that derive from StateMachineBehaviour. This is also the reason I wrote bossPositions in that script. I can add this to the answer as well if that's okay.
|
|
| Jun 25, 2023 at 14:10 | vote | accept | Ali | ||
| Jun 25, 2023 at 1:38 | comment | added | DMGregory♦ | Trivial fixes added. | |
| Jun 25, 2023 at 1:38 | history | edited | DMGregory♦ | CC BY-SA 4.0 |
added 14 characters in body
|
| Jun 24, 2023 at 23:56 | comment | added | Ali |
The second error is on the second part of theBoss.transform.position = shootingTriggers.bossPositions[maxTriggerEntered]; and states that it can't convert Transform to Vector3. I'm trying my best to solve them but it may take a while as I don't have experience with these specific errors.
|
|
| Jun 24, 2023 at 23:53 | comment | added | Ali |
So, I use the new scripts now (I know that Debug.LogError lines were added to find the null variable; but I'd like to keep them as well so I can fix the potential future bugs more easily). But there are some errors in both scripts that I should fix before I can test them. The first two errors are from the second half of public static bool[] enteredTriggers = new[10]; which state that the rank specifier is invalid and no best type found for implicitly typed array.
|
|
| Jun 24, 2023 at 23:37 | comment | added | Ali | Thank you very much for your answer and comments! Before seeing the answer, I checked all the variables and found that 'shootingTriggers' was the null variable. This was because I used 'animator' to access it while it wasn't attached to the game object that had the animator component. So, I added that variable to another script and dragged it into the inspector. This solved the error; but for some reason, the boss couldn't transition to the correct positions. Now, with the help of your answer, the code is noticeably short and efficient. (Continues in the next comment) | |
| Jun 24, 2023 at 21:28 | history | answered | DMGregory♦ | CC BY-SA 4.0 |