I’m using static flag now as it seems better since unity 5 than combine them with a script. Problem is i use a couple of functions that need to acces vertices, triangles etc from those meshes (for drawing a mesh for a decal) and Unity tells me I can’t…
I can’t set them to non static and back to static on the fly since it would need the editor.
I understand that the engine need to protect data from being written but the reading? I don’t get why it would be also protected… Maybe i’m doig something wrong. What’s are your thoughts on this?
Btw my meshes have the write/read check so it’s not that, it works only if i remove the static flag. I can’t afford that or i have to return in the old way… Combining myself.
Rather than typing 4 letters into a post, why not make the assumption that your question isn’t easy to understand, and spend a bit more time explaining it. I, for example, have used Unity for 6 years and don’t understand what you are talking about, and can’t see any code to help explain things.
Sorry about that, i thought it was clear enough but i often forget that my english is pretty bad,.
I need to instantiate a decal on the fly and to doing so i need access to the vertices, triangles etc data of the mesh its colliding with so the mesh could actually have the same shape of the colliding object. I had that working great before but i wasn’t using the static flag. instead i was combining myself with CombineChildrenAdvanced. Before UNITY 5 it was better to do so than letting unity doing the job (or at least that’s what i thought) because draw calls were very important for a mobile app. Now it seems that draw calls aren’t the bottleneck anymore so i tried to set static flag instead and i gained a solid 10 fps. But the function i need to make my decal can’t run anymore since the static flag protect the read access (that i can’t understand why) and UNITY send me a bug that i can’t access to those data, and if I remove the static flag it works again.
I can post you part of the code (which is not mine)but i’m not sure it would be revelant here.
public static void BuildDecalForObject(Decal decal, GameObject affectedObject) {
Mesh affectedMesh = affectedObject.GetComponent<MeshFilter>().sharedMesh;
if(affectedMesh == null) return;
float maxAngle = decal.maxAngle;
Plane right = new Plane( Vector3.right, Vector3.right/2f );
Plane left = new Plane( -Vector3.right, -Vector3.right/2f );
Plane top = new Plane( Vector3.up, Vector3.up/2f );
Plane bottom = new Plane( -Vector3.up, -Vector3.up/2f );
Plane front = new Plane( Vector3.forward, Vector3.forward/2f );
Plane back = new Plane( -Vector3.forward, -Vector3.forward/2f );
Debug.Log(affectedObject);
Vector3[] vertices = affectedMesh.vertices;
/.. the code goes on but the error comes at this line
The exact message error is : Not allowed to access vertices on Mesh ‘Combined mesh (root: scene)’
I did some searching around and this was leading me to the static hint, which is indeed the guilty one here.
What i want to know is:
-is there another way to proceed to fit my need? How do you guys do?
-and why is the static flag preventing me to read in the first place?
Oh and for more precision about what i’m trying to do… I have a turret that shot a rocket, if it hit a walls or something i want to have a decal who fit the collided shape to be instantiated.
Please also tell me if i’m clear enough now or if I have to try harder explaining it.
I don’t know enough about your decisions. GameObjects marked as static in the editor get consumed into batches. Telling the editor that a game object is not going to move at all allows the runtime to combine a lot of these game objects together, so makes rendering faster. I don’t know enough about your game objects. Potentially if they were small, I’d duplicate them, not mark them as static, and use some runtime code to grab the verts from them when the level starts. I’d then make sure that the runtime knows that they don’t need rendering. (Alternatively, you could write some editor script that mines out the verts, and stores them Resources as text files.)
I’ve never done this.
Because the GO is being converted into a batch along with other static GOs. Marking them as static means “render these babies as fast as possible.” To make them fast, they don’t look like Meshes that a GO has.
So, i think having a non-rendered dupe of the wall makes sense, which is what I was saying above.
Seems like I understood your problem, but no-one else in the community does. Or they see you as someone who’s happy to use bump, and decide to leave you to it.
Hahaha! Yeah maybe. Thanks a lot for your concern and your nice input. It looks like the txt solution would be better for the overall performances but i don’t have any clue of how I could manage this with my few knowledge, so I decided to give the dupe walls a try. Again thank you!