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 AnipGames · Feb 05, 2021 at 02:22 PM · graphicsoptimizationscritpinginstancingdrawmesh

Will this script that does drawmeshinstancedprocedural actually work?

I was trying to make script that, at runtime, finds any children gameobjects with mesh filter and mesh renderers and it then draws them using Graphics.DrawMeshInstancedProcedural. Will this actually work? It seems like such an easy solution to a common problem so I expect it not to work. The reason I haven't tested it is because I don't want to spend many, many hours implementing into my final project (because I will only see if this benefits performance when scaled to the size for my game) for it then not to work. That is why I'm asking here to see if somebody out there knows if this will work so I can know if it would work before committing a lot of time to implementing this into the project. Any insight would be greatly appreciated! Here is the code:

 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
 
 public class InstanceObjects : MonoBehaviour
 {
     public Transform hexGrid;
 
     public List<ObjectData> Objects = new List<ObjectData>();
     //public List<GameObject> Children = new List<GameObject>();
     bool canGo = false;
 
     public void Start()
     {
         canGo = false;
         //Children.Clear();
         foreach (Transform child in hexGrid)
         {
             //Children.Add(child.gameObject);
             ObjectData n = new ObjectData();
             n.pos = child.position;
             n.rot = child.rotation;
             n.scale = child.localScale;
             n.rend = child.GetComponent<MeshRenderer>();
             n.filter = child.GetComponent<MeshFilter>();
             Objects.Add(n);
         }
         canGo = true;
     }
 
     private void Update()
     {
         if (canGo)
             BatchAndRender();
     }
 
     private void BatchAndRender()
     {
         foreach(ObjectData obj in Objects)
         {
             for (int i = 0; i < obj.filter.sharedMesh.subMeshCount; i++)
             {
                 Graphics.DrawMeshInstancedProcedural(obj.filter.sharedMesh, i, obj.rend.materials[i],obj.rend.bounds,1);
 
             }
         }
     }
 }
 
 public class ObjectData
 {
     public Vector3 pos;
     public Quaternion rot;
     public Vector3 scale;
     public MeshRenderer rend;
     public MeshFilter filter;
     /*
     public Matrix4x4 renderData
     {
         get
         {
             return Matrix4x4.TRS(pos, rot, scale);
         }
     }
     */
 }
 
Comment
Add comment · Show 3
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 logicandchaos · Feb 07, 2021 at 03:46 PM 1
Share

just run and see!

avatar image AnipGames logicandchaos · Feb 08, 2021 at 01:30 PM 1
Share

Ok, I ran it and all it did was drop my fps to like 3fps. I'm assu$$anonymous$$g its got to do with iterating through thousands of trees or something...

avatar image AnipGames AnipGames · Feb 08, 2021 at 07:37 PM 0
Share

Ok I fixed it! I just wasnt actually enabling the canGo boolean because it was being forced false from another script

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

116 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

Related Questions

How to move from Graphics.DrawMeshInstanced to Graphics.RenderMeshInstanced 1 Answer

Multiple scenes or one scene? 3 Answers

Not getting shadows for dynamic objects 0 Answers

Strange FPS drop 1 Answer

"Big" 3ds model gives performance issues 3 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