#Better code

1 messages · Page 1 of 1 (latest)

lucid musk
#

There's absolutely no reason to ever use Find is terribley slow, and uses a string so prone to errors.

You have a reference to the object when you spawn something, so you take that reference and pass it over/ cache it somewhere accessible .. and then create your dictionary with the reference you already have

little forge
#

i can send you the entire code, but you might not understand it.
In fact no one ever did, except me.

lucid musk
#

You especially shouldn't be repeatidly doing the search. Do it once, cache it, reuse the cached value

#

what do you think I'm gonna do with the code? 😛

void merlin
#

GameObject obj = Instantiate(…,…,…);

Now you got a direct reference to the object without having to use find

little forge
void merlin
#

Then just add obj to your dictionary

lucid musk
#

I don't need to check if I'm right, I already know I am

void merlin
little forge
#

obj is the object youve instantiated

void merlin
#

Yes

little forge
#

but to get this reference you first need to instantiate it

void merlin
#

Yes

lucid musk
#

instantiate returns the reference

little forge
#

but in my code, to instantiate it, i need to know which object i should instantiate

#

which is char11

void merlin