# Go.delete() and go.animate()

**URL:** <https://forum.defold.com/t/go-delete-and-go-animate/22843>\
**Category:** Bugs\
**Created:** [June 22, 2018, 5:07pm UTC](https://forum.defold.com/t/go-delete-and-go-animate/22843 "2018-06-22T17:07:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlfredriknybergbro](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/carlfredriknybergbro/32/8719_2.png) [@carlfredriknybergbro](https://forum.defold.com/u/carlfredriknybergbro)\
**Post date:** [June 22, 2018, 5:07pm UTC](https://forum.defold.com/t/go-delete-and-go-animate/22843/1 "2018-06-22T17:07:25Z")

</div>

Calling go.delete as a callback function for go.animate seems to cause some unexpected behavior.

```lua
go.animate("#sprite", "tint", go.PLAYBACK_ONCE_FORWARD, vmath.vector4(0, 0, 0, 0), go.EASING_LINEAR, 3, 0, go.delete)

```

The intended behavior is to fade the sprite to invisible over 3 seconds, and then deleting the game object. However, the actual behavior is the following (strange) output:

```lua
ERROR:SCRIPT: go.delete invoked with too many argumengs
stack traceback:
	[C]: at 0x7ff78758b1b0

```

It also does not delete the game object.

Of course, a local method (containing nothing more than go.delete() in its body) can just be created and call-backed to delete the object, so the severity is not particularly great, but the engine loses some adult points by just yelling **too many argumengs** when it faces this particular issue.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 23, 2018, 5:58am UTC](https://forum.defold.com/t/go-delete-and-go-animate/22843/2 "2018-06-23T05:58:46Z")

</div>

The thing is that the callback function of go.animate() will be called with self, url, property as arguments. go.delete() expects two arguments, id and recursive. So when you pass in go.delete() it will get called like this go.delete(self, URL, property) which is obviously wrong…

```
 go.animate("#sprite", "tint", go.PLAYBACK_ONCE_FORWARD, vmath.vector4(0, 0, 0, 0), go.EASING_LINEAR, 3, 0, function()
    go.delete()
 end)

```

The above will work.

---

<div class="post-metadata">

**Author:** ![Tremor\_Blue](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/tremor_blue/32/23330_2.png) [@Tremor\_Blue](https://forum.defold.com/u/Tremor_Blue)\
**Post date:** [February 26, 2021, 6:16pm UTC](https://forum.defold.com/t/go-delete-and-go-animate/22843/3 "2021-02-26T18:16:04Z")

</div>

Hi,

I have a question related to this.. I want to delete a gameobject after it is created in a factory.  
I dont want to use an attached script.. I have so many scripts that they are affecting performance.

Hence I am trying to use go.animate with a delete function..

I was trying this…

e.g

```lua
	local b = factory.create(component, p,nil,nil,scale)
	go.animate(b, "position.x", go.PLAYBACK_ONCE_FORWARD, p.x, go.EASING_LINEAR, 0.6, 0 ,function() go.delete(b) end)

```

Also tried it like this..

```lua
	local b = factory.create(component, p,nil,nil,scale)
	local url = msg.url(b)
	go.animate(b, "position.x", go.PLAYBACK_ONCE_FORWARD, p.x, go.EASING_LINEAR, 0.6, 0 ,function() go.delete(url) end)

```

But the game objects persist and memory fills…

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 26, 2021, 6:47pm UTC](https://forum.defold.com/t/go-delete-and-go-animate/22843/4 "2021-02-26T18:47:17Z")

</div>

> [@Tremor\_Blue](#):
>
> go.animate(b, “position.x”

Could it be that you are starting another go.animate() on “position.x” after you start the first one?

Couldn’t you use a timer instead?

```Lua
local b = factory.create(component, p,nil,nil,scale)
timer.delay(0.6, false, function()
    go.delete(b)
end)

```

---

<div class="post-metadata">

**Author:** ![Tremor\_Blue](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/tremor_blue/32/23330_2.png) [@Tremor\_Blue](https://forum.defold.com/u/Tremor_Blue)\
**Post date:** [February 26, 2021, 8:22pm UTC](https://forum.defold.com/t/go-delete-and-go-animate/22843/5 "2021-02-26T20:22:59Z")

</div>

Thanks for the response.. doesnt seem to work in my explosion function

```lua
function singleExplode(p)
	p.z = EXPLOSION_LAYER
	local component = "/createExplosions#explodedFactory"
	local scale = 0.6 + 0.3 * math.random()
	local b = factory.create(component, p,nil,nil,scale)
	timer.delay(1, false, function() go.delete(b)end)
end

```

Im having one of those days.. ☹ 😁

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 26, 2021, 9:00pm UTC](https://forum.defold.com/t/go-delete-and-go-animate/22843/6 "2021-02-26T21:00:04Z")

</div>

Are your saying the game object isn’t deleted? And how do you know that? Can you still see it? Is it perhaps a particle effect? The effect stays even if the game object is deleted.

---

<div class="post-metadata">

**Author:** ![Tremor\_Blue](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/tremor_blue/32/23330_2.png) [@Tremor\_Blue](https://forum.defold.com/u/Tremor_Blue)\
**Post date:** [February 27, 2021, 11:52am UTC](https://forum.defold.com/t/go-delete-and-go-animate/22843/7 "2021-02-27T11:52:13Z")

</div>

Yes its just a simple atlas with 6 frames.  
I put that function in a new project with the assets and it works fine.. just in the main project the timer does not get called.. I tried with a print statement.. seems like a deeper bug in my code.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 27, 2021, 4:55pm UTC](https://forum.defold.com/t/go-delete-and-go-animate/22843/8 "2021-02-27T16:55:18Z")

</div>

> [@Tremor\_Blue](#):
>
> seems like a deeper bug in my code

The `singleExplode` function is global. Could that be a problem? Perhaps not the function you think is being called? Do you have any errors in the console? Put a print() statement or perhaps a breakpoint and use the debugger?
