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 Geta-Ve · Mar 23, 2014 at 04:29 AM · movementinstantiateprefaborganization

Instantiate moving prefab

So, I am not even quite sure of how to inquire about this, however, I have a simple test game built where squares will "swarm" a player object.

My initial thoughts (which I am still using) was to build a prefab with a movement script attached, and then build a spawner object that will spawn the moving prefab clone.

As might be obvious this poses a problem because I can only build a prefab with objects already present within the game, meaning that my prefab is already moving when I start the game.

Obviously this functionality is unwanted. So I have paused to ask how I SHOULD be approaching this situation.

My goal is to spawn squares at a determinable rate and speed. I know I COULD do this in one script, but I was thinking it would have been cleaner and more organized to have the movement and spawning functionality separate from each other.

One solution I was thinking of was to only 'move' the prefab IF it is in or out of a certain area -- ie, IF prefab is in game area, move as intended, otherwise don't. This would allow be to set up any number of different styled moving objects.

But again I am unsure of what the right course of action would be. Or, at the very least, the most advisable course.

Thank you sincerely for any help. :) -- also, I apologize if my intentions aren't very clear, don't hesitate to ask for clarification! :)

Comment
Add comment · Show 7
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 robertbu · Mar 23, 2014 at 04:31 AM 0
Share

because I can only build a prefab with objects already present within the game, meaning that my prefab is already moving when I start the game.

A true prefab doesn't exist in the game until it is Instantiated:

https://docs.unity3d.com/Documentation/$$anonymous$$anual/Prefabs.html

avatar image Geta-Ve · Mar 23, 2014 at 08:47 AM 0
Share

Hmm, if I am not mistaken, that only reiterates what I stated. To create a prefab, it has to exist within the game / hierarchy first.

I should mention that the prefab I was attempting to make was sprite based, so, not sure if that matters.

avatar image xSmurfKasketter · Mar 23, 2014 at 08:54 AM 0
Share

actually a prefab does not exist in any way other that being in your project window. it should only be in your hierarchy if you need it to be in your game at launch. try deleting your prefab (make sure it really is a prefab by making sure it's name and icon is blue) and then try instantiating it by using Instantiate(yourPrefabName, position, rotation);

avatar image Geta-Ve · Mar 23, 2014 at 09:00 AM 0
Share

Is / did.

If I create an empty prefab, I can't add anything that isn't within the hierarchy -- fair enough. But the only way I can add a sprite to the hierarchy also adds it to the game window, which, for all intents and purposes, is the game itself. Thus, adding movement functionality (as in, go here, do that) to an object already in the game window, means, when I hit play, it will start moving.

So, while, yes, the prefab itself doesn't exist yet, within the context of the game, the object its based off of does, so if I were to, lets say, have a function that destroys said object if it hits the player, it will of course destroy the prefab also, no?

avatar image Geta-Ve · Mar 23, 2014 at 10:05 AM 0
Share

however the object in the hierarchy you can just delete if you don't want it to be in the game from the start.

Ohhh. I apologize. I had no clue I could delete the original after making the prefab.

Thank you VERY much. :) I really appreciate you taking the time to explain that to me, also, I apologize for being a bit dense. :P

Too bad I can't mark your comment as the answer... :(

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by xSmurfKasketter · Mar 23, 2014 at 10:01 AM

i'm don't think that you are totally aware of what a prefab is or how you create it. Let's say that you have an object called enemy that you want to make a prefab. you drag it out into the hierarchy and attach scripts and whatever components you want on it. you then drag it back down into your projects window and that makes it a prefab. however the object in the hierarchy you can just delete if you don't want it to be in the game from the start. And afterwards just use the Instantiate() function to create your prefab again. I'm not sure what you mean will it destroy your prefab. if you instantiate a prefab twice and destroys one of them, the other one won't be affected and you can instantiate one again. They are independent of one another.

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

21 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

Related Questions

Clone of prefabs copy original´s script state during runtime? 0 Answers

Cloned Object does not run Scripts 2 Answers

Instantiate only one Prefab per 40 unit 2 Answers

Problem with GetComponentinChildren and Instantiate 0 Answers

how to control spawned prefab of player ANDROID 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