Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7823115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:07:58+00:00 2026-06-02T08:07:58+00:00

Here is my first question. Haven’t been able to find anything on the topic.

  • 0

Here is my first question. Haven’t been able to find anything on the topic.

I want to create an editor script that changes a number of public bools in a script that is attached to a GameObject.

I have this script attached to a GameObject. The GameObject is a prefab:

using UnityEngine;
using System.Collections;

public class ScriptWithPublicBools : MonoBehaviour {

    public bool b1;
    public bool b2;
}

And here is my editor script:

using UnityEngine;
using System.Collections;
using UnityEditor;

public class EditorHelper : ScriptableObject
{
    [MenuItem("Trace/Trace")]
    public static void trace()
    {
        foreach (GameObject g in Selection.gameObjects)
        {
            ScriptWithPublicBools tb = g.GetComponent<ScriptWithPublicBools>();

            if (tb)
            {
                tb.b1 = false;
                tb.b2 = true;
            }
        }
    }
}

The scripts are working fine and the bools on the gameobject is set correctly in the editor. But when I press the PLAY button the values of the two bool switches back the values they were before the script was applied.

It does not matter what the values of the prefab is, the values are just restored to the values before applying the editor script.

Am I doing something wrong or is it a bug?

If I apply the editor script, save the scene as a new scene, and open the newly created scene the values are also wrong.

BUT, if the GameObject is not a prefab all works perfectly, and the values keep their values given by the editor script, even after initiating play mode.

So the problem is only present when using prefabs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:08:00+00:00Added an answer on June 2, 2026 at 8:08 am

    You need to call EditorUtility.SetDirty (tb); after all changes are done, see EditorUtility.SetDirty for more information on this.

    In case you need to change the prefab itself, have a look at PrefabUtility

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first question that I haven't been able to find an answer
This is my first question here, and the first time I haven't been able
I have a quick question here. I know that the cakePHP find('first') function returns
Alright I have a question that seems simple but I haven't been able to
First question here: it is a very short yet fundamental thing in Java that
this is my first question here :) I know that I should not check
This is my first question here, so I hope that I am providing enough
first question here, so hopefully you'll all go gently on me! I've been reading
this is my first question here at Stack Overflow. I've been looking for a
Well, this is my first topic around here, but that shouldn't matter so far.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.