Reset Front and Back lenses
Hi there,
I have built a 2 sided lens - one side has a game with mechanics and a countdown, the other side has a face lens. I'm trying (and failing) to stop and reset the game lens on the back camera and enable it when you switch between the two. Is there a way to do this? It's easy to hide the front lens objects when playing the game, but when I go back to the game from the front lens, it is still playing if you have initialised the game on start.
I've tried to enable objects and scripts to no avail. I've seen posts that discuss this, but nothing as yet of how to do this.
I'm not a coder per-se, and have mostly been using the built in functionality to create the lens.
Any help would be extremely appreciated!
Rich
Hi again,
Does anyone have any thoughts on the resetting of games mechanics as per my original question?
Many thanks,
Rich
Hi Richard!
The most important thing to note is that you'd probably want to have a separate object to be your game controller that is not affected by flipping the camera front to back.
The idea here is that if you disable the object, its script won't run. So if you try to disable the back camera object, and its script is on that disabled object, then whatever logic you put in there won't run.
For example, here's an example logic, where on the back camera, the Lens prints an increasing counter every frame. If you switch to front camera, this counter will stop, and the counter will reset to 0.
Can't wait to see your final game!
Cheers,
Jonathan
Thank you Jonathan for your response.
If it’s ok I wanted to show you in a little more detail so I can get this right as I feel it’s a bit more complicated. Or maybe it isn’t!
So, I have this set up. Various cameras are performing various things. The main thing is that when I go from front lens to back lens the game has been playing in the background and the countdown is still counting down. I want to completely reset to its original state when the lens was initially launched.
Below are the cameras and objects within my project. ‘Game mechanics_Back Camera’ is where all the functions for my Whack A Mole styled game are held.
Here is the open ‘Game mechanics_Back Camera’ object. There are objects for the game, lighting, an animated countdown, an update score at and of countdown and the simple high score controller.
Within in this is an object with further controls ‘Recycle_Bin_Behaviour’. This houses a number of holes which instantiate objects into the scene at given times throughout the game. When the countdown ends, the instantiated objects are timed to end just before that.
Here is an example of the instantiation scripts on Hole_1. As you can see, once the script is activated to start the behaviour, it runs through the events. They have been triggered by the initial touch event of a button at the start of the game. The countdown is also triggered by this button.
So, with your script – could you help understand how to apply to this logic? In my head, once the scripts have been initialized they are off and running. Basically, how do you reset all of this (including scripts running and tween that have run) to their original state. As mentioned previously I’m not a coder, so it’s taking me a little time to get my head around this!
Many thanks again,
Rich
Hey there, just wondering if anyone might have a solution to the above? Would greatly appreciate some help in this matter.
Hi Richard,
That looks like an impressive game setup!
To reset the tween and behavior, you can use
and then call that function when you want the tween and behavior to reset.
You can see an example of this in use in the SpectaclesTimeLoopHelper script of the Spectacles Depth/Path template.
Secondly, one thing to be careful about is that the Behavior script does not manage the instantiated object--this means that over time your game will keep creating new objects which might overload the phone's memory.
Consider taking a look at the Spawner script found in the High Score template, which has an option to destroy spawned objects after certain time. Another way to do it maybe is to create a script in the prefab which calls destroy() on itself after a certain period of time.
Let me know if you need any clarification!
Thanks,
Jonathan
HI Jonathan,
Thanks for responding in such difficult times. Much appreciated. Thank you for the 'destroy' function - that helps heaps!
On the tween restart I'm struggling to get my head around it.
I can see that this will reset the tweens, but what I really need is to reset the counter/countdown in some way. In the game, the counter is counting down from 20 to 0. When it hits zero the game resets itself. I was hoping there was a way to reset the counter when the camera flips which would in effect reset the game - a forced countdown to zero if you like
See I need to stop the behaviours that have been initialized in whack a mole game, reset the counter and bring up the initial start screen. - basically reset the whole thing to its original state.
Does that make sense?
As said I'd not a coder, so I get a bit fuzzy when I see the code - where to apply it etc. so if you could walk me through that would be of immense help!
Thanks again for your response :)
Hi There,
I've tried to implement the above scripting to no avail. Could you help me little more?
So I added a reset tweens script in the objects panel and a behaviour. I'm not sure this is the right way to call it?
Here's the script you created:
Then a behaviour script which enables/disables the script.
My understanding (which may be incorrect) is that when I flip to front lens, this should enable the script and reset all the tweens and behaviour. When switches back to back lens it should disable and so on through flipping.
Your thoughts on this would be appreciated. I can't seem to get to work!
Best,
Rich
Hi there, Any thoughts on this? Cheers.
Hi Richard,
You're close. We just need to modify that script to let it listen to a custom trigger on Behavior:
Then in your Behavior Script call the custom trigger "triggerReset"
Additionally, for optimization, you can comment out the original script that has to do with resetting base on time (since we're manually controlling it.
Cheers!
Jonathan
Hi Richard,
You're close. We just need to modify that script to let it listen to a custom trigger on Behavior:
Then in your Behavior Script call the custom trigger "triggerReset"
Additionally, for optimization, you can comment out the original script that has to do with resetting base on time (since we're manually controlling it.
Cheers!
Jonathan
Hey Jonathan,
Thanks for getting back. Still struggling with it. This is my set up:
I've replaced the script with the new one supplied which is now titled triggerReset. The behaviour triggers on front camera and the Trigger Name is triggerReset.
Nothing is happening. Is the set up correct? Just to be sure, this will reset all tweens and behaviours back to their original states?
Is it worth sending you the files or am I missing something simple here?
Hi Richard,
Hmm that's strange--what version is your Behavior Script, maybe it doesn't have the reset API. If you open the script it should be
// Version: 0.0.4
In the onLoop function, try adding a bunch of print("1") inside the function and if statements, that way you can see whether the script or the pieces of the script are being called or not.
Thanks!
Jonathan
Hi Jonathan,
It's version 0.0.4
I placed the print function as follows and can't see that.
Not sure in the right place!
Hi Jonathan,
I've put the print function here and it prints:
So that works but still not performing when on mobile device.
Hi Richard,
Hmm, can you try this example project where I combined the trigger and behavior?
Thank you,
Jonathan
Hi Jonathan,
I've tried the example project and this is the logger for it. I dropped it into my project as well. This still doesn't seem to work.
Hi Richard,
Hmm, it should reset your behavior and tween. Can you share the project for us to take a look at? Might be easier than just going back and forth :)
Thanks,
Jonathan
Yes that would be great. Do you have an email I can send to?
Hi Jonathan,
I'm good to send you the files if you're ok with that?
Best,
Rich
Hey Jonathan,
Any chance of sending this file over to you?
Best,
Rich
Hi Richard,
We have spent some time looking over your project. It is such an amazing project and quite complex! We have crafted and sent you a custom response for the specific problem on camera switch. Enjoy!
Happy creating :)
Nico
There is no inbuilt method to reset a Lens. You can however write a script that sets the values of your Lens to a starting state.