Assigning a variable in scriptable object script does not work?

what scripts I have:

StatesTemplate class file deriving from scriptable object with a string called locationName that I assigned the string: “dd”

MainScript with a statement that concatenates the location name.
it will store the concatenated string into a variable called text.

problem:

when I check to see what is inside text, I see that the location name is missing.

Then I found this:

“In a deployed build, however, you can’t use ScriptableObjects to save data, but you can use the saved data from the ScriptableObject Assets that you set up during development.” - Manual

I am doing this to try a different method of writing out player choices.
so for my game
it will have different locations
Each location can have different states
I am doing this so I don’t have to type out
press 1 to go to main street every time?
instead I can just do
press 1 to go to

my question:
So I cannot initialize and assign data to variables inside the scripts of scriptable objects?
Is this the issue or am I doing something else wrong?
Do you guys have any suggestions on how I can let the computer write out the next location the player will go for me?

Thank You!!

Hi,

Unless I misunderstood your description, you do not use the ScriptableObject to save data, do you? If you do not modify the scriptable object during runtime, the quote from the manual should be irrelevant for your problem.

Did you test your game in the Unity editor? Does the text get displayed? I assume you want to see “press 1 to go to dd”.

Also did you create an actual scriptable object or are you trying to use the script? The latter won’t work.

1 Like

Hello!
Thank you for your reply and clarification about the runtime!! Yeah, I put “dd” inside locationName. I assume that is not really considered saving data.
yes, I want to say “press 1 to go to dd”.
also I figured out the issue!
I think I had to restart unity after making changes to a variable inside my scriptable object?
Otherwise, it won’t update…
locationName was empty before.
then I added dd to it
it’s just that after adding “dd” nothing really changed?
but after restarting unity it seemed to work.

maybe my unity is glitchy.

Thank you for your help!

I’m glad you solved the problem. :slight_smile:

Yes, that might have been the case. It’s not uncommon that Unity does not update certain things when working with different objects in the Assets folder. Restarting usually helps.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms