#hi guys can someone help me figure out

1 messages · Page 1 of 1 (latest)

silk salmon
#

after the first respawn, the enemy dosent follow the player

keen night
#

!code

bright harnessBOT
silk salmon
#

i did a shit job on naming things and its biting me in the ass

gaunt lotus
#

this is all so weird

silk salmon
#

my brother

#

i have never learned any unity coding

#

i took coding classes in highschool and uni

#

this is for an art project

gaunt lotus
silk salmon
#

the server dosent let me say bro

#

i wrote all this code...

#

im jamming like 15 different youtube tutorials into one proj

gaunt lotus
#

ok and im asking where you learned unity syntax from

silk salmon
#

and holding it together with my basic java knodwledge

silk salmon
gaunt lotus
#

but there are blatant problems

silk salmon
#

like my knowledge of int bool and float n shit r from java and python

#

ive looked through the api but its giveng me an aneurysm

#

plus my mild dyslexia

keen night
#

Instead of using Resources.Load, loading it as a UnityEngine.Object, spawning it as a GameObject, then getting the Enemy component, you should instead just make enemyRef of type Enemy and drag the prefab into the inspector

#

Ah, wait, actually this is an Enemy so it'd update that prefab reference to a self reference. The Resources.Load might need to stay

gaunt lotus
keen night
#

But you can at least cut out the multiple layers of casting and getcomponent by making it of type Enemy to start

silk salmon
silk salmon
gaunt lotus
#

do you see the problem here

silk salmon
#

my respawn worked fine

keen night
# silk salmon uh... what does updating a prefab reference to a self ref mean

Unity automatically replaces references to things within the same prefab with the corresponding references on the instances it creates. Since this presumably is the enemy prefab, dragging in a reference would mean that it would update to refer to itself. Basically, due to a shortcut unity provides to make dealing with prefabs easier, in this specific case you do need the Resources.Load. But you can still just make the variable of type Enemy

keen night
gaunt lotus
#

ah my bad. i remembered having problems with this under different circumstances

keen night
silk salmon
#

i was thinking the same thing

keen night
silk salmon
keen night
silk salmon
#

it def respawns with the player bracket emtpy

keen night
#

Your Find does not get anything

silk salmon
keen night
#

There's nothing in the scene tagged player

keen night
silk salmon
keen night
silk salmon
keen night
silk salmon
#

so would this work better

#

i might be stupid sorry if i didnt do jack shit to improve it ts is confusing ash

keen night
#

Why are you loading it as a GameObject then getting a component from it

#

Just get it as an Enemy

#

then you don't need to get component

silk salmon
keen night
#

The string is the name

#

not the type

silk salmon
#

im gonna be completley honest im so confused

keen night
#

On that line

#

You can just replace the word GameObject with the word Enemy

silk salmon
#

so under cs
Enemy prefab = Resources.Load<Enemy>
this part
("Enemy");
if (prefab != null)
{
enemyRef = prefab.GetComponent<Enemy>();
}
would all be useless?

silk salmon
#

shit

#

well thats all i changed

#

this is the current state

keen night
#

Yes, and as your error states, your issue is there's nothing tagged "Player" in your scene to find.

silk salmon
#

and unity is saying the object i want to instantiate is null

keen night
#

you create a new variable prefab and then do nothing with it

silk salmon
#

oh

#

so like public int prefab?

#

and then my code will magically work?

#

this feels like a coconut.jpg

#

HELP it wont even respawn anymore i hate my life

keen night
#

You have a variable enemyRef that you spawn a copy of. You need to actually set that to something

silk salmon
silk salmon
#

bro i wanna thank you for your help btw i rlly mean it

keen night
keen night
silk salmon
keen night
silk salmon
keen night
#

This is where you're trying to use it

keen night
#

Why are you making a whole new variable to put this reference in to

#

instead of using the variable you actually want to put the prefab into

silk salmon
#

so ... sorry but.. what would this change look like

#

i deleted the prefab thing

#

btw

keen night
#

Think about how these two problems might relate

#

and how you might reconcile them

silk salmon
keen night
#

You are using a variable you never set,
and setting a variable you never use.

silk salmon
#

how would i set enemy ref to something and where? currently its only used in private Enemy enemyRef which like you said creates the enemy ref as an empty variable

#

and then

#

Enemy newEnemyScript = Instantiate(enemyRef);

#

which creates a new enemy

keen night
#

You aren't setting enemyRef to anything

#

so you are cloning nothing

silk salmon
#

oh fuck

keen night
#

What prefab are you trying to clone

silk salmon
#

Enemy

keen night
#

Cool, where do you get the Enemy prefab?

silk salmon
#

in my resources folder :)

keen night
#

So, you have a variable you want to set to Enemy

#

and a line where you get Enemy

#

So why do you not

#

set that variable

#

to that enemy

silk salmon
#

what country are you from by the way

keen night
#

Irrelevant.

silk salmon
silk salmon
keen night
#

is getting the Enemy prefab

#

from your resources

silk salmon
#

private Enemy enemyRef;

#

oh wait

#

i dont have one

keen night
#

Really?

#

There isn't a single line

#

that loads something

#

from resources

silk salmon
#

i had Enemy prefab= Resources.Load<Enemy>("Enemy");

#

but i deleted it

#

ill put it back

keen night
#

So, you have a line that loads the prefab from resources

#

and you have a variable that is supposed to hold the prefab from resources

#

and you know how to set a variable to a value

#

so do that

silk salmon
#

like this?

keen night
#

why would that even remotely work

#

do you have any clue at all what you are doing

#

or are you just hitting random keys in hopes it works

#

I literally cannot explain this any simpler

#

set the variable

silk salmon
keen night
#

to the value you want

#

that's it

silk salmon
keen night
#

that's the simplest explenation

silk salmon
#

i wont even lie to you

keen night
#

I'm not doing any more of this

#

Open a book. Literally any book. Finnegan's Wake would probably help you understand more than this right now

#

I'm out

silk salmon
#

private enemy enemyref? as the string variable?

keen night
#

Literally the variable that the error is telling you is null

#

Instead of never setting it to anything

#

set it to something

#

!learn

bright harnessBOT
keen night
#

Figure out what words like "variable" mean

silk salmon
keen night
#

I can't explain it if you literally do not know what words mean

silk salmon
#

bro icl if u show me what u mean

keen night
#

no

#

I have

silk salmon
#

i think it would help me understand 1000% percent better

keen night
#

many times

#

I've told you exactly what to do

#

and you've done like twelve completely unrelated different things

silk salmon
#

i understand that but if I lack the fundamental knowledge to achieve the task i feel like its harder to do

keen night
#

This is Sesame Street level.
You have a variable that you never set a value to.
You have a value that you never store in a useful variable.

#

Put two and two together

silk salmon
#

that solved the respawn but it still dosent fix enemy follow...

#

did i do it wrong?

keen night
#

there's nothing tagged Player in the scene

silk salmon
#

oh

#

thank u bro

silk salmon