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 chase.willits · Jan 24, 2014 at 12:00 AM · javascriptinstantiateprefablagmain thread

Unity Frame Drop From Instantiating Prefab that has script

I have a prefab that I instantiate 10 seconds after loading the level. The Script is a generic mover script which as you can see will not run as default. Then I have a separate scrip to instantiate the object which works correctly and assign targetA and targetB which normally would be done in inspector but the two targets are also instantiated objects that are made before my prefab with mover script. When I run this the script runs and everything but for some reason the main thread spike to 516-520milisecond response time dropping FPS in game from 120ish to 1.5ish. Can anyone explain/help me with this? Link below for video to show this....

//code 1

pragma strict

 var targetA : GameObject;
 
 var targetB : GameObject;
 
 var setter : boolean = false;
 
 var speed : float = 0.1;
 
  
 
 function FixedUpdate ()
 
 {
 
 if(setter) {
 
 var weight = Mathf.Cos(Time.time * speed * 2 * Mathf.PI) * 0.5 + 0.5; transform.position = targetA.transform.position * weight + targetB.transform.position * (1-weight);
 
 }
 
 }

//code 2 myobject = Instantiate(moverprefab, Vector3(1025.872, 41.44104, 2492.541),Quaternion.Euler(0,29.22,0-16.8));

         var theScript = myobject.GetComponent(lvl4padmover);
 
         theScript.targetA = top.gameObject;
 
         theScript.targetB = bottom.gameObject;
 
         theScript.setter = true;

link text

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 Lockstep · Jan 24, 2014 at 12:25 AM 1
Share

Why did you put your logic inside of FixedUpdate? FixedUpdate is usually used for physics only but you don't do anything physics related in there. Have you tried using the regular Update function?

avatar image chase.willits · Jan 24, 2014 at 01:17 AM 0
Share

Ah the fixed update when i was planning to have gravity added in for some falling pads, then I changed my $$anonymous$$d and made it move but never changed update function...

When i changed the update function my Frame Rate now runs around 20 using your Update function help, is there anything i can do to improve this, other levels where i use the same script[going through and flipping them to Update() thank you:) ] runs around 100.? Please and thank you.

avatar image thinkyhead_ · Jan 24, 2014 at 01:25 AM 0
Share

Do you see any messages in the Console window as you're running this? Your code looks reasonably efficient, but maybe it would be more efficient in C# ins$$anonymous$$d of Javascript, with all your constants as explicit floats?

avatar image chase.willits · Jan 24, 2014 at 01:38 AM 0
Share

I have no messages in the console window when this is running, its confusing me because if I do the same thing in the level before runtime it works without issue. Only when I Instantiate the prefab do I have these issues. It is all centered on the Box Collider I believe when I disable that no issues occur, but as soon as i enable it again I drop down to 20FPS

avatar image chase.willits · Jan 24, 2014 at 01:40 AM 0
Share

Haven't tried this with C# since I know very little C# in combination with unity. But can one language really cause such a huge issue. And which constant would you be referring to for floats?

Show more comments

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

20 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

Related Questions

Need help understanding scripted prefab behavior - when I click one, the script runs on ALL prefab instances, not just the one I clicked. 3 Answers

Problems instantiating a prefab (javascript) 1 Answer

A way to instantiate an item with 90 Degree increments? 2 Answers

[Urgent]Changing variables of an object AFTER instantiation 2 Answers

Instantiate prefab within parameters?(Javascript) 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