Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ben Blaut · Aug 23, 2012 at 08:21 PM · animationmeshes

Can't access animation after combining meshes.

I'm using a script attached to the parent of an .fbx model to add a script to each child that tells me when they've been clicked. It also combines all the meshes of the children and makes a mesh filter and renderer at the top of the hierarchy, which lets me change the shader on the object when any part of it is clicked. I want to be able to step through the animation using a slider, and I have that working as well. The problem is that they don't work together. I'm not sure why I can't access `animation["Take 001"].time` if I combine the meshes.

Here's the code:

 #pragma downcast
 #pragma strict
 
 @script RequireComponent(MeshFilter)
 @script RequireComponent(MeshRenderer)

 var HighlightColor : Color = Color.red;
 var startSliderValue : float = 0.0;
 var endSliderValue : float = 1.0; 
 var followStart = true;
 var followEnd = false;
 var selected = false;
 private var shaderNormal : Shader; 
 private var shaderHighlighted : Shader;

 function Start() {
   animation["Take 001"].weight = 1; 
   animation["Take 001"].enabled = true;    
   animation["Take 001"].speed = 0; 
   animation["Take 001"].wrapMode = WrapMode.PingPong;
 
   for (var child : Transform in transform) {
     child.position += transform.position;
     addRecursively(child, "ChildClicked");
   }
   transform.position = Vector3.zero;
   transform.rotation = Quaternion.identity;    
   var meshFilters = GetComponentsInChildren.<MeshFilter>();
   var combine : CombineInstance[] = new CombineInstance[meshFilters.Length-1];
   var index = 0;
   for (var i = 0; i < meshFilters.Length; i++) {
     if (meshFilters[i].sharedMesh == null) continue;
       combine[index].mesh = meshFilters[i].sharedMesh;
       combine[index++].transform = meshFilters[i].transform.localToWorldMatrix;
       meshFilters[i].renderer.enabled = false;
   }
   GetComponent(MeshFilter).mesh = new Mesh();
   GetComponent(MeshFilter).mesh.CombineMeshes(combine);
   renderer.material = meshFilters[1].renderer.sharedMaterial;
 }
 
 function addRecursively(parent : Transform, script : String) {
   for (var child : Transform in parent) {
     addRecursively(child, script);
   }
   var scriptExists : Component = parent.GetComponent(script);
   if (!scriptExists) {
     parent.gameObject.AddComponent(script);
   }
 }
 
 function Update() { 
   if (followStart == true) {  
     animation["Take 001"].time = startSliderValue;
     followEnd = false;
   }  
   else {
     followEnd = true;
   }
   if (followEnd == false) { 
     followStart = true; 
   }
   else {
     animation["Take 001"].time = endSliderValue;  
     followStart = false;
   }
 }
 
 function Clicked() { 
   selected = !selected;
   if(renderer.material.shader == shaderNormal) { 
     renderer.material.shader = shaderHighlighted; 
     renderer.material.SetColor("_OutlineColor", HighlightColor);
   }
   else { 
     renderer.material.shader = shaderNormal;
   } 
 }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image WilliamLeu · Aug 23, 2012 at 10:11 PM 0
Share

$$anonymous$$y Theory: Because the script doesn't convert the animations for the newly created model. It just concatenates the models and throws away animation data.

Easiest way to test this is to check out the newly created model while the game is running and see if it has an Animation behavior in the inspector, and see if it has anything in its Animations variable. $$anonymous$$y guess is that the behavior won't be there, or that the size of Animations will be 0.

Converting the animation across an entire hierarchy, to match with meshes across an entire hierarchy sounds like a very intensive process, and I would be surprised if it did.

avatar image Ben Blaut · Aug 24, 2012 at 03:56 PM 0
Share

That makes sense that that's what might be going on, but the animation behavior is still on the object at the top of the hierarchy. It just doesn't seem to be doing anything. $$anonymous$$aybe it's something along those lines, where the animation is there, but isn't matched with any of the objects anymore?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Ben Blaut · Sep 13, 2012 at 06:12 PM

I modified the MeshMerger script to work with what I have, and it solved this problem. So WilliamLeu's advice was pretty much correct - you have to match the meshes with all the relevant information for animations across the entire hierarchy.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Update iTween Path at Runtime 1 Answer

Animation within Unity 1 Answer

Animation by Scripting point A to B 1 Answer

Perform Action on frame/time of animation 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges