Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Pavoht · Feb 03 at 11:37 AM · optimizationuser interface

UI Optimization - Hundreds of floating damage text

Hey all, I struggle with an issue that I don't know how to fix. I'm new to Unity (many years on UE) so I don't know how and where optimize this kind of things atm.

I work on a project with hundreds of actors spawned in the world (that's why I switch to Unity, UE can't handle at all many pawns in the world and UMG is very very poorly optimized for hundred widgets displayed). I've made a Floating Damage Text script, work like a charm, but when I hit like 300 actors with multiple hits, fps drop to 40 with huge freeze.

I've made a Prefab that include a Canvas and a Text as a child, where I put my damage text that I need to display.

Then, with a SphereCollider, I do an overlap and detect all "enemy" in the radius, then I get the component and do the TakeDamage then the DisplayFloatingText. All works fine, but when I need to display hundreds of floating damage text, fps drop really down, like 40 fps, with huge freeze.

Is there any way to optimize the text render, or the settings of UI in world, or the prefab of the Floating text, or any other way to display floating damage in a more optimized way ? Like, render it in 2D on the player screen, not in 3D in the world ? Any suggestion or help is welcome !


My DamageIndicator script :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class DamageIndicator : MonoBehaviour
 {
 
     public Text text;
     public float lifetime = 0.6f;
     public float minDist = 2f;
     public float maxDist = 3f;
 
     private Vector3 iniPos;
     private Vector3 targetPos;
     private float timer;
 
     // Start is called before the first frame update
     void Start()
     {
         transform.LookAt(2 * transform.position - Camera.main.transform.position);
 
         float direction = Random.rotation.eulerAngles.z;
         iniPos = transform.position;
         float dist = Random.Range(minDist, maxDist);
         targetPos = iniPos + (Quaternion.Euler(0, 0, direction) * new Vector3(dist, dist, 0f));
         transform.localScale = Vector3.zero;
     }
 
     // Update is called once per frame
     void Update()
     {
         timer += Time.deltaTime;
 
         float fraction = lifetime / 4f;
 
         if (timer > lifetime) Destroy(gameObject);
         else if (timer > fraction) text.color = Color.Lerp(text.color, Color.clear, (timer - fraction) / (lifetime - fraction));
 
         transform.localPosition = Vector3.Lerp(iniPos, targetPos, Mathf.Sin(timer / lifetime));
         transform.localScale = Vector3.Lerp(Vector3.zero, Vector3.one, Mathf.Sin(timer / lifetime));
     }
 
     public void SetDamageText(int damage)
     {
         damage = 10;
         text.text = damage.ToString();
     }
 }



My Enemyhealth script :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class EnemyHealth : MonoBehaviour
 {
 
     public GameObject damageText;
     public int maxHealth = 100;
 
     private int curHealth;
 
     // Start is called before the first frame update
     void Start()
     {
         curHealth = maxHealth;
     }
 
     public void TakeDamage(int damage)
     {
         curHealth -= damage;
         DamageIndicator indicator = Instantiate(damageText, transform.position, transform.rotation).GetComponent<DamageIndicator>();
         indicator.SetDamageText(damage);
         if (curHealth < 1) Destroy(gameObject);
     }
 }



My spell function :

     public void SpellAoE()
     {
         Collider[] colliders = Physics.OverlapSphere(transform.position, 2f);
         foreach(Collider Enemy in colliders)
         {
             EnemyHealth enemy = Enemy.GetComponent<EnemyHealth>();
 
             if (enemy != null)
             {
                 enemy.TakeDamage(Random.Range(1, 15));
                 Debug.Log("Hitted");
             }
         }
     }
 
 }



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 MilitaryG · Feb 03 at 12:41 PM 0
Share

Some code would be great.

avatar image Pavoht MilitaryG · Feb 03 at 02:12 PM 0
Share

You're right, added !

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

185 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 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 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

Android Optimization 0 Answers

Circular Bar Transparent gradient 0 Answers

How do I get animations to play immediately? 0 Answers

How to draw Camera Canvas on top of Overlay Canvas? 0 Answers

How to add a tiled background panel to UIElement tree (Editor)? 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