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 hyman · Dec 28, 2013 at 04:19 PM · androidnullreferenceexceptionunity4.3

itween example work well on unity3d while NullReferenceException on android

I add some code on the example : 1) add public GameObject to do animation 2) Assigned innerGlow to this GameObject by drag it from the panel. 3) Add some Itween effect for this GameObject

The GameObject do the move effect what i want when i click the play button on unity3d.

then i build it for android and run it . But the GameObject miss the moving effect. and we can see the log say that the GameObject is null.

--- Android log from adb log cat ------- I/Unity (20229): NullReferenceException: Object reference not set to an instance of an object I/Unity (20229): at Controller.Start () [0x0004b] in /Users/apple/Dropbox/unity3d/itween/pathcontrolledcharacter/PathControlledCharacter/Assets/Scripts/Controller.cs:32

--------- All codes as below ----

using UnityEngine; using System.Collections;

public class Controller : MonoBehaviour { public Transform[] controlPath; public Transform character; public enum Direction {Forward,Reverse}; public GameObject turnRight; // add for test

 private float pathPosition=0;
 private RaycastHit hit;
 private float speed = .2f;
 private float rayLength = 5;
 private Direction characterDirection;
 private Vector3 floorPosition;    
 private float lookAheadAmount = .01f;
 private float ySpeed=0;
 private float gravity=.5f;
 private float jumpForce=.12f;
 private uint jumpState=0; //0=grounded 1=jumping

 private bool isShow = false; // add for test
 void OnDrawGizmos(){
     iTween.DrawPath(controlPath,Color.blue);    
 }    
 
 
 void Start(){
     //plop the character pieces in the "Ignore Raycast" layer so we don't have false raycast data:    
     foreach (Transform child in character) {
         child.gameObject.layer=2;
     }
     turnRight.transform.position = new Vector3 (-0.4f, 0.7f, 0f);// add for test
 }
 
 
 void Update(){
     if (!isShow){// add for test
         Debug.Log ("MoveFrom. 9end.");
         isShow = true;
         Hashtable args = new Hashtable();
         args.Add("x",0.5);
         //    args.Add("speed",10f);
         
         args.Add("time",.6f);
         args.Add("delay", 2.2f);
         args.Add("oncomplete", "AnimationEnd");
         args.Add("oncompleteTarget", gameObject);
         //移动的过程中面朝一个点
         iTween.MoveTo(turnRight,args);
         
         //iTween.MoveFrom (turnRight, iTween.Hash ("x",-.6,"time",.6,"delay",0.2,"oncomplete","SwitchToTitleScreen"));
         
         
         
         
     }
     DetectKeys();
     FindFloorAndRotation();
     MoveCharacter();
     MoveCamera();
 }
 void AnimationEnd(){// add for test
     Debug.Log ("AnimationEnd. end.");
     iTween.MoveTo (turnRight, iTween.Hash ("x",-.8,"time",.6,"delay",1.2,"oncomplete","setFlag","oncompleteTarget", gameObject));
     
 }
 void setFlag(){// add for test
     isShow = false;
     Debug.Log ("setFlag. end.");
 }
 
 void DetectKeys(){
     //forward path movement:
     //if(Input.GetKeyDown("right")){
         characterDirection=Direction.Forward;    
     //}
     //if(Input.GetKey("right")) {
         pathPosition += Time.deltaTime * speed;
     //}
     
     //reverse path movement:
     if(Input.GetKeyDown("left")){
         characterDirection=Direction.Reverse;
     }
     if(Input.GetKey("left")) {
         //handle path loop around since we can't interpolate a path percentage that's negative(well duh):
         float temp = pathPosition - (Time.deltaTime * speed);
         if(temp<0){
             pathPosition=1;    
         }else{
             pathPosition -= (Time.deltaTime * speed);
         }
     }    
     
     //jump:
     if (Input.GetKeyDown("space") && jumpState==0) {
         ySpeed-=jumpForce;
         jumpState=1;
     }
 }
 
 
 void FindFloorAndRotation(){
     float pathPercent = pathPosition%1;
     Vector3 coordinateOnPath = iTween.PointOnPath(controlPath,pathPercent);
     Vector3 lookTarget;
     
     //calculate look data if we aren't going to be looking beyond the extents of the path:
     if(pathPercent-lookAheadAmount>=0 && pathPercent+lookAheadAmount <=1){
         
         //leading or trailing point so we can have something to look at:
         if(characterDirection==Direction.Forward){
             lookTarget = iTween.PointOnPath(controlPath,pathPercent+lookAheadAmount);
         }else{
             lookTarget = iTween.PointOnPath(controlPath,pathPercent-lookAheadAmount);
         }
         
         //look:
         character.LookAt(lookTarget);
         
         //nullify all rotations but y since we just want to look where we are going:
         float yRot = character.eulerAngles.y;
         character.eulerAngles=new Vector3(0,yRot,0);
     }

     if (Physics.Raycast(coordinateOnPath,-Vector3.up,out hit, rayLength)){
         Debug.DrawRay(coordinateOnPath, -Vector3.up * hit.distance);
         floorPosition=hit.point;
     }
 }
 
 
 void MoveCharacter(){
     //add gravity:
     ySpeed += gravity * Time.deltaTime;
     
     //apply gravity:
     character.position=new Vector3(floorPosition.x,character.position.y-ySpeed,floorPosition.z);
     
     //floor checking:
     if(character.position.y<floorPosition.y){
         ySpeed=0;
         jumpState=0;
         character.position=new Vector3(floorPosition.x,floorPosition.y,floorPosition.z);
     }        
 }
 
 
 void MoveCamera(){
     iTween.MoveUpdate(Camera.main.gameObject,new Vector3(character.position.x,2.7f,character.position.z-5f),.9f);    
 }

}

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

18 People are following this question.

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

Related Questions

Problem with animation and void fixedupdate() 1 Answer

Unexplainable NullReferenceException 2 Answers

Unity 4.3 Android, Entire Screen Not Displayed on Device 0 Answers

NullReference in Start() or Awake() when testing on Android device, works fine in Editor 2 Answers

Cant fix a null reference exception? 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