#Dash Script Error
1 messages · Page 1 of 1 (latest)
Seems like theres probably other logic deleting it, is there any scripts that delete other objects on the enemy?
yes i have a script that deletes enemies. but it shouldn't touch my character at all. if an enemy spawns outside my walls, it deletes the enemy and triggers the respawn action. I'm not sure though right now that thing doesn't seem to be working properly. Let me assign that deletion code as well.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
But I didn't write this code. I found this on google.
I would add a debug at least or breakpoint to see if any deletion code is happening. Your game objects wont randomly delete themselves without you calling it
like that?
sure, or anywhere that you are calling destroy if it exists in more places
I think I solved the problem.
I don't think it has anything to do with that script. So yes, that script is probably destroying it, but I was using the trail.Clear() method, which deletes the old trail points after dash in my dash script. When I removed it from the dash script, the error was fixed, but now every time I throw a dash, my old dash points are drawn to the screen.
trail.clear wouldnt remove anything from your player hierarchy still. try not to associate random things to solving the issue
something is destroying it, or moving it in a place where you didnt notice (probably unlikely)
I tried so hard to get this screenshot bruh.
however, when I delete the trail.Clear() method, it draws every location I put dash on the screen as seen here.
trail.Clear doesnt have anything to do with your player deleting
so what then? so I don't have any other script that can delete any gameobject.
its possible that the trail itself is being hit, or some object. its hard for me to understand the code since the comments arent english.
Did no debugs print at all when your player was deleted?
nope
Wait, I'll translate the comments to English and upload them again.
Honestly itll probably be better if you just try to isolate which script the error is in, possibly by disabling components or going through them all to see what logic is happening
Maybe you can even put a breakpoint in OnDestroy and try to see the stacktrace to see what called it, though im just speculating here because i havent done this before
https://hastebin.com/share/jubalahiyo.csharp here is the new code
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I would try the OnDestroy, add a breakpoint and try to see the call stack
OnDestroy being a unity message, which is called by unity when your object is being destroyed
oh so you're telling me to call that function?
no.. let unity call it because your object is being destroyed
then see the call stack so you can attempt to see what calls on destroy
like that?
should be fine like that, although im unsure if that breakpoint will be called on the { ever. Ive never done that personally
actually i choose the row where start with private. but visual studio behaves as if i clicked below line...
Where should I look now to see that callstack?
did you attach the VS debugger and actually get the breakpoint called?
the callstack would be in VS
oh nope sorry wait a min.
ah what you could do actually is this
https://forum.unity.com/threads/how-to-check-if-a-gameobject-is-being-destroyed.1030849/#post-8284941
then just add like a Debug.LogError in there, to see the callstack if its relevant
like that?
Seems fine, try running it and seeing if it ever prints
that trail renderer error might be just misleading you, if that somehow is running first and pausing your game before this error prints. Try unpausing once if thats the case
not logging
hmm
is this OnDisable script on the object being destroyed
The human continues to appear on the scene. and no, I put the script in the character movement script within the human itself, not in the destroyed object. (human still appears on the scenebecause my character's collider still exists even though it's gone.)
put this OnDisable in a new script and put that on the object being destroyed
on disable wont be called if its not disabled/destroyed
can you show the call stack of that error, click on it and expand the little area at the very bottom
this?
this line
Damn I really was hoping that would print out more
if you are completely unsure what is destroying/disabling your object, I would start by removing components and trying to replicate it. See where this exactly comes from
I suspect trail.clear() I put the trail.clear line in this line in the on cooldown end function, if there is no problem when it is like this, I think the problem is caused by this. When I searched the internet a bit, it said that trail.clear disables the trail and when you call the trail again, objects can be destroyed.
🤔 did you enable auto destruct on your trail renderer?
yes
ah well i guess that solves it.
That's not the problem...
hm?
https://docs.unity3d.com/Manual/class-TrailRenderer.html
AutoDestruct Enable this to destroy the GameObject to which the Trail Renderer component is attached after it has not moved for Time seconds.
you dont want auto destruct
omg wtf
honestly dont know why they made it destroy the object entirely
didnt even know this was a thing myself, i dont use trailrenderer much
lol np, honestly i never wouldve guessed it was the trailrenderer destroying the whole object until you said objects can be destroyed. You probably shouldve checked the api after seeing that 😅