Jump to content

animated container plugin and performance


Recommended Posts

I've created a container with drill bits that use Bahamuto's BDanimationModules (https://github.com/BahamutoD/BDAnimationModules/blob/master/BDAnimationModules/AnimatedContainer.cs) plugin to show how full/empty it is. The animation consists of 11 elements that follow same path in the container (so 2 keyframes per object). Now the problem is performance, having 10 or even 5 such containers in the scene seriously slows down KSP (yellow timer).

Is there any animation trick or plugin edit that I can use to improve performance?

Photo below: 2 trucks, each with 5 drill bit containers results in low fps and yellow timer even when there's no animation:

ty1eUO8.jpg

edit: changed title to better describe a problem

Edited by riocrokite
Link to comment
Share on other sites

You could try using the skinned mesh renderer. That would allow the animated meshes to be combined into a single object. To set this up if you are using blender youll need to use an armature to drive the meshes. The advantage of this is that you can use the more extensive bone constraint system in blender to bake the animation. I have not done any benchmarks on if this method results in better fps or not. From what i read the disadvantage of using it is that there is a greater cpu overhead as the vertecies needs to be translated before drawing(only while the animations are playing) but less total drawcalls because of the lower object count. There may be a point at which it becomes better than standard parent/child animations (if there are many moving parts) but im not sure when that is.

That is if there are not other setup related or keyframing issues causing the slowdown.

Edit. Read the op again. Saw your using a plugin for the animation. So im not sure if this could be the cause or not. The animations would still be played by the unity legacy animation component but perhaps the plugin is polling for animation status too often causing cpu overhead. But seeing as its the one made by bahamuto it should be pretty optimised(the guy made a kickass mech game from scratch:cool:) but worth checking out in the source nonetheless

Edited by landeTLS
Link to comment
Share on other sites

I've seen random performance issues pop up with animations here and there, but I can't give you anything definitive. There shouldn't be performance issues, I can tell you that much. What happens if you trigger the animation with stock or FS modules?

Link to comment
Share on other sites

I think the reason lies in the plugin (or unity limitations), however don't know how to resolve it.

@lo-fi: I've tried to trigger animation with stock animation module, max fps when animation is not triggered, low fps only with animation:

http://i.imgur.com/mF7wIn6.png - before animation

http://i.imgur.com/KEBsQzd.png -when animating

http://i.imgur.com/h45ol73.png - after animation

@landeTLS:

the whole code I use from Bahamuto is here:

https://github.com/BahamutoD/BDAnimationModules/blob/master/BDAnimationModules/AnimatedContainer.cs

Code consists of 4 elements: onStart, onUpdate, onUpdate in editor and AnimationState.

I've tried deleting whole 'onUpdate' section but that didn't resolve low fps problem (even though that disabled an animation).

So it's like onStart or AnimationState component causes a situation where a KSP part is 'always animating' even though animation is stopped.

Ideally the plugin would trigger animation only when amount of resource is changing, otherwise not doing stuff that lowers fps.

Edited by riocrokite
Link to comment
Share on other sites

I'm thinking there's something messed up with the animation itself, I'm sure I've seen this kind of thing before..

Could you bundle all the assets up into a .unitypackage so I can take a look at how its rigged up? I think we'll find the culprit is hiding in there, and the animation modules are struggling to deal with it somehow.

Link to comment
Share on other sites

The plugin is very simple. The animation init method used is the same as used by kethane etc. I dont think it is the issue. I agree with lo-fi. The problem lies in the setup not the api. Unity can handle more complex animations without issues

Link to comment
Share on other sites

tried different type of animation (1 container = 11 objects not following bezier curve but moving linearly between 6 locations - used 6 key frames per each object). Results are 'weird':

Difference in editor:

new linear animation: 4 containers = 55 fps, 8 containers = 37 fps

old bcurve animation: 4 containers = 40 fps, 8 containers = 23 fps

Difference when launched:

new linear animation: 4 containers = 33 fps, 8 containers = 22 fps

old bcurve animation: 4 containers = 38 fps, 8 containers = 23 fps

so simple animation using just location keyframes (compared to following bezier curve path) behaves better in editor however worse when launched :/

edit: played a bit with Bahamuto's plugin;

changing WrapMode from ClampForever to Once causes certain bugs however has one desired effect: disables animation when container is full. In effect I have 60fps with 8 containers (and that drops to above numbers when containers are even slightly depleted).

I would be totally happy if I could disable animation with full and empty container since I would be using stack_priority_search when using resources so only one container would be animated at the same time rest being either full or empty thus not slowing down KSP.

Edited by riocrokite
Link to comment
Share on other sites

ok, code fiddling brought desired effects:

I can disable animation when container is either full or empty: change in code:

foreach (var cs in containerStates)

{

cs.normalizedTime = (float)normalizedRes;

cs.enabled=true;

if (normalizedRes >= 0.99f || normalizedRes <= 0.01f)

{

cs.enabled = false;

}

}

so full 60 fps if container is either empty or full.

Now I believe that further optimization to plugin is possible. For example enable animation only when resources in container have changed. Any hints how to do it?

------------------------------------------------

edit:

My problem is mostly resolved for now:

+ disabling animation when container is either empty or full (look above)

+ making sure that container resource and users of them have STACK_PRIORITY_SEARCH config - this ensures that only one container is animated at the time (rest being either full or empty thus not affecting performance)

- the only problem that remains is filling containers again (using another converter or drill) since it will always fill them equally thus activating all animations and slowing down the game

Edited by riocrokite
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...