Give objects an "on-create" and "on-destroy" property

In the Edit Object menu, there could be sections called “oncreate” and “ondestroy”
and in them you could make a set of events that trigger when an instance of the object is created or destroyed. It would be way more convenient that making a behavior for each object.

5 Likes

You can when you create a behaviour for an object

1 Like

I did always wonder why some behaviors have condition to check if object was just created
YET there is no condition in events to check if any object was created
I would love having such condition

You might move this to Feature requests.
Click on the pencil icon besides the title and change.

Do it means that we gonna have

if just deleted
if just created
conditions?..

actions too?
like delete object
Just deleted
something similar to the wait action…

asking bcs in rare occasions i too wanted something like this…

adding this to any object is extremely easy. You just create a behaviour with said lifecycle functions, if you want to use the functions on the scene, just create a function/parameter/variable(something that the scene can work with) so the scene can trigger whatever events you want to trigger on those steps.

Idea is to have conditions in events by default
Not being forced to add some behavior to each object

Imagine like you are able to make your own controls in each game
VS having remap behavior
BTW idk why its still not built in feature to topdown and platformer behaviors
But i hope you get the idea
It should be something that is there not something you need to add yourself

{"000kind":"GDEVELOP_Events Based Behavior_CLIPBOARD_KIND-jsBdHbLy912y8Rc","content":{"eventsBasedBehavior":{"description":"","fullName":"","name":"lifeCycle","objectType":"","eventsFunctions":[{"fullName":"","functionType":"Action","name":"onCreated","sentence":"","events":[{"type":"BuiltinCommonInstructions::Standard","conditions":[],"actions":[{"type":{"value":"critter::lifeCycle::SetPropertylifeCycle"},"parameters":["Object","Behavior","=","\"onCreated\""]}]}],"parameters":[{"description":"Object","name":"Object","type":"object"},{"description":"Behavior","name":"Behavior","supplementaryInformation":"critter::lifeCycle","type":"behavior"}],"objectGroups":[]},{"fullName":"","functionType":"Action","name":"doStepPreEvents","sentence":"","events":[{"type":"BuiltinCommonInstructions::Standard","conditions":[{"type":{"value":"BuiltinCommonInstructions::Once"},"parameters":[]}],"actions":[{"type":{"value":"critter::lifeCycle::SetPropertylifeCycle"},"parameters":["Object","Behavior","=","\"onScene\""]}]}],"parameters":[{"description":"Object","name":"Object","type":"object"},{"description":"Behavior","name":"Behavior","supplementaryInformation":"critter::lifeCycle","type":"behavior"}],"objectGroups":[]},{"fullName":"","functionType":"Condition","name":"Created","sentence":"","events":[{"type":"BuiltinCommonInstructions::Standard","conditions":[{"type":{"value":"critter::lifeCycle::PropertylifeCycle"},"parameters":["Object","Behavior","=","\"onCreated\""]}],"actions":[{"type":{"value":"SetReturnBoolean"},"parameters":["True"]}]},{"type":"BuiltinCommonInstructions::Standard","conditions":[{"type":{"inverted":true,"value":"critter::lifeCycle::PropertylifeCycle"},"parameters":["Object","Behavior","=","\"onCreated\""]}],"actions":[{"type":{"value":"SetReturnBoolean"},"parameters":["False"]}]}],"parameters":[{"description":"Object","name":"Object","type":"object"},{"description":"Behavior","name":"Behavior","supplementaryInformation":"critter::lifeCycle","type":"behavior"}],"objectGroups":[]},{"fullName":"","functionType":"Condition","name":"onScene","sentence":"","events":[{"type":"BuiltinCommonInstructions::Standard","conditions":[{"type":{"value":"critter::lifeCycle::PropertylifeCycle"},"parameters":["Object","Behavior","=","\"onScene\""]}],"actions":[{"type":{"value":"SetReturnBoolean"},"parameters":["True"]}]},{"type":"BuiltinCommonInstructions::Standard","conditions":[{"type":{"inverted":true,"value":"critter::lifeCycle::PropertylifeCycle"},"parameters":["Object","Behavior","=","\"onScene\""]}],"actions":[{"type":{"value":"SetReturnBoolean"},"parameters":["False"]}]}],"parameters":[{"description":"Object","name":"Object","type":"object"},{"description":"Behavior","name":"Behavior","supplementaryInformation":"critter::lifeCycle","type":"behavior"}],"objectGroups":[]},{"fullName":"","functionType":"Action","name":"onDestroy","sentence":"","events":[],"parameters":[{"description":"Object","name":"Object","type":"object"},{"description":"Behavior","name":"Behavior","supplementaryInformation":"critter::lifeCycle","type":"behavior"}],"objectGroups":[]}],"propertyDescriptors":[{"value":"","type":"Choice","label":"","description":"","group":"","extraInformation":["onCreated","onScene","onMemory"],"name":"lifeCycle"}],"sharedPropertyDescriptors":[]},"name":"lifeCycle","extensionName":"critter"}}

