Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by sid4 · Dec 02, 2016 at 11:55 AM · spawning

My instantiations are spawning all kinds of sizes clones especially larger ones and i dont know why? 20x the size at least

My instantiations are spawning all kinds of sizes clones especially larger ones and i dont know why? 20x the size at least

I checked the prefab its small size

I did try the script on another object and it works fine with another object so why with this prefab I have does it clone all kinds of sizes clones and 20x larger ones at times?

please help

2d game

Comment
Add comment · Show 8
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 hexagonius · Dec 02, 2016 at 04:55 PM 0
Share

without knowing what your code is doing, there's no way one can help

avatar image sid4 hexagonius · Dec 02, 2016 at 05:42 PM 0
Share

I have s few scripts on them il l post 1 now

avatar image sid4 hexagonius · Dec 02, 2016 at 05:45 PM 0
Share
 using UnityEngine;
 using System.Collections.Generic;
 using Random = UnityEngine.Random;
 
 public class crashspawn : $$anonymous$$onoBehaviour {
     public GameObject SpawnItem;
 
     public bool ControllerActive = false;
 
     public List<GameObject> SpawnedObjects;
 
     public int SpawnAtOnce = 1;
 
     public int $$anonymous$$axSpawnedObjects = 2;
 
     public float SpawnEatch = 3;
 
 
     public bool OverSpawn = false;
 
     private float spawnTimeLeft;
 
 
     private Vector3 spawnPosoition
     {
         get
         {
             return new Vector3(
                 Random.Range(0f, 10f),
                 Random.Range(0f, 10f),
                 Random.Range(0f, 10f));
         }
 
     }
 
     void Start ()
     {
 
         SpawnedObjects = new List<GameObject>($$anonymous$$axSpawnedObjects);
 
         spawnTimeLeft = SpawnEatch;
     }
 
     void FixedUpdate()
     {
 
         for (var i = 0; i < this.SpawnedObjects.Count; i++)
         {
             if (SpawnedObjects[i] == null)
             {
                 this.SpawnedObjects.RemoveAt(i);
             }
         }         
         
         if (ControllerActive)
         {
 
             if (spawnTimeLeft <= 0)
             {
         
                 if (SpawnedObjects.Count < $$anonymous$$axSpawnedObjects)
                 {
                     
                     if (OverSpawn)
                     {
 
                         // Debug.Log("Over Spawning " + SpawnAtOnce + " Objects");
                         for (int i = 0; i < SpawnAtOnce; i++)
                         {
                     
                             var o = (GameObject)Instantiate(SpawnItem, spawnPosoition, Quaternion.identity);
 
                             o.transform.parent = this.transform;
 
                             SpawnedObjects.Add(o);
                         }
 
                     }
                     else
                     {
                         var itemsAllowedToSpawn = $$anonymous$$axSpawnedObjects - SpawnedObjects.Count ;
                         var itemsToSpawn = $$anonymous$$athf.Clamp(itemsAllowedToSpawn,0,SpawnAtOnce);
 
                         //Debug.Log("Spawning " + itemsToSpawn + " Objects");
 
                         for (int i = 0; i < itemsToSpawn; i++)
                         {
                             var o = (GameObject)Instantiate(SpawnItem, spawnPosoition, Quaternion.identity);
 
                             o.transform.parent = this.transform;
 
                             // Add Spawned Objects to List
                             SpawnedObjects.Add(o);
                         }
 
                     }
                 }
 
                 spawnTimeLeft = SpawnEatch;
                 // Debug.Log("DoneSpawning");
 
             }
             spawnTimeLeft -= Time.deltaTime;
     
         }
     }
 }
 
 
avatar image hexagonius sid4 · Dec 02, 2016 at 06:46 PM 0
Share

Is it possible you're instantiating UI elements or something? if so, you cannot use the parent = transform way of childing them but you need to use SetParent(transform, false) ins$$anonymous$$d

Show more comments
avatar image Link0n3 · Dec 02, 2016 at 07:40 PM 1
Share

@sid4 usually when you put an object as the child of another one it rescale according to the parent scale. So one think I would look is that your parent has Scale (1,1,1) and just to be sure on the child object you could try o.transform.localScale = new Vector3(1, 1, 1); after you parent it. Of course I am assu$$anonymous$$g that spawn objects have an initial scale of (1,1,1). If not just save the scale after you instantiate them and reassign as above.

avatar image sid4 Link0n3 · Dec 02, 2016 at 10:42 PM 0
Share

i just tried this it worked so far I must test more

can you explain to me why this happened? and more of what you mean I did not understand

avatar image Link0n3 sid4 · Dec 03, 2016 at 07:09 PM 1
Share

Hi @sid4 , every time you parent an object to another one you put it into his reference system. That is composed by it' s position, orientation and scale. Every time you parent one to the other there is an inner transformation matrix that, taking in consideration parent properties, get multiplied by the position, rotation and scale of the child object. Therefore intuitively if you have a child object with scale (1,1,1) and you parent to an object with scale (1,2,1), once parented the child object will have double of the size on the y axes with respect to its original size. If you want to know more, have a look at Chapter 7 of this book to have a better idea. This is the base maths that a game programmers need: $$anonymous$$ath 3d Primer

0 Replies

· Add your reply
  • Sort: 

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

80 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

Related Questions

NetworkServer.Spawn() make client crash to desktop when called in a loop 1 Answer

Check if there's no GameObject with specific tag in the field (in the camera view) 0 Answers

How to make Object X spawn when there're no more Objects tagged "XYZ" in scene? 1 Answer

spawn in specific areas only 0 Answers

How do I make the enemies continue spawning? 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