#Sorry, I dont know how to delete this. It will self destruct in 1 hour.
1 messages · Page 1 of 1 (latest)
yah. Im trying to remember how to refer to the variable...
Ah so you're trying to get a variable on another script?
yeah.
tbh, considering how common issue that is googling
is pretty damn unfruitful.
Yeah its a toughie earlier on
it can depend on a lot too
So you have multiple objects that have a text component and you want to modify their text?
I swear I've used Objectname.Classname.Variablename before.
yes.
duplicate children of the prefab.
This is fine, but you'll need to access the component that has it
Ok so
duplicate children of the duplicated prefab.
Where are you trying to access the text
Is it from the parent object or somewhere else
there is no component that has it I think.
if the script aint it
ah, its something I need to Awake upon gamelaunch, and since I wasnt sure where to put the script that does it, I figured, GameManager will do.
its a singleton too.
oh wait. thats not what you asked.
the text to replace the text of the child of the parent of the duplicate prefab.^
will be located in a scriptable object.
Ok and the parent of the duplicated prefab spawns them?
but accessing it, happens trough script that instantiates the duplicates.
which
resides in the GameManager rn.
didnt wanna put the script to duplicate the prefab into the prefab, cause then it duplicates the code infinitely.
Ok so, if you have the scriptable on the GameManager and the spawning on the GameManager too
you could get the text component on each of the spawned objects
and set the text that way
something like
spawnedObject.GetComponent<Text>().text = scriptable.text...
it depends on what type of Text component you're using
this sounds reasonable to me. what will the spawned objects names be?
or is there a way to refer to them? the name for the spawned prefab is set. That's newChild rn.
but that isnt what we are trying to find.
the other, child objects... dont think I have a name for them. if one isnt generated.
unless, referring to just the same name as the prefab child object will do it.
When you instantiate an object, the method returns the created object
So you can get information through it:
GameObject instance = Instantiate(prefab);
instance.GetComponent<Component>();
//Assign data...
rn I have this:
Instantiate(prefab ) would be the name of the instance, if it contains all the information within it, that'd be nice.
So you want .text = "Hello World" to instead assign text from the scriptable?
its a placeholder.
actually, the text in the scriptable object isnt locked yet. ^
it could be anything.
this made no sense to me ^ script aint a component after all
but then, TMP_Text wouldnt know which TMP text to choose.
since there's two children, both which have it.
rn I dont even have access to the scriptable object. I have my own created, to simulate one. but it might be unfinished.
its a mess.^
honestly. thanks so much for help all the way trough to this far...
The script is a component but it depends on the name
What is the name of:
- The script you're trying to access
- The scriptable object
as in the name of the classes for both of them
it's no problem! We all gotta start somewhere yk?
aye! :D
the script Im trying to access rn is VariableX. But honestly. I should rename it to something else.
the scriptable object... well. the one I have, is... TaskVariables rn. ^the one the main project branch has... of that I have no idea.
possibly a Variable Manager of some sort.
yeah you should rename it to something clear
It sounds like you need to clean up your script names and keep the consistent, especially if your main branch has a different name on them too 😬
so you should be looking for GetComponent<VariableX> right now
hm. I see.
if I were to be consistent with my script naming, it'd become "Variable for the variable God."
but in consideration to the main branch, I'll probably have to change all of them later.
If a class is only for data its always good to name it as such
Like TextData etc
and for Scriptables, if you're just stating data, you can always name them definitions as you're defining data
Examples for scriptables could be ItemDefinition, EnemyStats etc
They're clear and straight to the point
How did that go for you
I'm pretty sure it worked!
the script is still to have any altering words, so I cannot be sure. ^but its all green.
no errors around.
I think... this is good enough for today. ^^ working hours getting late. :D thank you again.
ey nice
Yeah no problem if you're needing further help post it in the help channels I should be around back and forth but there's a lot of amazing people here that will help too
You should probably delete this thread now just so they don't have a lot of unused ones
yeah. for sure.
see you around^^ If I dont get banned today.
Sorry, I dont know how to delete this. It will self destruct in 1 hour.
rip....
gah. archiving didnt destroy it?
is there nothing like this
if there's no delete i guess archive will do the trick