Unity: Detect If Animator Is Idle on UI Element - unity3d

Animator has to be disabled when the UI element is idle(ie not pressed).
Catch: UI Element is enabled/disabled from outside, not in sync with the animator. Can't modify those controls.
Tried:
Checking via enter/exit events on an idle state
Checking via animation events on an idle state
Problem: Enabling and Disabling Animator disables state related events and hamper proper firing.
How to detect that the animator is not being used and disable it?

Related

Unity Input System event triggered without input

Using the "new" Unity Input System.
I have a start scene with a menu and from there I can load the game scene where I have a TouchManager, the touch manager allows me to control the player and to visualize the force applied to the player.
To visualize the force I have a game object that starts disabled and with the touch manager I enable the visualizer only when there is touch input.
The issue is that at start of the game scene the touch visualizer is enabled, although after the first touch it starts working perfectly.
With debugging I see that the event that signals "touch" is fired (without touch) but the event that signals the release isn't.
Regarding the code there is nothing particularly relevant as far as I am aware, so I briefly explain: (Scripts by order of execution)
GameManager:
Awake() the game is set to pause;
Start() the game is set to "unpause";
TouchManager:
Pause(bool isPause) input events are subscribed and unsubscribed;
Move is the input that is causing the issue.
I tried to disable the visualizer but has to be on update since the event that enables it is triggered after start method and I dont know how/when the touch event is triggered, also I would like to fix the issue at the source instead of covering up.
Any ideas?

If a GameObject will be activated and deactivated, should it be static?

Say you have some GameObjects which are using Render Mode: Screen Space - Camera. These will be hidden and shown via activation and deactivation. Are they to be considered Static, or no?
In order to activate or deactivate a GameObject it doesn't matter if it's static or not. Unlike a dynamic GameObject a static one has disabled movement
at runtime but it doesn't lock its active state. At least that is my case.

Unity3d Animation - How to make the player to stay at the target position after the animation completes

Created a simple animation to move a cube from (0,0,0) to (5,0,0).
When the animation stops, cube is going back to (0,0,0). How to make sure that the cube stays at (5,0,0) even after animation completes
You could also checkout the AnimatorState WriteDefault value.
Whether or not the AnimatorStates writes back the default values for properties that are not animated by its Motion.
By default it is enabled so if the State is left the Animator resets to the default values of your inanimated objects.
If you disable this value than the last state stays persistent although the state is left or the Animator disabled.
Got it working using simple Animator state machine with idle, moveLeft and moveRight states and appropriate triggers!!!

Entry Animation does not play again when Animator is disabled then enabled

I have an animation I created called "FallingTile" that plays on my object on the Entry phase of the Animator. The problem is, because I need to change the color of the object throughout my game I need to toggle the Animator on only when it's being used, and then disable it again (this seems to be the only way to be able to change the object's color still). The first time the object's Animator is enabled the "FallingTile" effect runs smoothly and the Animator is disabled properly. However if I try to trigger the same object to animate again it will not do so. I don't believe Entry is only ran the first time the Animator is enabled because I use the same type of system for fading in/out background colors. Here's what I'm trying:
public void FallingTilesAnimation() {
Anim.enabled = true;
Invoke ("DisableAnimator", 1.1f);
}
private void DisableAnimator() {
Anim.enabled = false;
TileImage.material = null;
}
I also tried setting the Animator state back to Idle before disabling it to see if maybe that was the issue but it didn't seem to help.
edit: Probably worth noting my object starts with no material and one is added/manipulated in the FallingTile animation. It should go back to having no material after the animation ends to "reset" to the pre-animation object.
edit2: I realized it may be that Entry only runs the first time the Animator is enabled. For changing background colors I'm changing the active state of the entire object - setting the object to active likely triggers Entry again but enabling the Animator a second time may not?

Unity particle system only plays if i hit SIMULATE button

I have a prefab with a particle system attached. In the code I play the particle by using this code
ps.enableEmission = true;
When i run the game, and that code executes, the particle emitter does not emit anything in the "game" window unless i press simulate button in the "scene" window.
Anybody knows why?
For the emission property to work the particle system has to actually be playing. To do this you can either enable Play On Awake in the ParticleSystem component or you use the Play method on an instance of the ParticleSystem component.
As a side note, if you are using 5.3+ the enableEmission property is now obsolete and you may want to consider using the emission property. One thing to keep in mind when using this property is you have to assign it to a variable before attempting to modify it:
public ParticleSystem _ps;
...
private void Update()
{
ParticleSystem.EmissionModule module = _ps.emission;
module.enabled = true;
}
UPDATE #1
In response to your tractor beam example in the comments I would probably suggest using SetActive on the game object that has the ParticleSystem component. By using SetActive it will prevent extra particles being emitted and will destroy any that are active, i.e. those currently in the scene.
If you use the Emission property, then it will prevent the emission of extra particles, but it will not destroy any that have already been emitted.
One other approach would be to use Play and Stop methods but these, as with the emission property, will not destroy any active particles. If you use these methods, then some things to watch out for are:
If the Prewarm option is not enabled, then Play does not start
emitting particles (not sure why this happens)
The isPlaying property will remain true as along as there are
active particles in the scene. Once these die, then it will
be set to false
The Stop method will not destroy particles active in the scene
If the ParticleSystem has stopped and you call Play while there are particles active
in the scene, then all active particles are destroyed and the
ParticleSystem starts emitting a new set of particles
Check out to see if particle GameObject is active when you call ps.enableEmission = true; on it. To show or hide particles i normally use gameObject.setActive() not ps.enableEmission.
My particle was not simulating and after I changed the culling Mode to Automatic everything worked. The default is pause and catch-up.