- Home /
Can you assign a simple variable directly in Inspector without writing a script?
When i only need to assign a single integer or float i'm writing a script that declares a public float/int/etc and then filling it in the Inspector. Would be nice to just add a float/int/string as a Unity built in component like all that other stuff in the Inspector.
When i only need to assign a single integer or float
Assigning to what?
If you want to associate data to a gameObject, either you attach a script to it with the data you need, or you create a dictionary gameObject → data in the script needing the information.
Yeah that's what i'm talking about. But to me as a noob in program$$anonymous$$g it seems kinda weird that you need to create a whole separate script just for adding a single number to gameobject. I mean there are all sorts of complicated things (Physics stuff, Animations, Particle Systems etc.) which can be assigned in one click to gameobject via editor gui and compared to this manually writing a primitime single line script for assigning a float or int looks like unnecessary overcomplication.
Behind the hood, Physics, Animation, ... components are scripts.
Having a dedicated (simple) component to associate data to a gameObject is possible. However, I$$anonymous$$HO, it's a symptom of bad architecture. Components are meant to give behaviour to a gameObject, i.e, make a gameObject do things.
If you need to associate data to a gameObject, I would not go with a "data container component". The solution heavily depends on what's must be done and the current architecture.
Answer by MomkeyDev · Jan 08, 2021 at 02:44 PM
If you mean something like adding a component. Nah you can't.
Actually sorry, you might actually can ? If you mean something like adding a simple variable that can be referenced later. You can make your own script to do that. Just make sure you add a way to know which variable is which (Like making some kind of search function) Still really not recommending it but it really depend on what you're trying to do.
sorry to bump old thread, but i feel guilty to say misinformation
Well, to be fair, his question ended with
without writing a script?
Answer by Stonemass · Jan 08, 2021 at 01:18 PM
yep...like others things but....not. i really hate the boolean behavior.
Answer by logicandchaos · Jan 10, 2021 at 12:54 PM
Yes and no, you still have to make a script.. but if you make a script that inherits from scriptableObject and stores just one variable, then you can make variables in your project folders, it's a great way to connect all your code.
I'm very new to both program$$anonymous$$g and unity so i don't fully understand what you mean. Can you explain it on a noob level?
Your answer
Follow this Question
Related Questions
How to control 2 scenes with 1 script 0 Answers
newbie: how to setup an input? 2 Answers
Having some issues with firing a "projectile" 1 Answer
Basics of procedural map generation 0 Answers
Why won't my guy move forward/back? 2 Answers