#nullreference in build
1 messages ยท Page 1 of 1 (latest)
i am having an issue with nullreferences in the build and not the editor
what is happening is that none of my scripts seem to be able to access anything outside
their own gameobject
player2
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:Log (object)
generalmovementscript:Start () (at C:/Users/Admin/New Unity Project (2)/Assets/scripts/generalmovementscript.cs:63)
(Filename: C:/Users/Admin/New Unity Project (2)/Assets/scripts/generalmovementscript.cs Line: 63)
NullReferenceException: Object reference not set to an instance of an object
at generalmovementscript.Start () [0x001bc] in C:\Users\Admin\New Unity Project (2)\Assets\scripts\generalmovementscript.cs:104
(Filename: C:/Users/Admin/New Unity Project (2)/Assets/scripts/generalmovementscript.cs Line: 104)
Null
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:Log (object)
is a part of the erro log
Use code sharing guidelines for errors and code
!code
๐ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
And we don't need all the errors right away. Pick and share one.
this is a really small part of all the errors
i just wanted to show the two debug log reulsts
{
Debug.Log(gameObject.tag);
hold on
where can i find backquotes
this is line 61 62 and 63 of generalmovementsscript
Debug.Log(p1);
player1
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:Log (object)
generalmovementscript:Start () (at C:/Users/Admin/New Unity Project (2)/Assets/scripts/generalmovementscript.cs:63) oh i forgot that i needed this
Take a screenshot of the error and share the whole generalmovementsscript. Upload it to a paste site.
Line 63..?
CurrentMove4 = jam;
It feels like your code changes did not compile. The game runs an older code while you keep on making changes that don't apply
wait please tell me you rebuilt it
after
you changed the code
this is line 61 62 and 63 btw
this is line 37 and 38 of roundstart lemme post that
@storm ledge
ok
dlich might need to carry i cant put off studying any longer sryy
been procrastinating too hard ๐ฆ
There's no way this line could throw an error:
Debug.Log(gameObject.tag);
yeah it didnt
it returns player1
Please take a screenshot of one of the errors in the console...
there are both errors and normal logs in that text
the null is from line38
and an error occurs when i try to pull something from it in line49
p1 = GameObject.FindWithTag("player1").GetComponent<generalmovementscript>();
Debug.Log(p1);
yep that one
Try separating that line into 2. One that finds the object with the tag and the other one getting the component. Then debug the name of the found gameobject.
oh wow i think i just found the issue
it returns a descendant of the object i wanted apparently
Yep. It probably has the tag
one question though
why does it return the parent in the editor but the child in the build
If 2 objects have the same tag, there's no guarantee what object would be found first. It might be deterministic on one machine, but not deterministic between different machines and platforms. That's why it's not considered a great practice to use the Find method.