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 kyly1992 · Jun 16, 2014 at 07:44 PM · backgroundscrollscrollingparallax

Parallax scrolling background performance problem

So i have a parallaxing background in a 2d game im making. The problem is when i port it to my android phone and run it, it runs fine for the first 20 seconds or so, after that it starts to run laggy/sluggish, seems like a framerate issue but im not to sure because all other elements in the game runs perfect however> Appreciate any help. Here is the code i use for the parallax background.

 using UnityEngine;
 using System.Collections;
 
 public class Backgrounds : MonoBehaviour {
     public float speed = 0;
 
 
     // Use this for initialization
     void Start () {
 
     
     }
     
     // Update is called once per frame
     void Update () {
         renderer.material.mainTextureOffset = new Vector2 (Time.time * speed, 0f);
     
     }
 }
 
Comment
Add comment · Show 2
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 kyly1992 · Jun 16, 2014 at 07:38 PM 0
Share

Another things is to the more times i replay the scene (on phone) with the parallax background the laggier and choppier it gets.

avatar image TiagoMachado · Oct 08, 2014 at 07:45 PM 0
Share

you fix it?

i have the same problem

4 Replies

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

Answer by kyly1992 · Jun 19, 2014 at 04:15 PM

So i figured it out had to take out Time.time from the code. Apparently that was taking up to much resources

Comment
Add comment · Show 3 · 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 thomasindustry · Jun 19, 2014 at 04:32 PM 1
Share

Taking a second look at things, you probably want Time.deltaTime ins$$anonymous$$d of Time.time anyway

avatar image Salazar · Sep 16, 2014 at 07:21 PM 0
Share

I have the same problem, this solution didnt work for me.

avatar image Salazar · Sep 27, 2014 at 10:37 AM 0
Share

I write a solution of my experience here.

avatar image
2

Answer by TiagoMachado · Oct 09, 2014 at 12:01 PM

use this...

using UnityEngine; using System.Collections;

public class MoveOffSet : MonoBehaviour {

 private Material currentMaterial;
 public float scrollSpeed;
 private float offset;

 void Start(){
     
     currentMaterial = renderer.material;
     
 }
 
 
 void FixedUpdate() {
     offset += scrollSpeed * Time.deltaTime;
     offset = offset % 1.0f;
     currentMaterial.mainTextureOffset = new Vector2(offset,0); 

 


 }
 
 
 

}

Comment
Add comment · Show 2 · 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 Salazar · Oct 11, 2014 at 05:01 PM 0
Share

Anyone tried it?

avatar image tomicz · Jan 18, 2016 at 07:10 AM 0
Share

I tried this, it worked, thanks a lot !

avatar image
0

Answer by thomasindustry · Jun 16, 2014 at 09:31 PM

Try saving the material in a variable at the start instead of accessing it each frame. It may increase performance.

 using UnityEngine;
 using System.Collections;
 
 public class Backgrounds : MonoBehaviour
 {
     public float speed = 0;
 
     Material theMaterial;
 
     // Use this for initialization
     void Start()
     {
         theMaterial = renderer.material;
 
     }
 
     // Update is called once per frame
     void Update()
     {
         theMaterial.mainTextureOffset = new Vector2(Time.time * speed, 0f);
 
     }
 }
Comment
Add comment · Show 4 · 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 kyly1992 · Jun 16, 2014 at 09:57 PM 0
Share

ok i played the game for countless turns and the lag is still there

avatar image kyly1992 · Jun 16, 2014 at 10:08 PM 0
Share

runs very fine in the beginning but when i die and click retry a number of times the parallax background lags a lot, very noticeable

avatar image kyly1992 · Jun 17, 2014 at 12:29 AM 0
Share

Any ideas anyone???

avatar image Salazar · Sep 14, 2014 at 08:46 PM 0
Share

I have the same problem, this solution didnt work for me.

avatar image
0

Answer by Akrog · Oct 21, 2014 at 11:43 AM

  theMaterial.mainTextureOffset = new Vector2((Time.time * speed)%1, 0f);
 

Enjoy!

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Moving Background with translated images 1 Answer

Problem with changing the direction of an Infinite scrolling background. 1 Answer

2D Parallax Background 4 Answers

trouble with getting the background to show past the midground in 2d parallax backgrounds 0 Answers

How to create an infinite scrolling background in top down multi-directional shooters. 2 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