Hi GIL,
I need unique Ids to be generated at runtime, because I use object variables on combatants and they need to not be shared. So I need each combatant to have unique Ids. How do I generate a new id and assign it to a combantant when they're initialized? I think I can put a game event in the default init of each combatant, then call a function in the game event, but I just need some help with the script. I would do something like
combatants[1].Variables.ChangeString(xxx, "whatever")
But I don't know how to
1- change the ORK GUID
2 - Make the change by actors or by selected data, not by combatant index, so I can change the variables of the combatant that started the script.
E.g. like this:
using UnityEngine;
using ORKFramework;
using ORKFramework.Behaviours;
public class SaveVariableObjectID : MonoBehaviour, IComponentSaveData
{
// save key used to store different components of this class
public string saveKey = "variableObjectID";
private ObjectVariablesComponent variables;
private void Start()
{
this.variables = this.GetComponent<ObjectVariablesComponent>();
if(this.variables != null)
{
this.variables.objectID = System.Guid.NewGuid().ToString();
}
}
public string GetSaveKey()
{
return saveKey;
}
// called when the component data is saved/stored
public DataObject SaveGame()
{
DataObject data = new DataObject();
if(this.variables != null)
{
data.Set("objectID", this.variables.objectID);
}
return data;
}
// called when the component data is loaded
public void LoadGame(DataObject data)
{
if(data != null &&
this.variables != null)
{
data.Get("objectID", ref this.variables.objectID);
}
}
}
Add the component to your combatant's game objects - it'll create a random object ID when spawned and save/load the ID with the combatant's data.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Using a Combatant Spawner with Remember Combatants enabled should solve that issue, as it'd store the combatant's status (and with that the custom component save data).
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
For the player group : I use standard ORK, it spawns a prefab combatant, with the script attached on the prefab. Same problem with the player: new guid every time I change scene.
Try changing private void Start to private void Awake.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
I tried putting a static bool to only run the script once... but then my the new guid gets overwritten by ORK GUID then. Tried putting no GUID in ork editor, but then it generates one. Tried putting an obj var component instead, same problem.
Any ideas?
I'll do some tests to get this working.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
using UnityEngine;
using ORKFramework;
using ORKFramework.Behaviours;
public class SaveVariableObjectID : MonoBehaviour, IComponentSaveData
{
// save key used to store different components of this class
public string saveKey = "variableObjectID";
private ObjectVariablesComponent variables;
private void Start()
{
this.InitVariables();
}
public void InitVariables()
{
if(this.variables == null)
{
this.variables = this.GetComponent<ObjectVariablesComponent>();
if(this.variables != null)
{
this.variables.objectID = System.Guid.NewGuid().ToString();
}
}
}
public string GetSaveKey()
{
return saveKey;
}
// called when the component data is saved/stored
public DataObject SaveGame()
{
DataObject data = new DataObject();
if(this.variables != null)
{
data.Set("objectID", this.variables.objectID);
}
return data;
}
// called when the component data is loaded
public void LoadGame(DataObject data)
{
if(data != null)
{
this.InitVariables();
if(this.variables != null)
{
data.Get("objectID", ref this.variables.objectID);
}
}
}
}
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
I have one last simple question regarding this. I will be using this unique GUID in the ork event system, so I need to store the GUID into a game variable on the combatant object. So I thought I'd just add a line under there:
this.variables.objectID = System.Guid.NewGuid().ToString();
// to store the GUID into a game var
this.variables.initialVariables.gameVariable.SetValue(whateverGameVariable, this.variables.objectID)
I looked around and tried to understand, but I have no idea of the syntax, or if I'm even using the right command. Can you point me to the right direction?
this.variables.GetHandler().Set("key", this.variables.objectID);
Instead of "key", use the variable key you want to store the GUID as.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!