Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Animation Event Particles from Bone

Discussion in 'Animation' started by pluMmet, Jul 25, 2016.

  1. pluMmet

    pluMmet

    Joined:
    Jul 18, 2015
    Posts:
    133
    I'm happy to have figured it out this far but now I am stuck.

    Here is my working code:
    I have the particles attached to the animated models bone object where the particles need to emit from and this event script on the model itself.

    I have to have it attacked that bone so it can follow it during the animation.

    If I move the script to the proper bone I can't access it in the animation Event.

    I am getting an error:

    MissingComponentException: There is no 'ParticleSystem' attached to the "Dragon" game object, but a script is trying to access it.
    You probably need to add a ParticleSystem to the game object "Dragon". Or your script needs to check if the component is attached before using it.


    How do I get the script to see the nested particle system attached to the jaw bone object?
     
    Last edited: Jul 25, 2016
  2. pluMmet

    pluMmet

    Joined:
    Jul 18, 2015
    Posts:
    133
    As it turns out I can't even get it to play the event with the particle system directly nested to the gameobject.. same error.

    I'm not sure what is going on?
     
  3. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    You could try simply this.GetComponentInChildren<ParticleSystem>(), that will find that particle system within the hierarchy of the gameobject
     
  4. pluMmet

    pluMmet

    Joined:
    Jul 18, 2015
    Posts:
    133
    Thank you for the reply...

    I found out that there is/was some sort of problem attacking particle systems to Bones rigs so I ended up finding this example that worked well:

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var castSpot            : Transform;
    4. var castPrefab            : GameObject;
    5.  
    6. function CastMagic(){
    7.     var newSpell        =Instantiate(castPrefab, castSpot.position, castSpot.rotation);
    8.     Destroy(newSpell, 5.0);
    9. }
     
  5. pluMmet

    pluMmet

    Joined:
    Jul 18, 2015
    Posts:
    133
    Also to mention that I made an empty object a child of the Bone and attached the particle prefab to that..

    It is working great!