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 /
  • Help Room /
avatar image
0
Question by Redmarian · Jun 27, 2017 at 01:52 PM · c#instantiateorder-of-executionreading

Instantiate blocks the reading of remaining lines in method

Hello everyone ! Good day to you.

I'm currently struggling with a GameObject Instentiation from a prefab ; the precise line of code I use for this seems to mess up the behaviour of the void I place it in no matter what.

I use this line :

 myPannel = Instantiate (pannelPrefab, new Vector3 ((gameObject.transform.position.x+cr.transform.position.x)/2, gameObject.transform.position.y-5, (gameObject.transform.position.z+cr.transform.position.z)/2), Quaternion.identity);

"myPannel" is an empty public GameObject, pannelPrefab is a GameObject : I dragged and dropped my prefab in the Inspector.

When make the line appear in Awake, it disable the script. When I make it appear on Start or on a Method I use once in update, the method will stop reading and I'll go back to Update. I tried void and Coroutines, it doesn't seems to change much.

Here are the parts of code concerned :

 public MeshRenderer myMeshRenderer;
     public GameObject pannelPrefab;
     public GameObject myPannel;
     bool init = false;

 void Awake () {
         //cr = GameObject.Find ("Controller (right)");
         //VM = this.gameObject.GetComponent<ValueManager> ();
         myMeshRenderer = gameObject.GetComponent<MeshRenderer>();
         //myPannel = Instantiate (pannelPrefab, new Vector3 ((gameObject.transform.position.x+cr.transform.position.x)/2, gameObject.transform.position.y-5, (gameObject.transform.position.z+cr.transform.position.z)/2), Quaternion.identity);
     }

In here, cr and VM were supposed to be called but are never. I managed to work around, and myMeshRenderer is called correctly at this moment. If I don't comment myPannel, the script desactivates itself.

     void Start(){
         //myPannel = Instantiate (pannelPrefab, new Vector3 ((gameObject.transform.position.x+cr.transform.position.x)/2, gameObject.transform.position.y-5, (gameObject.transform.position.z+cr.transform.position.z)/2), Quaternion.identity);
 
         //cr = GameObject.Find ("Controller (right)");
         VM = gameObject.GetComponent<ValueManager> ();
         //IM = cr.GetComponent<InputManager> ();
 
         GameObject gpg = GameObject.Find("ValueG");
         GameObject gpf = GameObject.Find("ValueF");
 
         //myPannel = Instantiate (pannelPrefab, new Vector3 ((gameObject.transform.position.x+cr.transform.position.x)/2, gameObject.transform.position.y-5, (gameObject.transform.position.z+cr.transform.position.z)/2), Quaternion.identity);
         pg.GetComponentInParent<Transform>().tag = "G";
         pg.gameObject.tag = "G";
 
         pf.GetComponentInParent<Transform>().tag = "F";
         pg.gameObject.tag = "F";
 
     }

I tested it out on Start here in various place : Whatever was placed before is read, the line and the following is ignored.

 void Update(){
         if (!init) {
             Debug.Log("First Update");
             TheInit ();
         }
 }
 
 void TheInit(){
     Debug.Log("Init");
     myPannel = (GameObject)Instantiate (pannelPrefab, new Vector3 ((gameObject.transform.position.x+cr.transform.position.x)/2, gameObject.transform.position.y-5, (gameObject.transform.position.z+cr.transform.position.z)/2), Quaternion.identity);
     Debug.Log("Init2");
     myMeshRenderer.enabled = false;
     myPannel.SetActive (false);
     init = true;
 
 }

Here again, Debug.Log("First Update") and "Init" are proprely read, but never "Init2". If i Place init=true before my Instentiation, it reads normally, and TheInit() is never called again.

This is a project I've been working on for days and I managed to make it work before, messing up with the order of call. But trying different set ups in order to displace the Instence or make it spawn in different placed, I lost track and am a bit lost in the understanding of how the whole thing works.

Thanks to all, and have a nice day !

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

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

Instantiating GameObject loses some properties of the original GameObject 1 Answer

How does one continuously move an object forward without using velocity? 1 Answer

Adding different values to randomly created objects 0 Answers

When re-parenting instantiated object as child of current gameObject, why does GetComponents() not retrieve instantiated object's components? 1 Answer

scroll rect UI buttons all do the same thing 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