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 alfredtai · Aug 21, 2015 at 08:35 AM · transformpositionstart

Object cannnot be transformed in start()

I'm a newbie of using the unity. I wonder why how I can't transform the instantiated object in start(). However, if I transform the object in Update(), it works immediately. Could somebody tell me what is the reason behind? Thanks T.T

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Gameplay : MonoBehaviour {
     public GameObject pausePanel;
     public GameObject loadingPanel;
     public GameObject[] monsters;
 
     private int row = 6;
     private int col = 1;
 
     private static float horizontalSpacingOffset = -3.0f;
     private static float verticalSpacingOffset = 3.0f;
     private static float borderSpacing = 0.0f;
 
     List<GameObject> monstersList;
     bool start;
 
     // Use this for initialization
     void Start () {
         monstersList = new List<GameObject>();
         pausePanel.SetActive(false);
         for (int y = 0; y < col; y++) 
         {
             for (int x = 0; x < row; x++) 
             {
                 Vector3 location = GridToWorldPoint(y, x);
                 GameObject monster = (GameObject)Instantiate (monsters [5], location , transform.rotation);
                 monstersList.Add(monster);
             }
             monstersList[3].transform.position = new Vector3(0, 1, 0);
         }
         start = true;
     }
     
     // Update is called once per frame
     void Update () {
     }
 
     #region GetInitialLocation
     //finding the grid location
     private static Vector3 GridToWorldPoint(int x, int y) 
     {
         return new Vector3(x + horizontalSpacingOffset + borderSpacing * x, 
                            -y + verticalSpacingOffset - borderSpacing * y, 0);
     }
     #endregion










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 Positive7 · Aug 21, 2015 at 10:17 AM 0
Share

Do you have any errors? Cause it works just fine here

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by christuart · Aug 21, 2015 at 11:36 AM

Often if you have some code which appears to function when in an Update but not when run straight after instatiation, it is because your change is being unmade by some other code before you can see it.

Check that your 'monsters[5]' GameObject doesn't have a script attached with a Start() method altering its transform.position. When you instatiate an object, all Awake() methods in attached scripts are run immediately, but the Start() methods don't get called until just before the first Update(), so after the Gameplay.Start() code you have posted would have already run.

If you can't identify any code in a Start() method that might be changing the transform.position from the Vector3(0, 1, 0) you have specified in Gameplay.Start(), you could use

 Debug.Log(<a reference to the transform.position you want to have changed>);

in various locations, including Awake() and Start() methods in the 'monsters[5]' GameObject to try to find when it is changing. Remember that the running order will be:

  1. Any Awake() methods in the monster GameObject

  2. Your attempt to change the transform of one of those monsters

  3. Any Start() methods in the monster GameObject

  4. Any Update() methods in the Gameplay GameObject and the monster GameObject, in an unknown order.

Are you absolutely certain that the code doesn't work as you've posted it? Depending on your scale, it may be difficult to see the effects directly in the scene or game views. Are you certain you're checking the correct instance of monsters[5]? Are you aware that you are only changing the position of one of the 6 instances? (Just checking!) And finally, have you realised that if you included more than one column then your code to try moving that one instance would be called multiple times, as it is inside the columns for loop?

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

How to Return Enemy to startPosition 1 Answer

Return Enemy To Start Position 1 Answer

Remember the start coordinates? 2 Answers

can't use camera position in equasion, help! 2 Answers

transform position vectorially 2 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