General questions about custom objects

EDIT:Before reading this,I apologize to have been a bit sceptical about the usefulnes of custom objects/prefab.The fact that all the pre-steps process to link/stick objects togheter can now be replaced by 1 object it is really a good thing and a very useful feature.

I was thinking to create a custom objects (collision box) that can transform to all his children weapons with each collisions and animations. But before doing this i need some answers that i’m gonna list here and hopefully may help others:

1-why do i need to place object inside the scene to use the extract function?..why i can’t do it from the object list…or better why i can’t create a custom object from the add object button or like an external layout where u can just put things inside?

2-can i create a custom object when needed with the classic “create object” action in the running scene?asking this bcs… let’s say i’ve something in the scene that for exists, needs the presence of the custom object…am i forced to drag the custom object inside the scene or i can create it when needed?

3-can i check collisions between a custom object and other non-custom objects inside the scene?

4-why / when to use custom objects?..i mean…i’ve an object that act as its own in a linked external event and i’m thinking to turn it into a custom object…
why should i turn it into a custom object?..what are the advantages?..what are the differences from to link an external event and create things there?

5-when i use in a custom objects “on created do” function is it the same as scene create action where the object is picked?if i assign a var below that, is the var assigned to all the childrens?

6-the wiki says “By doing this for more complex needs, you can break down game menus or even gameplay objects (like a player character, complex obstacles, enemies, etc…) into custom object that can be edited independently. Your scene stays simple and only focused on the high level details of your game.
waz the difference from coding an object (custom) outside the scene or coding an object inside the scene? how this can simplify the scene…aren’t the same lines of codes…but in a different places?

7-regarding performances, are there particulars situations where using custom objects may improve performances?

8-are custom object implemented bcs there will be “a must to have feature” later?

sry for asking all of this but before implement this and spend some more hours into it i prefer to have some advice first.

Thx

Just for some clarity. You’ve probably been using custom objects (prefab) for awhile. Button, sliders, switches and resource bars are all custom objects.

Custom objects behave mostly like regular objects. The mask though is a combination of the child objects. You can choose to exclude children objects from the parent mask.

Otherwise, you can add them at runtime and check for the collisions between the custom object and the scene object.

Within the custom object, you can detect collisions between the children. It’s a little more complex to test for collisions between individual children and scene object. Unless, you use something like in the platform or pathfinder behavior, you need to use a function to check for collisions between objects not inside a custom object. You also need to sync the object with the scene. Meaning placing the custom object at 0, 0. Otherwise it’s like when layers are out of sync. You need to call the custom object’s function from the scene to pass the scene object as a parameter.

You could use point is inside but you would need to offset the coordinate by the custom objects x, y.

1 Like

3-yes
4-the primary advantage that functions on cudstom objects have over external events is that those functions are certain to only run if that object exists on the scene, this inevitably improves performance.
5-onCreated works similar to atTheBeginningOfTheScene, events run only once on the frame the object is created. the var will be asigned to the thing you assign it to, if you add a local var it will be asigned to the parent object.
6-the docs say that you can make lots of cool things with prefabs and that is true, but the devs have told me again and again that its true intended use is making UI elements, and that other things should be done with behaviors instead, so don’t get too exited.
7.I think I already answered this one.
8.prefabs were implemented because a very interesting conversation happened a few years ago, which started because arthuro555 proposed “objectStates”(many variations of the same object being stored and managed from a parent object)

1 Like

you mean inside the custom object right?..so i i guess i can’t do that in the regular scene editor… am rite?

Ok this one help…it seems it’s indeed more complex than i thought

ok…but this is something i don’t get…i can disable the external event with a var if needed…but i understand your point.

…i’m not…i mean …i’m not exited yet…since i stil don’t find a place for custom objects in my game…

yep i rememberd to have argued about this one.

you know what i think…and i may be wrong…custom object are good to replace some conditions/behaviours like:
the follow/position actions or stick behaviour, the “first” for each create and link,some take into account …maybe…and thaz all to me…but maybe they gonna be more useful later as premade assets…like a full player AI enemies in the store, like eg controllers are for unity…ecc…in that case i could see their usefulness…but in truth at the moment it seems that i probably don’t need em…and thaz what i find strange…i was expecting something revolutionary…

what i’m interested more is the possibility to check their collision (childrens too) as we already do with other objects..(.this could even replace the request thread about collision’s naming)…

I’m not sure what you mean by this. You can add custom objects just like any other object. You add it to the scene with the editor or through actions. You can create the object or create a group and add it by name. Just like any other object.

Screenshot_20241014_092455_Chrome

If you want to add children objects then you can add them from within the custom object with the do step event or you can create a function in the custom object and create children from the scene.

Collison between custom objects and other scene objects is easy. There’s no difference. Custom objects use the collision masks of all of the children objects unless they are set to be excluded.

If you had 3 children objects. A collision with the custom object would happen when a scene object collided with any of the children that weren’t excluded.

