Is there a way to add Object Variables to an Object with the Object Variable Component in a running game?
For example I have a Cube Object that starts with no Object Variable Component on it, but does have a TIck Machine on Update.
This Tick Machine checks if the an Object Variable Component Exists.
If True wait 1 second and remove this Tick Machine.
If False Add Component, Object Variable Component.
Now that the Object Variable Component is attached to the Cube, it has no Initial Object Variables.
Is there a way to add/set/remove variables to appear in the Object Variable Component list?
The reason I'm doing this is I found that when the Object Variable Component is attached during gameplay it generates a new Object ID and that is ultimately what I want. But I can't figure out how to add in the Variables to the Object Variable Component during gameplay.
Unless there is a easy way to generate a New Object ID on the Object Variable Component during gameplay via Schematic Nodes that I'm not seeing?
Any help is greatly appreciated!
Thanks,
-Nate
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Any help is greatly appreciated!
Thanks,
-Nate
Follow my project on Reddit - My Game DevLog
relentingVids - My YouTube Channel
Half Super Shop - My Shop
However, the handler is already cached the first time the variables are accessed, so if you change the object ID at a later time it might not have any impact.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Edit* I figured out how to place the ObjectVariableComponent and set the objectID. Now I'm just trying to figure out how to add the variables to it by code.
Thanks,
-Nate
Follow my project on Reddit - My Game DevLog
relentingVids - My YouTube Channel
Half Super Shop - My Shop
ObjectVariablesComponent component = gameObject.AddComponent<ObjectVariablesComponent>();
component.objectID = "id";
VariableHandler handler = component.GetHandler();
handler.Set("key", value);
Add the component, set the ID, get the handler and change variables on the handler with key/value as you want :)
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
I was doing just
component.handler.Set(key, value);
Without getting the handler first.
But that wasn’t doing anything from what I could tell.
Appreciate all the help!
Thanks,
-Nate
Follow my project on Reddit - My Game DevLog
relentingVids - My YouTube Channel
Half Super Shop - My Shop
However the way I’m trying to update the object variables is all at once by a menu item, in an editor script when the game isn’t running. Is this a possibility?
Follow my project on Reddit - My Game DevLog
relentingVids - My YouTube Channel
Half Super Shop - My Shop
In that case you'd have to set up the whole initial variable setup by code, which is very complicated and can lead to lots of errors when not done correctly.
Isn't it easier just setting up the component once, copy it and paste it on other game objects?
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
My script currently is reading a CSV file and then splits and parses the data for each line. It creates a ScriptableObject with that lines split parsed data and an empty gameObject with a name value from the data. It then creates a Prefab out of that named empty GameObject and destroys that GameObject Immediately afterwards so it’s not left in the scene.
I came up with a work around for now since I can’t figure out how to directly tie the data to the Object Variable Component. I made another script with just public variables and have that added to to Prefab when it’s created and then inserts the CSV data into those public fields. I then created a schematic that will pull the data from that script and add it to the Object Variable Component automatically at runtime with it placed in an Auto Machine Start. I know it’s a lot of duplicated variables but ultimately having the data in the Object Variable Component makes it easier to work with Makinom. I have a video that runs through the scripts I made here if interested.
If I could get the data to go directly on the Object Variable Component that would save me the trouble from doing the workaround.
Follow my project on Reddit - My Game DevLog
relentingVids - My YouTube Channel
Half Super Shop - My Shop
It's complex but doable - depending on which type of variable it is (bool, float, string, etc.) you'll have to initialize different things.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
How does the initialVariables field work? Is it similar to the VariableHandler?
Follow my project on Reddit - My Game DevLog
relentingVids - My YouTube Channel
Half Super Shop - My Shop
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Follow my project on Reddit - My Game DevLog
relentingVids - My YouTube Channel
Half Super Shop - My Shop
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Follow my project on Reddit - My Game DevLog
relentingVids - My YouTube Channel
Half Super Shop - My Shop