- Home /
JavaScript, lag spammed function call
So here's the deal
I am used JavaScript to make some scripts for my game (which I sort of regret- it was a production speed choice)
Now I have a very performance heavy script that use coroutines every where in it and atm the moment does cause considerable lag.
here's the problem occasionally it will randomly call a function twice-which double spawns a component
are there any uber technical programmers who know the specifics of this bug? does it stem from javascript or unity? is there any way I can make it only callable once?
just to rule out all the obvious mistakes -this script when it runs uses an event to spawn 8 other objects -after testing it multiple times, there is no pattern on which of the child objects have their function double called, its completely random - there is no random behaviors associated with this process - there is only one source that calls the function in question and there simply is no way it can run itself multiple times without causing even greater chaos - the source function is on the original object and the function in question is called on the spawned object -nothing is run in a repetition loop, not even an update function is used
Sorry I can't post the code, It's just so massive, and such a chain of events that it would probably confuse everyone here and take forever to understand it. PS I didnt mean that in any sort of vain or ego blotted way.
dude you have been spam$$anonymous$$g ridiculous questions for days now, THERE ARE TUTORIALS!!!!!!!!!. youtube unity for whatever subject, learn some basic program$$anonymous$$g ffs, try javascript "HelloWorld", but no one is going to answer a flurry of (sorry to say) stupid questions. Everyone here was a unity noob at one point and we all recognize that but you got to put forward a $$anonymous$$imum amount of effort here. Hell the scripting reference has example scripts that do 80% of what you ask.
Answer by Eric5h5 · Nov 17, 2012 at 09:17 PM
Functions are not ever randomly called twice just by themselves for no reason; it's something you're doing in your code. It sounds like what you have is difficult to debug, but I'm afraid that's what you'll have to do.
gee thanks captain obvious
I know they arent supposed to be called twice randomly but that is exactly what is happening
my actual question is if a lag and the use of coroutines could be responsible for having double function calls
yes the script is tricky to debug but I am entirely certain that there are no other calls to that function
especially because the double call doesnt always happen yet the conditions that enter that process are always the same except for the lag ingame. Like I said there are no random or changing variables used in this process.
it happens more frequently when the lag is worse
Your question is "does the bug stem from Javascript or Unity", the answer is neither. It's stem$$anonymous$$g from your own code, captain oblivious.
its really not, i can understand why you might think it is but just before the function call is an instantiation so if I were calling it twice I would see a double spawn but I dont
Answer by lil_billy · Dec 11, 2012 at 04:53 PM
Right so I love all the trolls that have been posting here. Honestly I knew that this subject would invite the obvious answers because it is well a common stupid mistake. However I didnt think that I would get purely crap for answers.
Anyways I will post my current results on this problem
Thanks to more intelligent external sources: I have found out that the root of the problem comes from instantiating within a coroutine and is compounded by mutating that new object within the same routine. So the problem comes from coroutine.
I havent yet figured out a surefire way to resolve this issue. im guessing the only thing to do is to put your generator outside in a non coroutine function
Your answer
Follow this Question
Related Questions
Converting function variable to CS 1 Answer
Unity crashed and corrupted my .cs file,Electricity went down and corupted a .cs file 1 Answer
broadcasting error for targetting script 3 Answers
IpointerClick Interface Error 0 Answers
Enemy AI C# 0 Answers