• 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 clonetrooper2021 · Jun 07, 2021 at 05:15 PM · instantiate prefab

Instantiated prefabs acting different than those dragged onto scene

I have some prefabs that, when instantiated, act differently than ones that I just place into the scene manually (which perform exactly as intended). Some people have said that it might have something to do with the code that instantiated the objects, so I've included some pictures of that. Just in case it helps, my game is in 2D.

Thanks in advance :)

First pic: alt text

Second Pic: alt text

instantiate-code-pic-1.png (56.3 kB)
instantiate-code-pic-2.png (53.2 kB)
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 tormentoarmagedoom · Jun 23 at 06:51 AM 0
Share

Hello!

Post the code as text, not an image.... If not we can no copy and paste to explain things to you..

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by spkmark · Jun 23 at 01:14 AM

If u instantiate multiple of the same thing and there all using the same script then one command will happen to all of them unless you put 'this.' Before each line. I.e. this.astroidtype = random.range(0, 4);

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 tormentoarmagedoom · Jun 23 at 06:59 AM

Hello @clonetrooper2021

Your posted code is not related with the acting of the asteroids. This code only Instantiate them, only spawns them in the scene.

The code that makes the asteroids do things, i supose is placed inside the asteroids itself.

One thing you can do when instantiating is to give "orders" or assign variables to the just new instantiated object.

You are doing this:

 Instatiate (Object, pos, rotation);

But, if you do this (imagine the asteroids prefab have a script component called "MovingAsteroid.cs") :

 GameObject NewAsteroid;
 NewAsteroid = Instantiate (AsteroidPrefab, position, rotation);
 NewAsteroid.GetComponent<MovingAsteroid>().SomeVariable = 4;
 NewAsteroid.GetComponent<MovingAsteroid>().SomeFunction();

So, I access the just instantiated object the same frame is instantiated, and only that object. Its like the "Start" funcion but executed from outside.

So, if you are having problems with you asteroids, try to force this way the thigs they do when spawned

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

119 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

Related Questions

How to replace prefab at the same location? 1 Answer

Instantiated Object does not fall 3 Answers

Instantiate Prefab Gameobject vs Transform 2 Answers

Object not Instantiating Correctly 1 Answer

Missing Prefab DontDestroyOnload.,Can´t instantiate dontDestroyOnLoad prefab in other scenes. 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