im currently programming a game and stored all my options inside scriptableObjects.
Example:
using UnityEngine;
[CreateAssetMenu]
public class ProjectileScriptableObject : ScriptableObject {
[Tooltip("Projectile")]
public GameObject rocket;
[Tooltip("Max Ammo")]
public int maxAmmo = 5;
[Tooltip("Infinite Ammo")]
public bool infAmmo = false;
[Tooltip("Firerrate")]
public float fireRate = 1.0f;
[Tooltip("Projectile Speed")]
public float projectileSpeed = 100.0f;
[Tooltip("Hitable layers")]
public LayerMask mask;
}
Is it possible to change these values while the game is running?
I thought i could use that to make an pause-/optionsmenu.
So that i could straight enter the value in an inputfield.
I found some youtubers but they only created settings for easy, medium, hard and loaded them, but that is not what i want.
Can anyone help me?
thanks in advance
You can change the values of a scriptable object at runtime, but the changes won’t persist in a build (only the editor). You’d just assign to the variable like you always do.
At runtime you don’t work with the scriptable object itself, you work with an instance of it. Like any other resource, the original is on disk and the one you work with is on memory. Change it however you want at runtime, but they are more of a prebuild storage for the devs.
Im programming this game with a group…but the other people in this group are doing 3dmodels and tetures etc. and have no idea of unity. but I would like to give them the chance to edit the settings of the game for playtesting. So they can test in this very alpha build what the optimal projectilespeed, playerspeed, explosionforce etc settings are.
Sure, then you could modify the SO during the game session if that’s all it’s for.
Though, in the editor, their changes will persist.
Alternatively, or in addition to, you could show them the very basics of the Unity editor and where they could edit the SO directly. Whichever seems easier for ya.
Sure. Just set the variable in the appropriate event on the InputField.
If you want it to persist between game sessions, then write the data out to a text file. Its a fairly useful skill to be able to have as a programmer anyway, its going to form the basis of every single save system you ever write.
Just be cautious with changing the SO inside the editor. SOs are assets, which means changes made to them in the editor are permanent, even if you are in play mode. This can lead to some unexpected behavior.