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 Marcello1975 · Oct 27, 2014 at 05:17 PM · instantiateprefabclone

Cloned Object does not run Scripts

Good day for all.

Well, My point is: I have created a simple GameObject which has a Renderer with a Single Sprite. No Animations, no magics, not fancy... OK.

Secondly, i´ve created a C# Script. The most simple C# Scripts ever seen: I have a void update method which print("hello world"). OK, so now a dragged that GameObject to my Project, so it becomes a "Prefab", right?

In parallel, i´ve create an ObjectPool Script, so i can Instantiate 20 clones of my Prefabs in its start method. OK?

So, I attach this ObjectPool Script to an empty GameObject and associate my prefab as the type to be pooled.

Here i have the premisse: 1 empty GameObject which has a script to pool GameObjects which has my "Simple Prefab", which contains a Script which prints "hello world".

I play my "game", what i can see that all of the clones are created in hierarquy but none of them runs my print("Hello World") unless for the original prefab.

It seems that the Instantiate method is not cloning my whole prefab.

Does anyone have idea about the why my Clone´s Scripts are not running? In addition: does inactive objects are still able to run their scripts??

Att, Marcello

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by robertbu · Oct 27, 2014 at 05:19 PM

First, while the game is running, select one of the spawned object. Verify that the script you created is attached to the clone. If that is working, next go to the console window and make sure the 'collapse' button is not pressed. If 'collapse' is enabled, then all of your 'hello world' statements are being compressed into a single statement.

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
0

Answer by arcbd2005 · Mar 18, 2016 at 10:01 AM

I am listing 3 cases that can solve your issue. one of them should work for you.

1.)I was facing same issue like bullets were cloned in my game. then I gave the bullets prefab a tag and used script with the targets. It worked for me. on collison i used this if(other.gameObject.CompareTag ("bullet")){ code lines }

2.)otherwise you can use the script which is creating the prefabs clones to do something for you. becaues when you create the clone you can use the clone to do whatever you want. so you wont need a new script for clone because some times that causes issue.

3 .) if it is compulsory in your case to attach a script with clones then put a original prefab in the scene and attach script to it. once script is attached then disable it from inspector. and your script is also cloned with the prefabs.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Instantiate moving prefab 1 Answer

Instantiate Clones Itself - Rather than Prefab 0 Answers

i attach the prefab, but when i hit play, its not the prefab anymore 0 Answers

Cast Source Instantiating Error 1 Answer

Instantiate Not Working - Boo Script 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