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. :slight_smile: – also, I apologize if my intentions aren’t very clear, don’t hesitate to ask for clarification! :slight_smile:

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.