#Sorry, I dont know how to delete this. It will self destruct in 1 hour.

1 messages · Page 1 of 1 (latest)

polar cargo
#

hmm. intriguing.

#

@timid rampart you present? ^^

timid rampart
#

Eyo what's up

#

Ok so what's your current situation

polar cargo
#

yah. Im trying to remember how to refer to the variable...

timid rampart
#

Ah so you're trying to get a variable on another script?

polar cargo
#

yeah.

#

tbh, considering how common issue that is googling

#

is pretty damn unfruitful.

timid rampart
#

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?

polar cargo
#

I swear I've used Objectname.Classname.Variablename before.

#

yes.

#

duplicate children of the prefab.

timid rampart
#

Ok so

polar cargo
#

duplicate children of the duplicated prefab.

timid rampart
#

Where are you trying to access the text

#

Is it from the parent object or somewhere else

polar cargo
#

if the script aint it

polar cargo
#

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.

timid rampart
#

Ok and the parent of the duplicated prefab spawns them?

polar cargo
#

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.

timid rampart
#

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

polar cargo
#

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.

timid rampart
#

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...
polar cargo
#

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.

timid rampart
#

So you want .text = "Hello World" to instead assign text from the scriptable?

polar cargo
#

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.

polar cargo
#

its a mess.^

#

honestly. thanks so much for help all the way trough to this far...

timid rampart
#

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

timid rampart
polar cargo
#

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.

timid rampart
#

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

polar cargo
#

but in consideration to the main branch, I'll probably have to change all of them later.

timid rampart
#

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

timid rampart
polar cargo
#

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.

timid rampart
#

You should probably delete this thread now just so they don't have a lot of unused ones

polar cargo
#

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?

timid rampart
#

if there's no delete i guess archive will do the trick