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 EndBoss · Sep 18, 2010 at 01:56 AM · instantiatenullreferenceexception

pass transform value to another script

This is related to my previous question which I solved another way, but now I started on a new script and trying out a suggestion in my previous question, so now I'm stuck again...

my error

'NullReferenceException: Object reference not set to an instance of an object spawnPickup+SpawnAnother$1+$.MoveNext () (at Assets\scripts\spawnPickup.js:13)'

PickUpManager - empty game object spawnPickup.js

var myPickup : GameObject;

function SpawnAnother(currentTransform: Transform){

 yield WaitForSeconds (1);
 Instantiate(myPickup, currentTransform.position, currentTransform.rotation);

}

pickup > cube

pickup is an empty game object with a rotate JS on it, and cube is the child, which has a collider , is trigger set

var collectSFX : AudioClip; static var originTransform : Transform;

function OnTriggerEnter (otherCollider : Collider) {

 if(otherCollider.gameObject.tag == "player"){

     audio.PlayClipAtPoint(collectSFX, gameObject.transform.position);
     var score = gameObject.Find("scoreDisplayer").GetComponent(displayScore).AddScore();    
     var puManager = gameObject.Find("PickUpManager").GetComponent(spawnPickup); 
     puManager.SpawnAnother(originTransform);
     Destroy(gameObject);


 }   

}

/* static function StoreOrigin(otherTransform : Transform){

 originTransform = otherTransform;
 Debug.Log(originTransform.transform.position.z);

} */

function start(){

originTransform = gameObject.transform; Debug.Log(originTransform.transform.position.z);

}

So basically I'm trying to store off the original location of the pickup. When it's destroyed I want to instantiate another one at it's orginal location.

I can then go into the level and drop these all over the place.

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

1 Reply

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

Answer by _Petroz · Sep 18, 2010 at 02:04 AM

Looks like the problem is that your 'originTransform' variable is storing a reference rather than a copy of the object's transform.

Try creating a copy of the original transform, I don't do javascript but I looked online and I think it should be something like:

originTransform = gameObject.transform.clone();
Comment
Add comment · Show 1 · 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 EndBoss · Sep 18, 2010 at 04:22 PM 0
Share

Hey thanks. I couldn't find anything on clone. Isn't clone just instantiating? I think you gave me an idea though. I never knew about the reference thing. I think to keep it simple I will simply assign the position xyz values into ints and pass those to the spawner.

I will look into arrays as well. thanks

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

No one has followed this question yet.

Related Questions

Simultaneous Null Reference Exception and expected value 1 Answer

Variable Assigning with GameObject.Find("") causing NullReferenceException? 0 Answers

Accessing a prefab after instantiating results as null 1 Answer

Networking-multplayer issue 1 Answer

Naming an instantiated gameobject gives nullreferenceexception. 0 Answers


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