Checking an objects visibility in the scene from a script?

I’m developing a mini game and I’ve done everything so far in the patch editor. Basically if you lose, a losing screen will pop up and at this stage is turning the game elements’ visibility to off. However, this doesnt disable the objects just makes them invisible which mean they are still effecting the game.

A simple solution would have been at the end of the game, it flicks a boolean (isGameRunning) to off which will then effect everything else - but Spark AR doesn’t allow that because of loops.

So, in a workaround attempt I am trying to use scripting to find if an object is visible (the lose screen) and then get that bool into the patch editor to drive the other elements of the game without being caught out for using a loop.

Is there any possible solution for what I am trying to do?

Not ventured into scripting myself yet, but just a thought:
If the elements are in a different layer, would that make a difference?

It’s pretty difficult to manage game state in the patch editor, but you can store numbers in a null object position and read them back with the world position patch. That’s what I usually do if I just need to get some value out of the reactive loop so I can do some introspection.

When the game over screen shows, you can set a null position to vec3(1, 0, 0) or something, then compare that value from the world position patch in your “game active” state check to determine how things behave. I think you can actually use a 0 or 1 value as a boolean so that simplifies it a little.

One small trick I used for the Atlanta workshop was to move the objects out of the way!

So, I grouped all the objects inside of a null, and when the score crossed a certain threshold, the null object moves really far away (meaning no collisions would be detected)

Here’s the template from the workshop

Here’s the recording

Edit: formatting

1 Like