Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Issue ; Performance Issue 96ms performance hit

A topic by 78Star created Apr 09, 2023 Views: 370 Replies: 10
Viewing posts 1 to 11

wSetup:
I have 18k instances of SuperTextmeshes in scene.
Overview
So this is about half the number I will be going for. I just have them as static objects in scene, so I am assuming whatever is causing this I can work out. I tried looking through the SuperTextMesh.cs script,,, but it is long. I am not sure if this was done to keep file count down for the unity asset store, but is there a github, or other version I could get that has all the class separated?

Developer

Hello,


1) What are you programming that requires 36k instances of Super Text Mesh on screen at the same time? Knowing this might help me come up with a specific solution for your use-case.

2) Have you looked into object pooling as a solution to this?

3) Super Text Mesh was originally designed to just work as a single text box, then was optimized to function efficiently as UI elements, so for something like requiring 36k active instances at once, some manual optimization may be required... For instance, are all the meshes going to display the exact same text? If that's the case, you could write some code that causes the mesh generated by one Super Text Mesh object to be shared with a bunch of mesh filters & renderers, instead.


4) SuperTextMesh.cs's whole script is long, but it's all exposed and I tried to keep it as organized as I could. Only SuperTextMesh.cs needs access to all those methods inside of it, so it's all in the one script... maybe in the future I could divide it up, but it might end up having a reverse effect of making it harder for me to edit. (Unity doesn't like partial monobehaviour classes, so I would properly divide STM into multiple components...) I'd recommend expanding and closing parenthesis within a code editor should help with making things navigable. (Some code editors also have a "Structure" view that's very handy for this, too)

1) I am running low polly 3d modules through a method that spawns STMP assets on the edges of each tri, 2) so object pooling will be something I look into. 3) It will be groups of meshes yes(so like all plants are using one specific mesh, all rocks, all buildings, ect). 4) I have also ran into issues with Unitys dislike/lack of support of good coding practices. Though what I have been doing is using MonoBehavior's for purely the editor logic, or using them to wrap one to one class instances of my behaviors. Allowing for partials in the wrapped class, is a has a.

I am also trying to build out the exe as I see a good portion of the Update function has editor specific code(not sure this is the issue, but might alleviate it enough), but am running into other issues from another plugin so will get back with the results. Also my condolences if you have been waterfalling a 5k line file lol. Partials and Single Responsibility is the only thing keeping my sanity as a programmer intact, though often find others pushing projects through without consideration of future maintainers(from lack of budget or bad timelines of course, no fault to the programmers who make actual functioning code). 

I will also see if the Update method is anything I need since this will basically be static once spawned in, or might change in editor only.

Developer (1 edit)

I see... right, a few things to keep in mind are... Super Text Mesh will only update its mesh every frame if it uses an animated text effect, or has the "force animation" boolean checked.

But I think in your unique case, mesh instancing per gameobject type might be something worth looking into. So... for each type of object, you can have a single STM object generate a mesh as a type of generator, instance the mesh produced by STM, and that object type would then know to just use that mesh. If it's low poly assets, you can probably go a step further and bake the text mesh into the lowpoly model's mesh to save on object count, too. If this works, having a script that updates the one shared mesh for a lowpoly object should be pretty efficient if text needs to be updated (localization, different messages, etc) vs having 36k live STM objects that need to be updated. If you're using a font that's marked as dynamic though, baked meshes would have to be rebuilt when OnFontTextureRebuilt() gets invoked by STM, though. So I'd recommend starting with a font with import settings set to something non-dynamic.

In this instance, animated effects would be much better to handle using a custom shader if needed.


The Update method does have a lot of editor-only code. One thing to watch out for is that Unity's inspector itself is pretty inefficient. You can sometimes get an editor performance hit by having an inspector open for an object with a lot of fields. (The TextArea field is especially inefficient (and lacking in features!)... I've actually told Unity about this pretty recently, but there's really no way for me to work around it)

Super Text Mesh was originally made before I was familiar with many good coding practices, but sometimes I get thanked for leaving some out... (Lots of users seem to like that I don't use a namespace, for instance) But if I ever get the time to do a huge update, there would be a lot of backend stuff that gets cleaned up. For the time being though, I'm comfortable enough with it to edit and fix whatever needs to be done. In the end, all that matters is that it works as you need it to, and that our games get completed!

(1 edit)

I have a script pulling the meshes from each SuperTextMesh child component, but I am not sure how to move forward with getting the textures. They all are using the same char so could share a single material, I am assuming. Using the "SMT Unlit" shader, so would just getting the "_MainTex" variable and assigning it to a sharedMaterial work?

(1 edit)

The combined mesh is empty for some reason.
I am grabbing the meshes from.
combine[i].mesh = superTextMeshes[i].textMesh;
I am assuming there is somewhere else to grab the generated meshes from?


https://gdl.space/xezewihayi.cs

(1 edit)

Figured out how to get the mesh(f variable) and texture from materials(r variable). The position of the generated mesh is off, but not to big of an issue, but the main issue I face now is the texture being generated seems pretty low quality? Also the UVs I am assuming of the meshes aren't matching the generated texture, as the meshes are just transparent when using it.
https://gdl.space/ezewucaray.cs

Developer

Super Text Mesh uses submeshes to render, so it's possible the mesh data will be inside of that data block. 

https://docs.unity3d.com/ScriptReference/Mesh.GetSubMesh.html

This should be what you need to get a single mesh out of a mesh that uses submeshes. STM will make a new submesh every time the material changes.

Then, see what texture is on the corresponding mesh with STM's meshrenderer, and getting the material at the same index as the submesh. Hooopefully this works, and it was just the submeshes causing the issue.

(2 edits)

Yeah it was subMesh. And then the UV I fixed by getting a UV from each mesh and adding them to an array(which will match the new vertex array size). The only issue I face now is the position of the new mesh being off, though from the link bellow it seems to be something with how matrex4x4 works with different spaces(Will have to figure that out some other time for now I am brain dead). Thanks for the help @KaiClavier

https://answers.unity.com/questions/231249/instanced-meshes-are-being-offset-to-...

(1 edit)

I fixed the placement issue. I am just moving the objects back to world space default, and generating the mesh, and then moving it all back. Not pretty code, but functional.

https://gdl.space/ironakudic.cs