Why does global light in the BUILD ignore objects created via new GameObject()?

Hi, I just came across a problem that in the build light ignores objects created by new GameObject(). The strangest thing is that everything works right in the engine, but not in the build. All settings are exactly the same as that of a pre-created object in the scene. And everything works perfectly through the prefab, too. And I’m definitely not missing anything. Maybe a bug? That’s exactly what I’m doing:

var obj = new GameObject();
obj.AddComponent<SpriteRenderer>().sprite = objSprite;

Think I have the answer for you. It’s called baked lighting and if you bake it instead of having it dynamic then the light will never change, aswell as light data will never be added for new objects unless you add it into the bake data. Unity - Manual: Light Mode: Baked - @Ricollwy

It’s possible that the issue you’re encountering has to do with the object’s position in the scene. When you create a new GameObject, it doesn’t have a position in the scene by default. In the editor, you can see the object in the Hierarchy window because the editor automatically assigns a position to it, but in a build, the object will not be visible if it doesn’t have a position.
Home Bargains Portal

To fix this issue, you can try setting the position of the object after creating it. For example, you can use:

scss
Copy code
var obj = new GameObject();
obj.transform.position = Vector3.zero;
obj.AddComponent().sprite = objSprite;
This will set the position of the object to the origin (0, 0, 0), which should make it visible in the scene. If the object still doesn’t appear, you may want to check the camera settings and make sure the object is within the camera’s view frustum.

Just a thought, does your light use layers? Do your new gameobjects switch to the proper layer?