Objects disappears when I exit Play-mode

Hello all,

I have uploaded a short video to describe my problem. Please see the vid below.

I want to edit the texture of the cubes among other things - but as I exit Play-mode they all disappear.
I can edit the cubes in the “Scene” in Play-mode, but it’s not possible to save in Play-mode, and as I exit Play-mode, the cubes are reset to their original texture.

I want all the objects to be visible so that I can edit them without entering Play-mode.

Heelp… :o

Still trying to figure this out. I’m only few weeks into Unity

Why can’t you edit them in edit mode?

Hi, because they’re not visible in the Hierarchy in edit-mode, only visible in play-mode

Yeah, it seems like you’re generating them somehow. How are you doing that? By instantiating prefabs? Or by generating them completely from code?

I am not sure how. Here’s the project I am trying to edit: https://github.com/Rinirihiriro/UnityValley
Would you kindly take a quick look into it and see if you figure how the objects are generated?

Nope.

I can help you with specific problems, but this is asking too much. While I’m usually in favor of jumping into the deep end of the pool, you seem to have bit off a bit more than what you can swallow.

In particular, you should be able to figure out what scripts are in the scene, see what they do in their Awake/Start methods, and follow that trail to see what’s causing stuff to spawn. That’s pretty fundamental.

I’d suggest looking into a few more of the step-by-step tutorials in the learn section.

I understand.

As I read from the code, the objects are generated this way:

void Start () {
stage = GameObject.Find (“MapMaker”).GetComponent ();

From the MapMaker script I can follow a trail to the different map-scripts.

My question would then be: how can I edit the material for the Mesh Renderer for these generated objects?

If the generated objects are generated by instantiating prefabs, you’ll have to change the material on the prefab.

If the generated objects are generated by creating objects directly from code - often through GameObject.CreatePrimitive, you’ll have to get the mesh renderer, and set it’s material to the material you want.

You can get the material you want either by putting it in a public field on something somewhere, or by loading it from the Resources folder through Resources.Load

Thanks! Seems like it’s the second option from what you mention:

GameObject makeSlope () {
GameObject obj = GameObject.CreatePrimitive (PrimitiveType.Cube);
obj.name = “Slope”;
Mesh mesh = obj.GetComponent().mesh;
mesh.Clear ();
mesh.vertices = slopeVertices;
mesh.triangles = slopeTriangles;
mesh.RecalculateNormals ();

I created the Resources folder in the assets folder, added the texture png, and edited the code into:

GameObject makeSlope () {
GameObject obj = GameObject.CreatePrimitive (PrimitiveType.Cube);
obj.name = “Slope”;
Renderer rend = obj.GetComponent();
rend.material.mainTexture = Resources.Load(“grass”) as Texture;
Mesh mesh = obj.GetComponent().mesh;
mesh.Clear ();
mesh.vertices = slopeVertices;
mesh.triangles = slopeTriangles;
mesh.RecalculateNormals ();

Here’s the result. It seems a little werid, as only some part of the cubes changed texture_._

// EDIT: I FIGURED IT OUT :slight_smile:

1 Like