#Instantiated entities won't render.

1 messages · Page 1 of 1 (latest)

thorn sluice
#

why might this be happening? I'm trying to instantiate an entity, the gameobject prefab is an empty transform with a renderer as a child. Here are my scripts:

[BurstCompile, UpdateInGroup(typeof(InitializationSystemGroup))] public partial struct SpawnEnemySystem : ISystem
{
    [BurstCompile] public void OnUpdate(ref SystemState state)
    {
        state.Enabled = false;
        Entity gameEntity = SystemAPI.GetSingletonEntity<GameProperties>();
        GameAspect game = SystemAPI.GetAspect<GameAspect>(gameEntity);

        //switch to better command buffer
        var ecb = new EntityCommandBuffer(Allocator.Temp);

        for (var i = 0; i < game.NumberOfEnemiesToSpawn; i++)
        {
            var newEnemy = ecb.Instantiate(game.EnemyPrefab);
            ecb.SetComponent(newEnemy, 
                 new LocalTransform { Position = game.GetRandomOffset(0.5f, 1)});
        }

        ecb.Playback(state.EntityManager);
    }
}






public struct GameProperties : IComponentData
{
    public Entity Enemy;
    public int Amount;
}






public struct GameRandom : IComponentData
{
    public Random Value;
}






public class GamePropertiesAuthoring : MonoBehaviour
{
    public GameObject Enemy;
    public int Amount;
    public uint RandomSeed;
}

public class GamePropertiesBaker : Baker<GamePropertiesAuthoring> 
{
    public override void Bake(GamePropertiesAuthoring authoring)
    {
        Entity entity = GetEntity(TransformUsageFlags.Dynamic);
        AddComponent(entity, new GameProperties 
        {
            Enemy = GetEntity(authoring.Enemy, TransformUsageFlags.Dynamic),
            Amount = authoring.Amount,
        });

        AddComponent(entity, new GameRandom 
        {
            Value = Unity.Mathematics.Random.CreateFromIndex(authoring.RandomSeed),
        });
    }
}




public readonly partial struct GameAspect : IAspect
{  
    private readonly RefRO<GameProperties> _properties;
    private readonly RefRW<GameRandom> _random;
    private readonly RefRW<LocalTransform> _transform;

    public int NumberOfEnemiesToSpawn => _properties.ValueRO.Amount;
    public Entity EnemyPrefab => _properties.ValueRO.Enemy;

    public float3 GetRandomOffset(float magnitude, float height)
    {
        float2 randomPosition2D = _random.ValueRW.
                                   Value.NextFloat2(magnitude * -1, magnitude);        
        return new float3(randomPosition2D.x, height, randomPosition2D.y);
    }
}```
thorn sluice
#

bump

lusty citrus
#

we know nothing about what you're trying to instantiate

#

are you looking at game or scene view

thorn sluice
#

both don't do anything

#

like I said its just an empty game object with a sphere mesh renderer as a child

#

showing up in entity heirarchy but not in the normal heirarchy

lusty citrus
#

It shouldn't appear in normal hierarchy, it's an entity

#

Normal hierarchy only shows game objects

thorn sluice
#

why is it not rendering either?

#

I tried having a mesh renderer on the main instantiated object but to no avail

lusty citrus
#

That I can't really tell you without looking at data

#

You do have entities graphics installed right

thorn sluice
lusty citrus
thorn sluice
#

I do...

lusty citrus
#

Have you tried to just put an entity in a subscene

#

does it bake/render properly?

thorn sluice
#

It is in a subscene

#

Wait

#

Do i need to create thr prefab while is is in the subscene?

lusty citrus
#

i mean skip the whole spawner stuff

#

just put the prefab directly in the subscene

#

or even just a sphere

#

can you see any converted entity?

thorn sluice
#

If I create an ordinary sphere, it gets converted to an entity

twin sail
#

It is always a good idea to try to simplify your project as much as possible.
If you use this ordinary sphere as your EnemyPrefab, do you see it being rendered?

thorn sluice
#

I'll give it a go, I think it has something to do with the prefab being made in the main heirarchy and not in the subscene

twin sail
thorn sluice
#

again this, at this point I should just start an empty project to see if I messed something up in the beggining

#

it aint rendering either, I just treid updating my package as well

#

yup, screw this im restarting the project

thorn sluice
#

I've set up a new project and the exact same thing is happening again, the spheres aint rendering or showing up in the normal hierarchy.

lusty citrus
#

a) are you sure SpawnEnemySystem is actually running

thorn sluice
#

yes

lusty citrus
#

because at the very least, i don't think your code will work if you close your subscene

#

if you close your subscene, does it error entering play mode?

#

if you no requireforupdate on GameProperties

#

as subscenes load async your system will tick at least once without GameProperties existing

thorn sluice
lusty citrus
#

debug.log

#

is the equiv

#

you can log from burst

#

you just have to use formatter

#

i.e. can't do
int x
debug.log(x)

#

have to do
debug.log($"{x}");

thorn sluice
#

unity crashed

#

whoopse

#

certainly is being called

#

Ill try creating entities without command buffer

lusty citrus
#

it's not error with closed subscene?

#

i don't see how this would work with closed subscene/in a build

thorn sluice
#

no, in fact, the spawning still works

lusty citrus
#

sorry i'm kind of side tracking as this has nothing to do with your actual issue but i'm pretty sure you will have issues in future with builds

thorn sluice
#

fully unloading the scene still spawns the entities in

#

its not the ecb, entities still not showing. Im sure im missing something here

lusty citrus
#

i dont know if it's fixed in 1.0.16

#

but in 1.0.14 spawning from prefabs didn't show up properly in hierarchy

#

but you should still be able to see it in world

lusty citrus
#

have you tried updating?

thorn sluice
#

in that case I need to know why entities arent rendering

#

Ill update now

#

oh nvm I am on .16

#

Instantiated entities won't render.

lusty citrus
#

what's your authoring of both the spawner + the prefab look like?

thorn sluice
#

script? or in inspector? (sorry im getting used to ecs slang or whatnot)

lusty citrus
#

inspector

#

i think you've shown the script above already

thorn sluice
lusty citrus
#

whats your error?

thorn sluice
#

entities glitch

lusty citrus
#

still not fixed in 1.16? 😅

#

(i have a local work around so haven't seen it in months)

thorn sluice
#

;-;

lusty citrus
thorn sluice
#

yes sir

#

prefab was also created from sphere originating in subscene

lusty citrus
#

and it's not rendering?

#

can you see it in game view

#

not scene view

thorn sluice
#

yup, its just instantiated stuff I cant see

lusty citrus
#

preferences -> entities -> scene view mode -> change it to runtime data

thorn sluice
#

doesnt change much

lusty citrus
#

this screenshot seems to imply they have been instantiated right?

thorn sluice
#

yes

lusty citrus
#

the targets

#

can you click on one, whats the entity data?

#

AH bugger

#

ok

#

new LocalTransform { Position = game.GetRandomOffset(0.5f, 1)});

#

i shoul dhave seen this a long time ago

#

you're seting scale = 0

#

and an invalid rotation

#

scale = 0 is you can't se eit

thorn sluice
#

they aren't set by default? damn

lusty citrus
#

LocalTransform.FromPosition(game.GetRandomOffset(0.5f, 1));

#

will give you defaults

#

it's a struct there are no defaults if you use initialization

thorn sluice
#

I've spent an entire week doing nothing just because I forgor how structs work

#

Thank you so.... so much.

lusty citrus
#

I should have spotted it earlier tbh

#

Generally good at catching this

#

But so many other common cases of stuff not rendering

thorn sluice
#

Its all gud, u actually figured it out unlike me...

#

also how do you check entity data cause clicking in entity heirarchy doesnt do anything

undone silo
thorn sluice
#

Nothing at all