[Solved] How does the "Count" of objects now work?

I would like an explanation of how the new way of Counting objects works. Because in previous versions, there was only one version of the function, now there are two, one working together (I believe) with “Pick all objetcs” and another for the scene.

In the game we are developing for gamejam, I noticed that some things don’t work like they used to and I had to adapt to make it work, which I found more work.

I made an example, I would like you to take a look, why it doesn’t work.

In the example I want the text to show only objects that are in collision with a certain object. Same when not in collision

https://drive.google.com/file/d/1T4p7MJVzfPR5ob4MjAiriC5cfgZZstul/view?usp=sharing

Before, both the “Number of objects” condition and Count() expressionwould actually pick all instances of that object, which was confusing to a large majority of users. The expression also picking objects, was unusual behavior.

The two new expressions and conditions have pretty detailed descriptions in the engine currently, but to reiterate on those, they work as following:

Number of object instances currently picked (or the “PickedInstancesCount()” expression):

  • This shows the total number (count) of instances of that object that are picked by the current event.
  • So if you have a “TestObject X position is > 100” condition, having the “Number of TestObject instances currently picked > 2” condition will mean the event will only fire if there are at least 2 or more TestObjects that have an X position greater than 100.
  • If you just have “TestObject X position is > 100”, and then have an action that uses the PickedInstancesCount() expression, it will return the total number of TestObjects that have an X position > 100

Number of object instances currently in the scene (or “SceneInstancesCount()” expression):

  • This shows the total count of that object instances in the scene, regardless of the current event conditions.
  • This is useful for if you want to create more objects if the total count of objects falls below a certain number, and then apply actions to just that new instance you create in the same event. With the old condition/expression, using “number of objects < 100” as your condition, creating a new instance and then applying actions to it would apply those actions to all instances, since the condition picked all of the instances.

Overall, the big change is that the new conditions and expression do not pick any objects. If you would like them to also pick objects, you just use “Pick all instances” after the rest of your conditions, or in your actions.

1 Like

Okay, I understand in parts. For example. How do I show only objects that are colliding with another scene object?

It’s like this:

I would like it to return only the number of the object that has the ID =5. In this example above it shows all, even the ones that are not colliding

Correct. As mentioned above, “SceneInstancesCount” is to return a total count of all instances of that object in the scene. It doesn’t care about conditions or actions. You would want to use PickedInstancesCount.

1 Like

Okay, the first part works. Shows only the ones that are in collision. Now the second part:

I want to make the player object deleted as soon as all objects_2 are no longer colliding with the room

not like that

not like that

Sorry!

You will never have any object_2’s picked by using collision if they’re not in the room, so I don’t think any combination of count will work as there’s no objects picked.

Why not just use “Not” > “Object_2” is in collision with Room", no count should be required.

It’s actually still in the scene, I just pulled it out of the object collision.

Look:

Because even if I use it like this, it deletes the player

Yes, as mentioned, the since you have no objects in the room, the “PickedInstancesCount” is already filtered out and nothing for it to count.

On the flip side, the “SceneInstancesCount” won’t work because there are more than 0 Object_2s (and it isn’t filtered by conditions).

I don’t think a count is going to work with what you’re trying to do for collision. I would remove the count logic entirely for that part and just check that all instances are not in collision with the room, so just use the “Not” and “Object_2 is in collision with room” (do not use invert).

Ahhhhh, that way it worked again. The same in the game I’m developing… Now, excuse my ignorance! But why has that changed? I don’t remember having to use “NOT” for this. Used “NOT” when it was other situations, like the raycast itself.

Invert and Not do not apply the same rules.

Invert is basically “If anything doesn’t apply this condition, treat as true.”

“Not” says “if the opposite of this condition is true, treat as true”.

When you have a single instance of an object, in most cases they will behave the same. When you have multiple instances of an object, they will behave very differently in most cases.

2 Likes

Thanks @Silver-Streak for clearing my doubt.

1 Like