Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 /
avatar image
3
Question by Legolax · Feb 21, 2020 at 12:33 PM · scripting problemscript.renderdotsmesh renderer

ECS RenderMesh not visible

Hello,

I've made a simple script for ECS and Hybrid Renderer, everything works fine except RenderMesh which do not render at all.

 public class GameManager : MonoBehaviour
 {
     public Mesh newMesh;
     public Material newMaterial;
     void Start()
     {
         EntityManager manager = World.DefaultGameObjectInjectionWorld.EntityManager;
         EntityArchetype archetype = manager.CreateArchetype(typeof(LocalToWorld), typeof(RenderMesh), typeof(Translation));
         Entity entity = manager.CreateEntity(archetype);
         manager.SetSharedComponentData<RenderMesh>(entity, new RenderMesh
         {
             mesh = newMesh,
             material = newMaterial,
             subMesh = 0,
             layer = 0,
             castShadows = ShadowCastingMode.On,
             receiveShadows = true
         });
     }
 }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
9

Answer by Zyche · Mar 23, 2020 at 07:14 PM

Hey mate,

If you are trying this one on newer versions of unity (2019.3.x), you NEED to add typeof(RenderBounds) to your archetype. Without this IT WILL NOT DISPLAY.

Best regards

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 yacth_Mon · Mar 31, 2020 at 04:26 AM 0
Share

I had tried this and it works!

avatar image Egemean · Mar 16, 2021 at 10:16 AM 0
Share

Thanks! It's worked for me :)

avatar image Kudrman · Apr 07, 2021 at 08:48 PM 0
Share

good! works for me!

avatar image CynicWild · Dec 30, 2021 at 07:29 PM 0
Share

Also worked for me!

avatar image
1

Answer by andrew-lukasik · Jan 02 at 07:58 PM

Most common issues:


  • Missing components

If you open up an Entity Debugger ( Systems since entities v 0.50 ) window it will list all component types that systems look for (aka "entity query"). If an Entity doesn't match that list (query) - entity is simply ignored. And this is exactly what happens here.

Note: some specific components are added automatically by systems when criteria is met. For example: adding Translation or/and Rotation to an entity will result in LocalToWorld being added as well. Adding RenderBounds and LocalToWorld will result in WorldRenderBounds being added.

alt text


  • RenderBounds with zero size. You can identify this case in cases where mesh is visible ONLY while it's world position (mesh origin) is visible to the camera and whole disappears immediately when it goes off screen.


  • WorldRenderBounds with not encapsulating the mesh properly. This is caused by RenderBounds being offset or not sized properly i.e. it's not zero but it's not correct either. It's harder to investigate this case because meshes can be totally invisible or appear/hide for no apparent reason when camera moves. I strongly suggest you install this package, as it allows you to select entities and see their WorldRenderBounds in the Scene window: https://github.com/JonasDeM/EntitySelection


  • Render Pipeline-specific components are missing because URP and HDRP require different data sets to work properly. This often results in meshes being black or not affected by lights. Fix: use RenderMeshUtility (see code sample below).


    TL;DR:

Here is a preferable workflow to create mesh entities. It adds all required components and initializes their values properly.

 using UnityEngine;
 using UnityEngine.Rendering;
 using Unity.Entities;
 using Unity.Rendering;
 using Unity.Transforms;
 using Unity.Mathematics;
 using Random = UnityEngine.Random;
 public class LetsCreateARenderMeshEntity : MonoBehaviour
 {
     [SerializeField] Mesh _mesh = null;
     [SerializeField] Material _material = null;
     void Start ()
     {
         var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
 
         Entity prefab = entityManager.CreateEntity( typeof(Prefab) );// prefab is invisible & inactive
         RenderMeshUtility.AddComponents( prefab , entityManager , new RenderMeshDescription(
             mesh:_mesh , material:_material , shadowCastingMode:ShadowCastingMode.On , receiveShadows:true
         ) );
 
         for( int i=0 ; i<1000 ; i++ )
         {
             float3 position =  Random.insideUnitSphere * new float3( 100f , 100f , 100f );
             quaternion rotation = quaternion.Euler( 0f , 0f , 0f );
             float3 scale = Vector3.one;
             Entity instance = entityManager.Instantiate( prefab );
             entityManager.SetComponentData( instance , new LocalToWorld{
                 Value = float4x4.TRS( position , rotation , scale )
             } );
         }
     }
 }



screenshot-2022-01-02-195051.jpg (45.6 kB)
Comment
Add comment · Show 1 · 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 Rouddem · May 03 at 06:15 PM 1
Share

RenderMeshUtility works like a charm <3 Indeed, it's adding some other components like "Builtin Material Property Unity | Rendering Layer", etc. Thank you !

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

314 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 can I make that the waiting time in StartCoroutine will take effect when changing the value in inspector when the game is running ? 1 Answer

Need a bit of help implementing something into a code 1 Answer

Door Script compiler error 0 Answers

What this part of code does ? 1 Answer

How can i rotate the camera with the mouse around the player ? 1 Answer


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