• 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 CCV334 · Nov 28, 2014 at 04:53 PM · animationtransform.positioncloneexplosion

transform.position assign attempt for 'Cubie' is not valid. Input position is { NaN, NaN, NaN }.

alt text

So here's some background information, I am trying to create this explosion effect of "cubie's". I have one object called enemy that when he collides with a bullet it destroys itself and instantiates another object called EnemyDeathAnimation which is not really an animation but a gameObject that replicates an explosion effect based on this tutorial: http://gamedevelopment.tutsplus.com/tutorials/how-to-make-an-object-shatter-into-smaller-fragments-in-unity--gamedev-11795

when I play the game and shoot the enemies occasionally I get the NaN error. I think it may be caused by the sphere used in the explosion effect instantiating and interfering with other objects. If anyone could shed some light on how to avoid/fix the error that would be great. If there is any better way of creating the explosion effect I would be more than happy to scratch this method and do it that way.

Enemy Script: using UnityEngine; using System.Collections;

 public class EnemyCubeScript : MonoBehaviour 
 {
     public GameObject deathAnimation;
 
     private float fadeTimer = 1.9f;
     private Transform player;
     private NavMeshAgent nav;
 
     void OnTriggerEnter (Collider col)
     {
         if(col.tag == "Bullet")
         {
             GameObject deathAnimationClone = Instantiate(deathAnimation, transform.position, transform.rotation) as GameObject; //instantiates deathAnimation gameObject
             Destroy (gameObject); //destroy self
             Destroy (deathAnimationClone, fadeTimer); 
             Destroy (col.gameObject); //destroy bullet
         }
     }
     void Awake () {
         player = GameObject.FindGameObjectWithTag ("Player").transform;
         nav = GetComponent <NavMeshAgent> ();
     }
     
     void Update () {
         nav.SetDestination (player.position);
     }
 }


nan error.png (253.5 kB)
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 CCV334 · Nov 28, 2014 at 05:03 PM 0
Share

I'm having a hard time understanding why the error occurs what appears to be at random. Also I'm confused as to why ending this game object and script would result in an error at all.

avatar image meat5000 ♦ · Nov 28, 2014 at 08:42 PM 0
Share

There are quite a few reasons for NaN. You need to look hard at the link (and other info) and try to find any places in your scripts in which those things may occur.

If in any script you ever divide anything by anything else, find out if that anything else could be 0 at some point. Good starting place. Search google for "Unity answers NaN".

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by meat5000 · Nov 28, 2014 at 04:47 PM

 if(col.tag == "Bullet")
 {
     GameObject deathAnimationClone = Instantiate(deathAnimation, transform.position, transform.rotation) as GameObject; //instantiates deathAnimation gameObject
     Destroy (gameObject); //destroy self

BANG! End of script... and gameobject.

http://en.wikipedia.org/wiki/NaN - Look under 'Operations generating NaN'. Divide by zero seems to be quite a common one.

It can also represent missing information, which is why I point out the gameobject destruction, as a case where info could be missing.

Also make sure the is information in all your variables. Its a safe practise to initialise them when you declare them.

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
avatar image
0

Answer by CCV334 · Nov 29, 2014 at 03:05 AM

11/29/14

It appears that if I remove the sphere causing the "cubies" to explode and changing its transform fixes the issue. It is not exactly the effect I was going for but will suffice for now.

==========================================================================================

12/11/14

I found that by by experimenting with the Unity particle system I was able to create the effect I was looking for and found this tutorial specifically useful: http://youtu.be/Tg4bgOR2HDM?t=17m49s

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Explosive ANimation 1 Answer

Can I make animations snap to a frame? 1 Answer

how to play a clone's (prefab) animation? 1 Answer

my explosion animation is stuck on last frame rather then getting destroyed after finishing 1 Answer

Camera follow player while it doesnt block animations 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