If you copy paste this on an empty behavior and add that to an object it gives that object an on Created condition and also a IsOnScene condition, I was not able to add the “on destroyed” but I left an empty onDestroyed function that can be filled like a normal event for most things.

there might be a hidden reason for lifecycle functions only existing on behaviors and prefabs, but I agree it would be cool in some instances, I avoid using the scene 's event sheet anyway, so I wouldn’t know

1 Like

Imo this could be useful for this reason:

when you create an object with action “create object” that object is picked in that event.

With something like if “object” just created.
You may have more versatility for subsequents events.

Like if “enemy” just created add 1 to var ID. and it will still pick that object at creation

and more…

but in truth i doubt it can be implemented bcs it would means to have something like
in a “middle (or before?) of a step” …a la Game Maker…
and i guess like in behaviours…

A working on create and on destroy, would need to be structured like a “while” event, not like another condition.

1 Like

I did always wonder why some behaviors have condition to check if object was just created
YET there is no condition in events to check if any object was created

Behavior needs this because otherwise they have no way to know when the object is created. On the contrary, in the main events you create the objects yourself, so you can add actions right below.

1 Like

And that is part i perfectly understand and am aware of

But from standpoint of person who don’t
I see single condition given to me thx to attaching behavior to my object
I don’t need that condition since i can directly do whatever under object creation action

Yet there is no default condition for it?
We have action to create / delete objects
By logic shouldn’t there be condition for on destroyed / created?

Is like hide/show actions vs change opacity
Do we need both?
Would change opacity be enough?

Cause i would say opacity change is enough
Same as you now say i can shove in whatever i want under object created action

Yet some ppl prefer to use hide / show instead set opacity to 0 / 255

Just matter of preferences
I would prefer to have built in condition to check if object was created or destroyed

I can live without them i don’t need them
Which does not mean i would not want to have them

Which condition are you referring to?

Cause i would say opacity change is enough
Same as you now say i can shove in whatever i want under object created action

The opacity condition:

  • pro: allows to keep track of the opacity without requiring a variable.
  • drawbacks: none as I doubt someone can be confused by it.

Created condition:

  • pro: none as it’s faster to just put actions directly below the “create” action
  • drawbacks: What does “created” mean? Is it the last one or all object created this frame?

Just matter of preferences
I would prefer to have built in condition to check if object was created or destroyed

Everyone has their own preferences but covering 100% of what few people needs make it worst for the many.
How would you feel if there were 20 results in the search for “create”? For instance:

  • create with Z position
  • create with Z-order
  • create with width/height
  • create with top-left-right-bottom
  • create with scaleX-scaleY
  • create with scale
    -…

I’m sure any of these can save time to 10% of people but they would make life harder for most people.

2 Likes

That single condition i mentioned was just example of logic (where i was referring to on created)

Opacity was also example
Imagine this as i see other engine like ct.js also using pixijs
I see in it spritesheet support i expect to see it in gdevelop also (since gdev also uses it)
NOT from technical side of things (i am not claiming to understand it) but from simple user standpoint

Trust me i know exactly what you are trying to tell

But what i am trying to say is NOT from technical side of things but from simple user perspective
It would be cool to have both on created/destroyed built in events and available in behaviors
Where again from simple user perspective i would say it would make more sense to have just built in conditions for both

Where i can’t disagree that we would soon swim in millions of conditions/actions if we add everything to make everyone happy which would make most unhappy

1 Like

…i would love to have a “if just created condition” when something like this happen::


instead to have everything all below the created action…(since it alredy looks like a mess)…shouldn’t be more maanageable to have something like this?:

…it seems cool at first glance…because you could even recall the same condition in external events…
…now…
i don’t know how much trouble something like this could cause…and how feasible it is
because it would be like stopping for a moment before the next events happens, but if i had the chance, is something i would like to
tests.

ps.: don’t take the ss seriously i just cut something in gimp.
edit.—u may not need to add the trigger once too…?..am rite…?.. :thinking:

If you really want to split the event in 3, you can use sub-events no need for this condition.

You don’t need this condition to use external events either.

do it means that the object created is still picked…in that case.?.. :astonished:

…in that case i’m a moron…

edit: maybe i got what u means…yes i can do subevents.
but with a “if just created” condition …i may still pick that object later at creation…i guess…thaz would be useful…and i don’t mean bcs variables but because is picked…at creation …

i can live without it…it was just curiosity

Just in case anyone sees this thread afterwards and isn’t 100% following the exchange above:

  1. When you create an object via the “create an object” action, that object is immediately added to the selected object list for any following actions.
  2. Subevents keep all object lists from parent events.
  3. Any actions that target ObjectA after you create ObjectA via an action, will automatically target that newly created ObjectA. They are your onCreate events, as they’re happening in the same event (or subevents).
1 Like

wait, what do you mean paste it on an empty behaviour? where in the behavior do i put it?

image
on the name, with empty behavior I mean a behavior with nothing in it (it can have stuff in it but pasting would delete everything)