0

I have a prefab Block. In my scene hierarchy, there is a lot of Blocks:

enter image description here

The prefab contains a code that contains an integer value called id.

I wrote a script (to run in edit mode) that sets random values to the id of all blocks and it works well, but when I hit play, all ids go back to 0. If I set the id manually in inspector, it stays correct during runtime.

What is this problem? Any ideas on how I can fix?


I tried to use things like PrefabUtility.RecordPrefabInstancePropertyModifications but it didn't work (or I don't know how to use it correctly).

1 Answer 1

0

I was able to fix it by using EditorUtility.SetDirty(blocks[i]) in the for loop where I was setting the ids of the blocks.

After doing this, the values were maintained.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.