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 MachCUBED · Aug 22, 2012 at 05:59 PM · updatestartawake

Start() not called upon instantation?

Hi guys,

I have a script attached to a poop object:

...

function Awake() {

Debug.Log("Poop created");

}

function Start () {

Debug.Log("Poop at x:" + transform.position.x + " y:" + transform.position.y + " z:" + transform.position.z);

...

}

function Update () {

Debug.Log("Poop update");

...

}

...

But when the object that has the above script attached is instantiated somewhere else...

function Poop() { poopChute.Play(); ... //Instatiate a poop pellet and drop it with an initial velocity of 1m/s opoosite to the magnitude of the pigeon var newPoop = Instantiate(poop, poopChute.transform.position, Quaternion.identity ); var poopScript : Poop = newPoop.GetComponent("Poop"); poopScript.velocity = rigidbody.velocity; }

...

The first script's Start() and Update() functions aren't being called at all, even though Awake() works ok. I can't test whether my poop's homing mechanism works until this problem gets fixed. What's going on?

MachCUBED

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 Mander · Aug 22, 2012 at 06:14 PM 0
Share

i just copy pasted ur 1st part and it works for me. u should copy all ur script o whatever u have

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kryptos · Aug 22, 2012 at 06:20 PM

When is function Poop() called? I can't see it in your script.

Anyway, I see two possible mistakes here:

  1. The Poop() method has the same name than the script. But it is forbidden with Unity to redefine constructor of Scripts. I don't know if this function is considered as a constructor in JS/US but in C# it will and thus not work.

  2. Make sure that the Poop() method is called, that the poop prefab does have a Poop script as component and that this script is not disabled by default (same with the GameObject), because disabled scripts do call Awake but not Start neither Update.


edit: other possibilities:

  1. Do you set Time.timeScale to zero somewhere?

  2. How are you sure that your function are not called? Maybe you forget to uncheck the "collapse" button on the console.

Comment
Add comment · Show 3 · 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 MachCUBED · Aug 22, 2012 at 07:39 PM 0
Share

I changed the name of my script to PoopBehavior from Poop, and the script attached to Poop (the GameObject) is enabled by default. it still isn't calling Start() and Update(). Bummer.

avatar image Bunny83 · Aug 22, 2012 at 09:31 PM 0
Share

I just guess you have disabled the component on the prefab? So the clone has the script also disabled.

avatar image MachCUBED · Aug 22, 2012 at 10:18 PM 0
Share

I've already said that the component is enabled by default on the prefab. And Time.timeScale is only set to 0 when the game is paused. It doesn't happen at all on PoopBehavior.

I tried adding this:


Time.timeScale = 1;

to Awake(). It made no difference, but I deter$$anonymous$$ed that the problem was being caused by OnCollisionEnter():


function OnCollisionEnter(collision : Collision) {
	
	// Not needed in the game environment after it hits something
	
	Destroy(this.gameObject);
}

The poop appears to be hitting the inside of a collider upon instantiation. So it's a positioning problem.

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

10 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Update and Awake not being called. 1 Answer

Start, Awake, Update. Any other ways to call functions from an empty GameObject? 3 Answers

FindGameObjectWithTag wont find in Start() or Awake() but will in Update() 1 Answer

C# void names 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