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 Bytebait · Jan 09, 2012 at 06:04 PM · instantiatechild object

Instantiate at Child Object

Parent is the 'Player' that holds the script that fires. I would like to instantiate the 'laserBeam' from an Empty Child Object (named LeftGunFire) directly in front of the gun barrel. I'm not sure where I'm going wrong. Below is the instantiating part I believe is in question.

 var LeftGunFire : GameObject; //Where I want it to instantiate from.
 var clone : Rigidbody;
 clone = Instantiate(projectile, LeftGunFire.transform.position, transform.rotation);
 clone.velocity = transform.TransformDirection (Vector3.forward * 1);
 
 
Comment
Add comment · Show 1
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 Jessy · Jan 09, 2012 at 08:49 PM 0
Share

Define "going wrong". Also, there's nothing called "Parent" in that. The parent-child relationship seems unrelated to the question you're asking, so you probably should edit the title.

2 Replies

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

Answer by Bytebait · Jan 10, 2012 at 04:29 PM

I've added 'child object' back to the tag as that is where I found an API hint to the solution.

For those who have the same issue as I did, here is how I solved instantiating to a child object from the parent.

var projectile : Rigidbody;

function Update () {

if (Input.GetButton ("Fire1")){

var clone : Rigidbody; aLeftFire = transform.Find("LeftGun/LeftGunFire");// LeftGunFire is an empty game object
//to always avoid collision issues with projectiles

clone = Instantiate(projectile, aLeftFire.position, aLeftFire.rotation); clone.velocity = aLeftFire.TransformDirection (Vector3.forward * 10); } }

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
-1

Answer by Bytebait · Jan 10, 2012 at 03:16 PM

Thank you for the heads up Jessy. "NullReferenceException: Object reference not set to an instance of an object" is the full error displayed.

I have a prefab with several objects inside it. The top hierarchy of the prefab (if my terminology is correct) is called the Parent. From the Parent, I'm trying to instantiate an object at the location of the child object.

This will instantiate the object from the Object that calls the script from itself.

var clone : Rigidbody; clone = Instantiate(projectile, transform.position, transform.rotation); clone.velocity = transform.TransformDirection (Vector3.forward * 1);

But how would I instantiate it at a Child Object within itself? Also, if my terminology is wrong, please correct me.

Prefab

-Player (Script Run Here)

  • -Left Wing

  • -Left Gun

    -LeftGunFire (Location I wish to 'shoot' projectile from)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

find/destroy camera in instantiated object 2 Answers

Instantiating a new gameObject as a child of a different gameObject 2 Answers

Issue with local and world positioning 1 Answer

Checking if object intersects? 1 Answer

Instantiate On Container Child 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