Deleting an object before linking won't properly perform the link

Setup:
Have a cow and an ox in a scene like this.

Event 1:

Event 2:
image

Event 3 and result:


My guess:

Deleting the object doesn’t remove it from object picking, as you did notice, the creation action uses Ox.X() and Ox.Y() as parameters to get the position of the Ox that was about to be deleted, and it works normally.

Following: the link action probably linked the object that was about to be deleted instead of the newly created one, and since it probably takes one frame for it to realize the mistake, it gives enough time for me to catch the object in the second event.

Project download:
https://file.io/nVfLUGfyHxTh
Mirror:
https://tmpfiles.org/4006383/linkingbreak.zip

2 Likes

It sounds similar to this bug.

https://forum.gdevelop.io/t/object-focus-bug/53856/5?u=keith_1357

If you use an action it seems to pick the object. When you add another object, there are now 2 objects picked. When you link the object it can only link 1 object at a time so it links to the one already in the scene.

The type of the 1st action doesn’t matter. You can change delete to an action that sets a variable. It links the original object instead of the new object because the one in the scene is the 1st in the pick list.

1 Like

I believe Keith is correct.
Actions that target an object pick those objects (by design).

Deleted objects not being unselected from the list seems…odd, but you might confirm that’s the actual issue by getting the object picking tools extension and putting the “Unpick all instances” action after your delete action.

1 Like

So, by design, any action that references an object picks that object? That’s what seems to be happening.

I tend to think that only conditions picked objects except for a few actions. I guess it makes sense though.

Yes, that’s why when you use the create an object from a group actions, the following actions target the instance created by that action (along with any other previously selected instances)

I unpicked all objects after the deletion, now the objects get deleted as intended

Here is what happens without the action

Using a variable action gives the same result, the “create object” is ignored and the link happens to the one which boolean “a” is true

Some object parameter only applies to one instance (objectPtr). This is the case of the link action. It is generated like this:

gdjs.evtTools.linkedObjects.linkObjects(
  runtimeScene,
  (gdjs.Untitled_32sceneCode.GDNewSpriteObjects1.length !== 0 ? gdjs.Untitled_32sceneCode.GDNewSpriteObjects1[0] : null),
   (gdjs.Untitled_32sceneCode.GDNewSprite2Objects1.length !== 0 ? gdjs.Untitled_32sceneCode.GDNewSprite2Objects1[0] : null)
);

You should use a “for each” event to link several objects.

In this case (the first picture on the topic), it is picking the object that is about to be deleted and linking it to the Cow, which definitively should not be something that should be happening.

It’s expected. Instances that are deleted are not remove from the picked list.

Should not “create object” be prioritized? We would expect it to occupy index 0 on the list

Let me see if I understand.
Add object then link works fine

But Delete object , Add object , Link
Doesn’t because the delete action picks the object that’s about to be deleted. So, when another object is added, there are now 2 objects in the pick list. (the old and the new)

The link action always uses the first object [0] in the pick list so it adds a link to the object that is about to be deleted. Then after the event it deletes the object.

In the current version of GDevelop, created instances are always added at the end of the picked list because it’s faster to add at the end of Array, but you should never rely on your knowledge of the picked list order because nothing tell you it will stay this way in future releases of GDevelop.

1 Like