Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 brenolimaa96 · Apr 20, 2016 at 04:31 PM · 2dgameobjectinstantiatetransformtime

Instantiate clones with error.

When i'm instantiating some clouds to my game, the clones dont get the game object, being "none" it appears a lot of errors in my console but the game doesnt stop.

look the picture alt text

I should do something in my scripts to those clones get the game Object, called "Nuvem", like in the Hierarchy you can see.

i'll post my scripts here.

First the cloud script

 public class nuvemController : MonoBehaviour {
 
     public float velocidade;
     public Transform transformNuvem;
     public GameObject objectNuvem;
 
     void Start () {
 
     }
     
     // Update is called once per frame
     void Update () {
         transformNuvem.Translate(velocidade * Time.deltaTime* -1, 0, 0);
         if (objectNuvem.transform.localPosition.x < -13){
             Destroy(objectNuvem);
         }
     }
 }

now the instantiator script

 public class Instanciador : MonoBehaviour {
 
     public GameObject prefab;
     public float rateSpawn;
     public float currentTime;
 
 
     // Use this for initialization
     void Start () {
     }
     
     // Update is called once per frame
     void Update () {
         InstanciarNuvem();
     }
 
     void InstanciarNuvem()
     {
         currentTime += Time.deltaTime;
         if (currentTime >= rateSpawn)
         {
             currentTime = 0;
             Instantiate(prefab, transform.position, transform.rotation);
         }
 
     }
 
 
 }
 

I think that i should put something in the Start() to initializate those clones with the cloud object. how should i correct this error?

problem.png (47.3 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 KidRigger · Apr 20, 2016 at 04:53 PM 0
Share

How are you assigning the Transform and GameObject to the nuvemController script?

avatar image brenolimaa96 KidRigger · Apr 20, 2016 at 05:05 PM 0
Share

$$anonymous$$y prefab "Nuvem" is receiving the gameObject and the Transform from the NuvemController, but when the prefab creates its clones, they dont have the gameObject, causing the error.

alt text

sorry for my bad explaining, i'm not still good at English '-'

problem2.png (52.4 kB)

1 Reply

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

Answer by KidRigger · Apr 20, 2016 at 05:12 PM

As you want the objects own Transform and GameObject, get the components in Start function, using GetComponent() function.

edit: I think you should not keep the prefab in the hierarchy. Once it gets destroyed the Instanciador script will not be able to reference. Rather just keep nuvem in the Prefabs folder and let the Instanciador spawn its clones only.

Comment
Add comment · Show 2 · 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 brenolimaa96 · Apr 20, 2016 at 05:37 PM 0
Share

Heey Really THAN$$anonymous$$S ! That was the problem, my prefab could not be in scene. Now it's working perfectly. I just took off the prefab from the scene and drag the own prefab to the GameObject field.

avatar image KidRigger brenolimaa96 · Apr 20, 2016 at 05:47 PM 0
Share

That problem bugged me a lot. :) It basically uses the instance, so when it is destroyed, you lose the reference. The Prefab reference that you now have will stay till the end. Nice to help you. ($$anonymous$$y first answer XD)

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

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

Related Questions

Instantiate - Prefab as Child 1 Answer

XBox Controller Angle of Fire Incorrect 0 Answers

Instantiate rigidbody, transform or gameobject? 1 Answer

Instantiate Game Object on Array of Transforms 1 Answer

instantiate gameobject with different size? 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