Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[SOLVED] Whats wrong with my Script?

Discussion in 'Scripting' started by EternalMe, Mar 16, 2020.

  1. EternalMe

    EternalMe

    Joined:
    Sep 12, 2014
    Posts:
    183
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using Unity.Entities;
    4. using Unity.Mathematics;
    5. using Unity.Transforms;
    6.  
    7. namespace ShiftBall
    8. {
    9.     public class Startup : MonoBehaviour
    10.     {
    11.         [SerializeField] private GameObject playerPrefab;
    12.  
    13.         private Entity playerEntity;
    14.         private World defaultWorld;
    15.         private EntityManager entityManager;
    16.  
    17.         void Start()
    18.         {
    19.             defaultWorld = World.DefaultGameObjectInjectionWorld;
    20.             entityManager = defaultWorld.EntityManager;
    21.  
    22.             var settings = GameObjectConversionSettings.FromWorld(defaultWorld, new BlobAssetStore());
    23.             playerEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(playerPrefab, settings);
    24.  
    25.             InstantiateEntity(new float3(0f, 0f, 0f));
    26.         }
    27.  
    28.         private void InstantiateEntity(float3 position)
    29.         {
    30.             var entity = entityManager.Instantiate(playerEntity);
    31.             entityManager.SetComponentData(entity, new Translation
    32.             {
    33.                 Value = position
    34.             });
    35.  
    36.         }
    37.  
    38.         // Update is called once per frame
    39.         void Update()
    40.         {
    41.  
    42.         }
    43.     }
    44.  
    45. }
    I can see the Entity in debugger, but is not showing up on screen :/
     
  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    So to help you out,
    we need some more information ..

    your calling functions from your different classes but we cant see them,
    if you want to instantiate any object in world space:

    Code (CSharp):
    1. public GameObject playerPrefab;
    2. public GameObject spawnPoint;
    3.      
    4. var newEntity = Instantiate(playerPrefab, spawnPosition.transform.position, spawnRotation.transform.rotation);
     
  3. EternalMe

    EternalMe

    Joined:
    Sep 12, 2014
    Posts:
    183
    Solved. I had not added Hybrid renderer.