Collision between children is simple. The children share the same coordinates.

Collision between scene objects and specific children is more complicated since the custom object children use their parents coordinates. So, 0, 0 is the top left corner of the custom object not of the scene.

If you place the custom object at 0,0 then collision between children and scene objects works fine. If the custom object isn’t at 0,0 then the collision will off by that amount. Collision will still happen but visually, they won’t be in collision. It’s like when layers aren’t in sync.

Some behaviors like the platform and pathfinding allow you to add behaviors to objects and then detect each other. They use mangers to sort of register the objects. I don’t think you can use this feature without Javascript.

Can you check for collisions between scene objects and children objects if you create a function in the custom object and then use that function from the scene. For continuous collision detection , the event in the scene would have to be run on each frame.

I’m saying function because you can create conditions, actions, and expressions and any function can check for collisions. You could create a condition that would check for collision between a specific child or you could create a condition + expression that would return something like the name of the child. That would behave like multiple masks.

The issue I have with custom objects is behaviors. It gets confusing because the children can have behaviors and the custom object can also have behaviors.

Say you add a platform and a platform character to a custom object. The 2 children would interact with each other. The problem for me is that the children wouldn’t interact with scene objects because the scene doesn’t see the children. The scene sees the custom object.

You can add the platform behavior to the custom object. But now the entire object is a platform character. The bounding box of the custom object is set by its children. So, the lowest object would be used as the bottom of the object. The other objects could move internally but they wouldn’t be able to interact with the platform unless they changed the overall custom object mask. The lowest object would basically be the feet for a character.

I don’t want to discourage anyone. The more people that use them, the better. The odds of getting new features will increase if GD see people embracing custom objects. So, use them, talk about them and make suggestions.

1 Like

Thx that explains a lot…

i’m on this third case…i’m, gonna dig into it more… if i have the time

1 Like

Keith have u tried to make a custom object with 1 2D particle object as children?
cos i got the red screen bug…so before reporting if u can double check.

to reproduce:
-create 1 square sprite object with piskel and drag it into the scene
-right click on it extract as custom object
-then i copied “from original scene” a particle object and pasted it inside custom object visual editor
-custom object have no conditions/actions
-create custom object at position x.y
-red screen after 2-3 secs , i wonder if it could be bcs i’ve the destroy when particles end thicked, or bcs i’ve no runtime event in cobject

The emmiter worked for me. No error. Are you using the most recent version of GD? Your error mentions object stacking. Are you using that extension?

1 Like

nope, i have nothing added, behaviors,effeccts ecc…
i’m gonna make a short video of my step

It should be a soft bug…cos some incompatibilities…i just made a fast test and the game is playable even with the error.there is no crash.

btw here’s my steps

don’t mind the dialogue i was just testing and i can disable it…it’s not the problem

what i noticed is that it happens when the particles end…as i said probably cos the thicked delete at particle end…but i may be wrong.

It seems to work for me. Did you try doing it in a new empty project? Also, are you using the most recent version of Gdevelop? I can remember that error but I can’t recall the context.

yes latest ver.
i could try from scratch…
but to me is something related to the particle…some settings there…

Found the problem. it’s a bug with the delete particle at end

guess it’s somthing related to destroy some children of a custom object in a non custom object event.

OK. It would probably help to create a new post as a bug report.

K. done, opened here

Also another thing
shouldn’t remove object form the scene list option remove the custom object in the scene cos it seems to not work…

btw with ver 5.4.216 the bug is still thgere i 've checked just now

Are you talking about when you delete an custom object from the object list and the object itself remains in the extension list? I agree maybe there should be the option to also remove the extension.

For me, it’s complicated because I think deleting a custom object should be a deliberate action. It’s not the same as deleting an object that just has settings and images. Custom objects can have a lot of functions and events inside them that would require a lot of time to recreate.

When you delete a normal object even a slider, the object itself still exists within Gdevelop or the server. If you completely delete your custom object it’s gone. You might want to delete it from scene 1 but still be able to add it to scene 2.

I do wish you could save custom objects locally to a list not just as an exported file. It would be nice to have a local depository or a way to add objects to the list without having to submit them to Gdevelop as a community object or extension. A sort of local entry.

nope i mean …
when you create a custom object, at the moment you have to drag it into the scene.
I guess when you extract it,it should remove it frome the scene (as it says to remove it from the instances list)…i’ve always thought that it was the meaning, since i’ ve always ended to remove it manually from the scene…

i mean the first object you drag intro the scene is the proxy u need to create the custom object so removing it after extract option, should be safer.

btw that bug is fixed upgrading stack ext to ver 0.2.0 as davy said…

Are you talking about this. I haven’t used that much.

Yep.
basically after u extract the custom object imo it should remove what you dragged into the scene.

I’m getting fun at using c.object the problem is what u said above
the fact that i can’t place the origin where needed make them unusable at the moment