Animation clip taking unexpectedly long time to finish - c#

I am trying to solve this problem which is really surprise for me. I have imported some max animation (different train object Animations). I am firing Below method on GUI click which attached to all train object. This code simultaneously run/fire on different trains Object. Some trains work correctly and animation complete timely while some take long time for animation completion.
public void HourSwitcher(string playShunt)
{
gameObject.GetComponent<Animation>().Play(playShunt);
gameObject.GetComponent<Animation>()[playShunt].speed = 20f;
}
I have also attach my debug logs. As u can see in log 1 image
train12 to 16 animation running running while the time 0(surprisingly).
and in image two train 17 worked correcly but train20-21 running and running

Refer to my this question and answer. It were much disappointing that no one able to identify the problem (maybe lack of much attention to this question). After working 4/5 days finally I got this.
It were mainly animation Culling type Problem. *For future use and help for the beginners like myself I am going to answer my own question.
Answer:
My animation culling type were selected to BasedOnRenderers which means that 'Animation is disabled when renderers are not visible'. i.e., my code were showing me that animation is playing but nothing acutal happening in my scene as my animation were far from camera view.
I solved this problem by selecting animation culling type to AlwaysAnimate (refer to this). It means that 'object is animated even when offscreen'.
My some animation were working correctly because they were coming under the view of camera while some animations were not working (while code showing that it is in play mode) and playing continuously/taking long time because they were far from my camera view.
Hope it will help others
Refer to this Questions also which I were asked (tightly associated with this problem):
Animation unexpected behaviour - Why animation becomes complete If my camera walk through the scene
Does culling affect animation.

Related

Unity Animation: Can I Skip/Forward the played animation by touch?

Halo guys, I'm literally new to C# on Unity. Can I ask some scripts if I may to you all. The case is somethings like this: I have an animation that played some sprites on a scene. I want to know if I can skip / forward the animation by touch using C# scripts placed on Empty Game Object. So the animation can move forward for 1 second / 2 seconds if the user touch the screen, so the animation more faster done playing or the user doesn't need to wait the animation that played to be finish.
I just think I may build that function with for statement and placed on void update. Please correct me if I'm wrong, and if I may put some code on you'r thought. Many thanks and cheers :).

Unity Dota style loading screen

I'm creating a 3v3 multiplayer game and I'm stuck on an important part before the gameplay comes in.
I was wondering how you would approach creating a Dota 2 style loading screen for loading characters into the game (Picture below).
Creating the UI isn't the problem. The problem is animating it to look clean while also having it actually load the game (terrain/gameobjects/etc) with a progress bar or something.
I load the level with this
PhotonNetwork.LoadLevel('Game');
Then a gameobject spawns each player with
PhotonNetwork.Instantiate('....');
This works pretty well with nothing in the scene other than a plane to walk on. Now I just need to create the loading screen BEFORE the character loads while actually loading the terrain/objects/etc.
If anyone could point me in the right direction I would really appreciate it.
Thank you
Dota 2 style loading screen example:
I think this is a perfect case to use for Scriptable Objects in Unity.
Because as far as i remember there are around 100 heroes in Dota 2 and only 10 of them will be picked. So the images in this loading screen would change based on player input. Therefore, you should create scriptable objects. Then you can change the image(hero) also modify/add nick names to it in Run time. So to sum up you will have 10(in Dota but 6 is your case) scriptable object in your scene but you will only modify the images and nicknames after player selects the heroes.
Another benefit would be since they are objects you can easily animate them move up and down adjust however you want.
Here is a tutorial from Brackeys that is perfect for your case. Good luck!

How to force repainting my scene?

I'm coding a script in Unity that is applying a sequence of motions to my camera, for it to follow a predefined path. I need to repaint the scene in between every small motion otherwise the scene is drawn only when it reaches its final position.
I tried a lot of options but I just can't find something working for me.
I already tried :
SceneView.RepaintAll();
HandleUtility.Repaint();
and it can't find the Repaint() method from the Editor or EditorWindow classes.
Any idea ?
rendering process start after each Update(). Let process your motion logic in several Update with interpolation between each update.

Animation unexpected behaviour - Why animation becomes complete If my camera walk through the scene

Maybe what I am going to ask you is unbelievable but It is my observation of Three days. I am unable to figure-out what is the problem. I have
asked my problem three times in different perspective but no luck.
Different but some kind (train) animation runs
at once on button click some animation complete on time while some not(play continuously-Don't know why). If I move my camera in the scene (a place where animation have to reach) then, my animation become complete but if I don't move or turn my camera then animation not complete even half hour passed.
I don't know what is the relation between camera and animation completion.
some things which I want to know
Why some animation complete on button click while the some not, even
the code is same and animation clips are right
Why those animation who play continuously, becomes complete as i walk
thorough my camera
What is relation b/w camera and animation play?
Is Train culling is the problem because i note that if i don't use the culling then, this problem occurring less(But occurring) as compare to train with culling.
Refer to my this question and answer. It were much disappointing that no one able to identify the problem (maybe lack of much attention to this question). After working 4/5 days finally I got this.
It were mainly animation Culling type Problem. For future use and help for the beginners like myself I am going to answer my own question here all questions are tightly associated with each other i.e., 1 answer to understand it:
Answer:
My animation culling type were selected to BasedOnRenderers which means that 'Animation is disabled when renderers are not visible'. i.e., my code were showing me that animation is playing but nothing acutal happening in my scene as my animation were far from camera view.
I solved this problem by selecting animation culling type to AlwaysAnimate (refer to this). It means that 'object is animated even when offscreen'.
Hope it will help others

Hide GameObjects to speed up game performance

My question is, how could I hide a GameObject when it is not being rendered by the camera, but to unhide it when it comes back into the camera view?
My code is the following:
void Update () {
if (renderer.isVisible) {
objectToHide.renderer.enabled = true;
}
else {
objectToHide.renderer.enabled = false;
}
}
The problem is, the object becomes hidden, so it can't be detected and unhidden.
Any help is appreciated!
(The goal is simply to speed up the FPS and improve game performance)
Your answer is simple. The game only renders the objects in camera sight. You can hide an object or even disable the renderer component but its not used for memory management or better process.
There are standard techniques for making a game run more effient. One of them is LOD or LEVEL OF DETAIL. You have a model with different polycounts and different texture resolution. When its near you use the highest polycound and highest texture resolution for further distance you use lower options.
Another technique is level streaming. If you have a big level and you want to game run on low memory or don't make players wait for long time for level loading, you have to do this. If you search a little you can find lots of information on different engines.
Most recent games have an option to choose foliage detail or environment detail. You can make a layer for every level of detail of your game and for every level of option player made you destroy those objects. Maybe I'm wrong but renderer.enable cant be good because the object still is in game and game just doesn't show it. You have to change many components to make it work and controlling all of them is hard.
To improve performance, you better try to destroy scripts and gameobjects as soon as they are not needed. Like bullets coming out of the game board, scripts that run just once and already finished, ...

Categories