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.

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.

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