#💻┃code-beginner

1 messages · Page 454 of 1

umbral rock
cosmic dagger
#

All you have to look at is the local position of the "EndPosition" GameObject, that's it . . .

umbral rock
#

but if u look at the endpositioning, its not higher right?

finite yoke
#

hi
help me pls, why does i get "MissingReferenceException: The object of type 'Animator' has been destroyed" error after scene reloading? The most weird part is that script actually works but throws this error for some reason
MissingReferenceException: The object of type 'Animator' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. UnityEngine.Animator.GetFloat (System.String name) (at <9b89611000504a9585efec19be4faf3b>:0) Movement.RunStop (UnityEngine.InputSystem.InputAction+CallbackContext context) (at Assets/Scripts/Player/Movement.cs:141) UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.CallbackArray1[System.Action1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Utilities/DelegateHelpers.cs:46) UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*) UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)

cosmic dagger
#

You have to actually click on it and look . . .

steep rose
#

the Y value should be higher

umbral rock
#

this the inspector

steep rose
#

what im seeing is the child object is the exact position of the parent object

#

i could be wrong

#

brb

steel hull
#

can someone PLEASE help me with moving

#

I can't even make movement system please

cosmic dagger
umbral rock
#

i dont know why the spawner is spawning higher

steel hull
#

I asked several times no one answered

#

where is the page where you see the inputs

#

like yk "Mouse X"

steel hull
#

no like where do I see how many Input options are there?

cosmic quail
steel hull
#

thank youu

cosmic dagger
steel hull
#

how do I make a movement system can someone please send a tutorial

#

my movement system doesn't work

languid spire
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

cosmic dagger
steel hull
#

that is why I am asking you guys

cosmic quail
steel hull
#

wasd fps

cosmic dagger
cosmic dagger
#

Great Brackeys . . . 🙄

steel hull
#

he uhm sort of adds the directions then sets it as a vector3...

pale ocean
final kestrel
#
  public void LoadData(GameData data)
        {
            transform.position = data.playerPosition.ToVector3();
        }

        public void SaveData(GameData data)
        {
            data.playerPosition = new SerializableVector3(this.transform.position);
        }

I have this class called Serializable vector which basically takes in a vector3 so that I can save it as json. When I try to load, it sometimes does not update my player position to the point where I saved it. I have to load couple times for it to work. Why is that?

#
[System.Serializable]
public class SerializableVector3
{
    public float x;
    public float y;
    public float z;

    public SerializableVector3() {}

    public SerializableVector3(float rX, float rY, float rZ)
    {
        x = rX;
        y = rY;
        z = rZ;
    }

    public SerializableVector3(Vector3 v3)
    {
        x = v3.x;
        y = v3.y;
        z = v3.z;
    }

    public Vector3 ToVector3()
    {
        return new Vector3(x, y, z);
    }
}

This is the class

finite yoke
steep rose
#

you need to raise the object to the position that you want

#

then check in LocalPosition not Position

steel hull
#

I think I figured it out

steep rose
eternal falconBOT
steep rose
#

bro these bots are on a lifeline man

#

also show us some code

steel hull
#

I DID IT

finite yoke
# steep rose first do this to your !code

but which code you need? i get the error i wrote in that message when a method that uses the animator reference runs, there's nothing special in this part of code

steel hull
#

WITHOUT HELP

#

but now I don't know why w makes me go right 😦

#

I don't get it 😦

languid spire
#

Go and follow the pathways from the learn site. we are not here to answer every basic unity question you have

steep rose
verbal dome
steel hull
final kestrel
finite yoke
steep rose
umbral rock
finite yoke
steep rose
languid spire
eternal falconBOT
steep rose
final kestrel
finite yoke
final kestrel
languid spire
steep rose
#

to see if im correct

finite yoke
wintry quarry
#

You're subscribing something to an input handler

#

And you're never unsubscribing it

#

That's your error

#

I.e. you did something like someAction.performed += something;

#

But you never did the equivalent -=

steep rose
eternal falconBOT
wintry quarry
#

So the problem is in your input handling code

vital gale
#

Can someone please explain why when someone hosts, the first method called is OnStartAuthority and then OnStartClient.. but when someone joins the lobby the first method is OnStartClient and then OnStartAuthority?

finite yoke
vital gale
#

whoops, sorry

cosmic dagger
finite yoke
# wintry quarry But you never did the equivalent -=

first time when i used InputSystm i watched a yt guide how to do it and it says that i should write for each action something like:

void OnEnable()
{
     someAction.Enable();
     someAction.performed += something;
}

void OnDisable()
{ someAction.Disable(); }
wintry quarry
#
void OnDisable() {
  someAction.performed -= something;
}```
#

yt guides are for getting you started quick but sometimes they skip a step...

wintry quarry
finite yoke
finite yoke
wintry quarry
finite yoke
#

let me try

finite yoke
#

i won't even think about this

#

that this is because i forgot to write one line

final kestrel
#

Maybe it is trying to load too fast hence the flickering between saved position and the current position

#

It works fine on my inventory though. I can save and load it without a problem its just the player position.

languid spire
#

if you dont share the relevant code how can you expect us to help you fix it?

winter tinsel
wintry quarry
#

not a Collision

final kestrel
wintry quarry
#

wrong parameter type

winter tinsel
#

ah

#

so Collider collider right?

wintry quarry
#

you can name it whatever you want

umbral rock
winter tinsel
languid spire
rich adder
# winter tinsel just logically

the important part is the type, the name of the parameter is inconsequential . You can literally name it "bread" and it wouldn't matter

winter tinsel
#

y dont say

rich adder
#

jesus christ this code screams AI

final kestrel
#

Not AI i got it from a repo

cosmic dagger
final kestrel
rich adder
final kestrel
#

Well yeah I tried hard understanding what it does and comments help a lot really.

rich adder
#

but yeah comments are good , use them

final kestrel
languid spire
final kestrel
#

Save is the same too

languid spire
queen adder
#

hi does anyone know this extension??

languid spire
#

you have only implemented half of the singleton pattern

rich adder
#

if you're talking about the sugegstionbox/Intellisense

queen adder
#

how to get it

rich adder
eternal falconBOT
rich adder
#

follow the instructions 🆙

queen adder
#

oh thanks

umbral rock
final kestrel
languid spire
final kestrel
languid spire
#

of course, DebugLogError does not stop processing

queen adder
languid spire
#

the script still exists and still runs

rich adder
final kestrel
languid spire
final kestrel
#

ah okay I can do that

#
  private void Awake() {
    if(instance != null){
        Debug.LogError("Found more than one Data Persistence Manager in the scene");
        Destroy(this.gameObject);
    }
    instance = this;
   }
#

It remains untouched on load. I looked for the duplicates but could not find any either.

languid spire
#

you really do not need to put this. everywhere it wastes your time and ours

final kestrel
#

All right I wont do that

final kestrel
#

Well I tried debugging and the serializable vector I'm trying to get the values from is accurate with whats saved in json.

#

Could it be that I'm doing it in update? Checking for the keystroke? It somehow runs too fast that unity cannot process or something

sweet sierra
#

Uhh how can I tackle this?

cosmic dagger
sweet sierra
#

Cannot convert from GameObject to AudioSource, obviously

#

But how do I find an AudioSource of that tag?

rich adder
#

so why are you trying to put a gameobject in audiosource

sweet sierra
#

I don't want to 😂

rich adder
#

the same way you get any other component

cosmic dagger
#

why are you trying to assign an AudioSource to a GameObject?

sweet sierra
#

I can't reference it directly though. I'm using DDOL

rich adder
#

.GetComponent

sweet sierra
#

Ohhhhh 😲

languid spire
sweet sierra
#

This makes sense 🤦

#

Get the gameObject, then it's component

#

Duhh

cosmic dagger
sweet sierra
#

Feels like I'm dumb and smart at the same time lol

cosmic dagger
rich adder
#

any time you need runtime components you will usually be using GetComponent/TryGetComponent

sweet sierra
#

Yes I'm pretty used to that by now

#

Also, GetComponentInChild/Parent. Saviors 🙌

rich adder
#

if you only have 1 of something then sstick to FindObjectOfType directly, no tags needed

sweet sierra
#

Yes. Here I had more than one. That's why I had to

rich adder
#

yes

final kestrel
rich adder
sweet sierra
#

Well actually... we had deadline today 💀. So I had to rush things a little

#

But the deadline got extended till monday so now at least adding the option to turn volume up/down

#

Otherwise, it's implemented and works perfectly fine

rich adder
#

its a good read if you got the time, check it out

winter tinsel
sweet sierra
rich adder
cosmic dagger
rich adder
#

iirc the new unity version changed the method name

winter tinsel
sweet sierra
#

Guys.. quick question.

Is
int something = PlayerPrefs.GetInt(key, defaultValue)

The same as:

if (!PlayerPrefs.HasKey(key))
{
    something = defaultValue;
}
else 
{
    something = PlayerPrefs.GetInt(key); 
}

Or is one better than the other?

wintry quarry
#

because the second one doesn't do anything if the key does exist

sweet sierra
#

Fixed that*

#

Now?

wintry quarry
#

oh you changed it

sweet sierra
#

Yeah mb I missed that earlier

wintry quarry
# sweet sierra Now?

now.. they behave the same but the first one is much cleaner and more performant

rich adder
#

Just when they think they've got the answers, I change the questions

sweet sierra
#

So I was right all along 👑. I saw a youtuber doing the latter and was kinda confused that why not use the overload?

wintry quarry
#

Youtubers are entertainers first, programmers second.

sweet sierra
#

Hence top hackers not teaching hacking 🌝

wintry quarry
#

Youtube tutorials are often riddled with errors and bad practices

rich adder
#

deletes old videos UnityChanPanicWork

wintry quarry
#

I mean... most code is riddled with errors and bad practices, we're all on a learning journey

sweet sierra
#

Literally. Also, they (most) only really teach one way which I find kinda wrong because everything has different best case usages soo... 🤓

wintry quarry
#

I'm learning ECS right now and I'm sure my code is hot garbage

finite dew
winter tinsel
#

can i use getComponent<> to get the component without specifying its name?

#

specifically if theres only one component

finite dew
#

but you always have to do that

ivory bobcat
#

What do you mean by "without specifying it's name"?

finite dew
wintry quarry
#

Transform is on every GameObject

#

No, you have to specify which component you want.

#

the code has no idea how many components there are until runtime

#

so it won't know what type you want without you telling it

winter tinsel
wintry quarry
rich adder
wintry quarry
#

you do GetComponent<somethingscript>() to get that script

ivory bobcat
#

Maybe consider referencing through the inspector instead, if applicable.

languid spire
winter tinsel
wintry quarry
#

as I said 5 times

#

It doesn't make any sense

winter tinsel
rich adder
#

NO because there are other components besides your script

cosmic dagger
wintry quarry
#

You could do GetComponent<Component>() but then you have no idea what component you're getting. Likely you'll get the Transform

wintry quarry
winter tinsel
#

yeah, how do i get the script wihtout specifying the name of the script

wintry quarry
#

you don't

winter tinsel
#

but specifying that i want a script

#

and no other component

cosmic dagger
wintry quarry
ivory bobcat
steep rose
#

its useless

wintry quarry
#

YOu could do:

Behaviour b = GetComponent<Behaviour>();``` but then you can't access any of your script data
#

only .enabled

finite dew
steep rose
#

you would be wasting your time if you wanted to not get the type

finite dew
#

you can get a base class than can be any of the various deriving classes

#

I'm not sure if that's what you mean or need but it's helpful knowledge

#

it's called inheritance

rich adder
#

no idea at this point what the purpose of this is

steep rose
winter tinsel
#

i have a gameobject with a script that has name x
i want the script, can i get the script without specifying the name of the script, BUT specifying that i need a script

#

that exists where im looking

finite dew
#

the code needs to know what kind of script it is before it starts looking for it

ivory bobcat
finite dew
#

so its name

cosmic dagger
# winter tinsel but specifying that i want a script

a script is just a file that holds a class (which is a type). if a class derives from MonoBehaviour, you can add it to a GameObject. a MonoBehaviour is a Component that when attached to a GameObject creates an instance of that component . . .

raw token
# final kestrel ``` private void Awake() { if(instance != null){ Debug.LogError("F...

On a belated note, this looks a little suspect for a singleton implementation - if instance is already set, you do destroy the new game object, but then you overwrite instance with the script on the to-be-destroyed GO anyway.

Neither Debug.LogError() nor Destroy() will exit method execution. You'd need to return, throw an exception, or put the assignment in an else block

rich adder
wintry quarry
rich adder
#

sounds like an XY question

wintry quarry
#

It's 100% an XY problem

polar acorn
wintry quarry
winter tinsel
rich adder
#

they are types yes

#

class specifically

sweet sierra
rich adder
#

scripts are just files.

polar acorn
#

Any answer I give could be technically correct but give you the wrong information

#

because you are coming at this entirely wrong

winter tinsel
winter tinsel
polar acorn
wintry quarry
#

what are you confirming

rich adder
polar acorn
#

How is the code supposed to know that

#

It can't just "know" that every object has one and only one script

wintry quarry
polar acorn
#

unless you tell it that

ivory bobcat
polar acorn
#

As far as unity is concerned, every gam object has a potentially limitless amount of components

#

and as such, the code is structured around that assumption

finite dew
rich adder
#

guess what Transform is already a "Script" etc.

sweet sierra
rich adder
#

they are components, so is any script you attach to gameobjects

winter tinsel
wintry quarry
#

they already derive from MonoBehaviour and Behaviour, but those probably are not useful to you

finite dew
# winter tinsel different scripts

you need to create a base class that will have the functionality you need on all those scripts, then make all those scripts derive from that base class
it's called inheritance look it up

#

and you need to getcomponent that base class

#

then and only then you can do what you wanna do

polar acorn
# winter tinsel different scripts

So, here's a question. Let's assume that you could get the one specific MonoScript instance as a component on an object.

What the hell would you do with it afterwards if you don't know what script it is?
If you could do Component c = GetTheOneScriptMagicFunction(); how do you intend to use it

#

all you'd know about it is that it exists

#

you couldn't access any properties, functions, or variables on it

#

because you could only access things that Component had

final kestrel
toxic pine
#

Does anyone know how to freeze the position of a rigidbody in a script

final kestrel
#

I do not change player position any other place than in my controller.

rich adder
#

its like the top result

polar acorn
ivory bobcat
rich adder
#

imagine that..

cosmic dagger
toxic pine
#

alr

languid spire
trim hedge
#

Hi everybody, could someone point me in the right direction on how to center my player prefab while climbing ladders?

This is my HandleClimbing, part of PlayerMovement script: https://pastebin.com/KuE40FUv

I tried to follow "WorldToCell" and "GetCellCenterWorld", but I wasn't able to reference the grid tilemap in the player prefab, when I tried I'd get "type mismatch" in the editor.

Right now my climbing works and all, but I wanted it to be always in the center of the ladder.

Should I be handling this from the "ClimbingTilemap" where the ladders are placed? And then use FindObjectOfType from the player to call a method that centers it? I'm confused if this is the right way, it seems like it should be simpler.

final kestrel
# languid spire which tells me that somewhere you are storing a 'previous player position' or so...

I am looking into it but cannot find any storing I'm doing regarding the player position. I thought maybe I was actually moving when I press load button which causes the flickering. Unity not deciding whether it should teleport me to the saved location or actually process the current movement. I lifted my hands from the keyboard and stood still when I pressed load but nah on 2nd or 3rd loading attempt it still flickers

languid spire
final kestrel
#

I used a boolean to disable the movement if its in a loading phasr. It works okay now

#

My experiment of lifting my hands up in the air was not reliable it seems

languid spire
#

then it is your movement code causing the problem

final kestrel
#

Yes I will keep looking into it.

#

Thanks for your time

nova shore
#

the sphere is parented to another object, it has a kinematic rb
SphericalShell.GetComponent<Rigidbody>().Move(Vector3.up * 10,Quaternion.identity);

IT JUST DOESNT WANNA MOVE, ive been stuck for an hour tryna make a sphere mvoe im gonna cry

#

the worst part is im sure ive tried every way of tryna move an object in the book

nova shore
#

bro i dont care where it goes

#

i just want it to budge

polar acorn
#

You're putting it at 0, 10, 0 every frame

nova shore
#

yea but it isnt at 0,10,0 is it

cosmic quail
nova shore
#

yea

cosmic dagger
polar acorn
nova shore
#

mf how the fuck did i not read the docs

polar acorn
rich adder
nova shore
modest dust
trim hedge
# modest dust You're getting a type mismatch because you cannot reference a scene object in a ...

thanks! That worked, instead of trying to reference the grid directly in the prefab, I referenced it in the player object that's in the scene! Do you know if there's a smarter way of doing this centering thing though? I'd do it in "OnTriggerEnter2D" but the collider I get is from the tilemap which doesn't have the accurate transform position of the ladder tile, in fact its position is always 0

steep rose
#

This is fake do not click it

#

thanks

fickle plume
#

!ban 1269754182391300157 spam

eternal falconBOT
#

dynoSuccess daring_wolf_85460 was banned.

steel hull
#

quick question-I have a player that is an empyt object, inside the player object I have a capsule and the main camera. Which part do I apply rigidbody for physics to work?

languid spire
eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

steel hull
#

where are the guys from yesterday? you were being toxic and you still are

#

how am I supposed to locate exactly what I am looking for in this gigantic tutorial page?

languid spire
steel hull
fickle plume
steel hull
#

or can you not read

#

BEGINNER

polar acorn
polar acorn
languid spire
#

Yes, beginner, no 'CAN NOT BE ARSED TO LEARN'

steel hull
fickle plume
#

@steel hull Make some effort to learn first. When you are completely blank slate you won't even be able to understand the help you are getting.

polar acorn
steel hull
#

I am trying to be as polite as possible

fickle plume
steep rose
#

Fogsight was being the most polite i dont see how he is toxic

steel hull
steel hull
#

stevesmith or sum

steep rose
#

same with steve

polar acorn
cosmic quail
fickle plume
steel hull
#

yes I do try them to understand first

#

but before I move on I need to understand the concept of this discord channel should be it, no?

cosmic quail
steel hull
cosmic quail
steel hull
#

I will try to send you a video

cosmic quail
#

maybe you forgot the collider then?

steel hull
#

the body falls off

polar acorn
steel hull
polar acorn
fickle plume
#

@steel hull What tutorial are you following?

steel hull
#

this is the video

#

wait the video is coming

#

guys thank you all but I don't have much time

steep rose
#

you need to lock the X Y Z on rigidbody

cosmic quail
# steel hull

are u combining character controller with a rigidbody. thats bad

steep rose
#

using constraints

fickle plume
#

@steel hull Where do you see in the video rigidbody being added anywhere?

steel hull
#

thats why I am here

#

I am a beginner

polar acorn
fickle plume
#

It's a video about FPS controller. It doesn't interact with rigidbodies

steel hull
fickle plume
#

Do a proper course on !learn so you won't be trying to do impossible things. Where everything explained gradually.

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

modest dust
# trim hedge thanks! That worked, instead of trying to reference the grid directly in the pre...

Yes, the position will be 0 since the transform you're getting is likely the tilemap transform. I can't really think of any solution which involves using the tilemap, but an alternative you can try is making the ladders into separate gameobjects with regular SpriteRenderers. Then their x position would be your players centering position. Another thing you might want to consider are raycasts, which return a RaycastHit2D which has a point property which you could possibly convert from world position to grid coords and back to centered position.

trim hedge
hallow sun
#

is it more efficient to Resource.Load<Sprite> or to use a List<Sprite>?
this is for a pointer to the next target

devout valley
#

hello. ive been trying for a long time to blend two tutorials basically. ive finished one tutorial on a 3rd person character movement using enum states and input actions asset. however im trying to add a new action and its proving very difficult. im trying to add a dash. i planned to just take the inputx and input y and use a second tutorial on how to add dashing into your unity game its proving very difficult to mix the two as im not fully familiar with everything that was done in the third person movement controller as i am still pretty new to game development.

3rd person controller tutorial : https://www.youtube.com/watch?v=otqmsZmP4ZI&t=5s

Dashing tutorial : https://www.youtube.com/watch?v=vTNWUbGkZ58

player locomotion : https://pastecode.io/s/kx5x5wbs

player controller : https://pastecode.io/s/59y633v1

In part 3 of this series, we go through jumping mechanics and animations. This includes distinct jumping and falling states with explicit transitions to allow for dynamic scene interaction.

In this series, I'll be going over beginner through advanced topics for building a complete player controller, both for 1st and 3rd person. We'll covers top...

▶ Play video

ThirdPersonMovement.cs - http://www.mediafire.com/file/brnb40r95hvxgna/ThirdPersonMovement.cs/file
Brackey's Third Person Tutorial - https://www.youtube.com/watch?v=4HpC--2iowE&t=1081s

This video, i will show you the simplest way to to Dash in a 3D game using Unity 2020. I will be using the Character Controller component to perform the dash sin...

▶ Play video
worthy tundra
#

every day is a new opportunity to re-invent the wheel

devout valley
worthy tundra
devout valley
#

oh oh alr

worthy tundra
#

making a fsm rn

devout valley
#

ah fair play

#

im so stuck this is awful

#

lol

raw token
cosmic quail
eternal needle
#

Resources is worse yes for performance but its something you really do once at the start.
You cant really compare it to a list though, as you still need to populate this list somehow

summer stump
#

Trading a performance cost for development convenience is sometimes a worthwhile choice

Especially for a one time cost

wintry quarry
#

In fact we make that tradeoff all the time by writing code in high level languages instead of assembly

summer stump
#

Very good point

hallow sun
#

oh no, its not a one time thing.
this pointer shows the direction and icon of the closest NPC, so it would do this several times depending on the player's movement

#

i think ill stick with the List for this

summer stump
#

Then you cache the return value

#

You would do resources WITH the list

#

The real question is inspector references vs resources. Not list vs resources
(Also there is Addressables)

drowsy flare
#

Is there any way to set an order or priority of how objects are started in a scene? I would like the void Start() of a certain object to be before another.

#

Is this a use-case for Awake() ?

polar acorn
#

Yes

#

Put the thing you want to happen first in Awake

wintry quarry
drowsy flare
#

Okay, thanks guys

#

I'll have a look at OnEnable too, cheers!

high totem
#

how do i detect if debug mode is enabled in the unity editor via code? I figured it would just be

#if DEBUG but it seems DEBUG is always defined even if you have debug mode toggled off in the unity editor

#

Is there a preprocessor for this at all?

#

i guess not

#

interesting

raw token
slender nymph
high totem
past cloud
#

hey, im using visual studio as me IDE, and up until now its been working fine, but today when i went into it its not working properly, anyone know what might be causing it

slender nymph
#

regenerate project files and restart it, if it still isn't working make sure it is actually configured. there have been some instances of the external tools setting in unity being reset so make sure that hasn't happened

past cloud
slender nymph
#

show your external tools settings, the package in the package manager, and the workload in the vs installer

#

actually before all that, just screenshot your entire IDE window with the solution explorer visible

slender nymph
#

right click the project in the solution explorer and select Reload With Dependencies

past cloud
#

what was the issue? so i can avoid it in the future

slender nymph
#

the project simply wasn't loaded. there's nothing to "avoid" it doesn't typically happen, but if it does you just reload it

#

regenerating project files and restarting should have also reloaded it, but sometimes that extra button click is what you need 🤷‍♂️

devout valley
#

https://pastecode.io/s/cimx9w5w

https://pastecode.io/s/uz7s83d3

apparently "isRotatingToTargetHash does not exist in the current context" but im pretty sure its supposed to be fine? ive called it from the player controller script and ive set it the exact same as the others. its referenced at the top with a string to stringhash like i did with the rest of them?? whats wrong

tranquil hollow
raw token
steep rose
polar acorn
rocky canyon
#
   public bool Loop = true;
    bool firstStart = true;

    private void OnEnable()
    {
        if (Loop && !firstStart)
        {
            Debug.Log("Test a function only once");
        }
    }

    private void Start()
    {
        if (Loop)
        {
            firstStart = false;
            this.enabled = false;
        }
    }``` heres a fun one.. found an old script i wrote when i *FIRST* start learning.. lol its a debug button (click the enable button on the script to call the function)
steel stirrup
#

How do I force a serialized unity event to actually use the value it's being invoked with rather than whatever nonsense is in the inspector (and ideally remove the parameter from the inspector entirely)? ie ```
[SerializeField] public UnityEvent<bool> OnEnter;
public void OnPointerEnter(PointerEventData eventData)
{
var b = true;
Debug.Log("Pointer Enter: " + b);
OnEnter?.Invoke(b);
}

    public void OnPointerExit(PointerEventData eventData)
    {
        OnEnter?.Invoke(false);
    }``` when tested the OnEnter does not actually pass 'b' but instead whatever the checkbox in the inspector is set to

EDIT: For anyone similarly annoyed, check the method dropdown in the inspector and check it isn't using static, which seems to completely disregard inputs without any warning.

rocky canyon
rocky canyon
#

if u (reset) ur script in teh inspector it'll go back to the original values

rocky canyon
steel stirrup
#

I don't have 'original' values, I just want it to behave like a normal C# event and be completely dynamic

steel stirrup
full kernel
steel stirrup
rocky canyon
#

theres a way to do this i cant remmeber tho..

#
    [SerializeField] private UnityEvent<bool> onEnterUnityEvent;

    public event UnityAction<bool> OnEnter;```
#

something like this maybe?

steel stirrup
#

No you just swap the method reference in the inspector

#

dynamic will respect the input, static just uses whatevers in the inspector

rocky canyon
#

[SerializeField] private UnityEvent<bool> onEnterUnityEvent; would using private serialized change the result any?

steel stirrup
#

that's just scoping, it shouldn't affect anything

rocky canyon
#

ahh ur right ur right

#

events outside my comfort zone.. but i need to learn them. so thats why im even replying lol.

#

but i understand the issue now, that was more than when i first read it

#

Unfortunately, Unity's inspector doesn't allow you to completely hide parameters for UnityEvent methods while still keeping the event exposed. However, the dynamic method selection in the inspector solves your main issue.

steel stirrup
#

I just use a wrapper for vanilla C# events whenever possible, so this is the first time in ~10 years this has come up

rocky canyon
#

yea, thats all i got from the threads im lookin at lol not really a often asked question i suppose

#

or i cant word it corrrectly

steel stirrup
#

Yes, if you select dynamic you won't see the parameter in the inspector (since it's being set when invoked)

rocky canyon
#

i'll remmeber that. ive never used the inspector to pass thru variables..

#

can'y you only pass 1 parameter via the inspector?

#

ahh, its a design choice

cosmic dagger
rocky canyon
#

ive never heard the term "vanilla c#" until just now

#

i kinda dig it 😄

#

w/o unity's ~~api ~~ library/namespaces i cant code c# soo..

#

lol ¯_(ツ)_/¯

cosmic dagger
#

Custom Unity events can have multiple parameters, but as mentioned, you won't see those . . .

rocky canyon
rich adder
rocky canyon
#

imo unity events in the inspector are clutter-some af

cosmic dagger
rich adder
#

i just call them c# events vs Unity events

rocky canyon
#

aye, ive heard POCO befor.. i avoid using it cuz ppl reply wdym

rocky canyon
steel stirrup
#

No

rich adder
#

UnityAction is similiar to c# action

#

UnityEvent is specific to inspector/unitys event manager or whatever it is

cosmic dagger
# rocky canyon

I agree. I have a ton of custom events for some things. You can clump them under an arrow with custom inspector/attribute . . .

full kernel
#

Unity events are serializable, which has a lot more powerful implications than your standard C# event

rich adder
#

I mean is just they show up in inspector

#

not extra benefits there

full kernel
steel stirrup
#

UnityEvent is handy (especially for UI) because it's extensible and shows up in the inspector. But iirc performance was (at least at some point) worse than C# events, and showing up in the inspector is a pretty major double edged sword to begin with (though obviously can be avoided with an attribute)

rich adder
#

only for designers or assets

#

I dont personally like using the inspector for events

cosmic dagger
rich adder
#

You can't tell which objects are listenting to event, its messy

full kernel
#

Serialization allows things to appear in the inspector...But the main purpose of serialization isn't just to make things appear in the inspector. There's much deeper implications to the power of serialization

rocky canyon
rich adder
#

I know there is benefits to serialization duh 😛

steel stirrup
rocky canyon
#

lol.. ya, the beginner response is "they expose things in the editor"

#

but we all know they're much more.. serialization just the word gives it away

rocky canyon
rich adder
#

"organize this textfile" 😛

rocky canyon
#

and they taught me w/ UnityEvents for some reaosn

steel stirrup
#

Ultimately, everyone should probably just learn all of it at some point, but UnityEvent is probably more useful for people who want to stay in the unity ecosystem and especially those who tend to handle data through the unity editor

rich adder
#

the decent part about UnityEvent they can also be listened in code directly so you dont have to use the inspector (dealing with the UI events like OnClick)

steel stirrup
rich adder
#

isn't that what I said?

#

I mean you can use AddListener

steel stirrup
#

thought you were implying it couldn't

rocky canyon
#

one thing im missing in this script is.. i have Add/RemoveListener

rich adder
#

naaa . My designer friends like those inspector goodness though

rocky canyon
#

but normally im used to seeing += and -=

cosmic dagger
cosmic dagger
rocky canyon
#

he wanted everything in the inspector 🤮

steel stirrup
#

I think a lot of tutorials push people towards using the inspector and scriptable objects to hold data just to get things done quickly

rocky canyon
#

theres gotta be more to it..

#

that seems sloppy.. but who am i to say..

steel stirrup
#

I still have never encountered an actual use case for it in all honesty

rocky canyon
#

anytime ive used a ScriptableObject.. its directly referenced via the script anyways

steel stirrup
#

I prefer to keep data in csvs loaded from streamingassets

mighty goblet
#

hey, ive been struggling to fix my player movement, my player keeps getting dragged and moves by itself a lot. This happened after i added in an animator cutscene and im not sure why, anyone got any suggestions ?

full kernel
#

The inspector is there to help design your game, and being able to control how events are hooked up in the inspector rather than hard-coding it is actually a pretty nifty way to handle dependency inversion/injection

rocky canyon
#

gets the job done ¯_(ツ)_/¯

eternal falconBOT
rich adder
#

whats handy about UnityEvent though is the same drawback it has, you dont have to modify 3-4 scripts to listen to event. If you need to interact with specific components without adding so many references. Good for quick prototype but in the long run..

steel stirrup
#

UnityEvent has its place, for ui its about as good as it gets honestly. Saves needing to make tiny scripts for every little thing

rich adder
#

I just put it all in UIManager 😛

rocky canyon
steel stirrup
#

I've just had enough bad experiences with the inspector losing references on older versions of unity that I don't trust it to hold anything important

#

Back with the old unity collab it felt like every pull had a 50/50 shot of some random prefab disintegrating

rich adder
#

also noticed the invoke order doesnt seem to be specific order ?

toxic yacht
#

Ive been using unityevents for message brokers. Like I'll have a Hittable component that has an OnHit unity event. Then I can hook up the listeners for any specific hittable object in the inspector. And then stuff that I don't need to think about when I'm not in code, like an enemy manager listening to all of the instantiated enemies' OnDeath event, I'll use c# Actions for.

rocky canyon
#

soo. private all the way.. or i tend to use [ReadOnly] alot now

steel stirrup
rich adder
mighty goblet
rocky canyon
rich adder
steel stirrup
#

yeah just put the code on hatebin or whatever and post the link here

dire flare
#

Am stuck pls I need help .
How do I shoot in unity I want to understand not to copy and paste any book or guide

rocky canyon
#

attn Hatebin has a 50% success rate

rich adder
rocky canyon
#

but remmeber to remove em all b4 build day

#

or i guess the stacktrace w/ a normal debug would be enough

mighty goblet
summer stump
steel stirrup
rocky canyon
steel stirrup
rich adder
rocky canyon
#

even this.. i forget this thing exists everysingle time

mighty goblet
steel stirrup
rocky canyon
rocky canyon
rich adder
#

imagine putting around every debug.log

rocky canyon
#

ahh nah, nvm thats not similar at all..cuz those would still be there.. just ignored.. or do they get stripped out?

rocky canyon
steel stirrup
#

editor classes don't get included in builds at all iirc?

rich adder
#

naw

rocky canyon
#

ya editor classes excluded irrc

rich adder
#

I think the whole assembly gets excluded

rocky canyon
#

yea, everything within an Editor folder gets droppped

steel stirrup
#

if you wanted to keep it when compiled you'd use Application.isEditor or something like that

#

though i'm not sure why you'd ever do that

rocky canyon
#
// Editor-only code here
#endif``` do too apparently
steel stirrup
#

anything with #if is a directive

rich adder
rocky canyon
steel stirrup
#

now go learn C# action/func/pred UnityChanwow

rich adder
#

delagate

steel stirrup
#

I really, really wish that the big tutorial channels/educators would focus more on teaching delegates

#

they're so incredibly useful

#

but most self taught programmers seem to not even know they exist

rocky canyon
#

ohh delegate* lol

rocky canyon
#

delegates are OP

rich adder
#

the 👁️ pattern

rocky canyon
#

ehh, i should probably avoid classes named Action then i guess 🫣
edit - welp, time to refactor some stuff real quick

rich adder
#

using Action = System

steel stirrup
# rich adder https://learn.unity.com/tutorial/delegates

See, my issue with that is that, like most info on the subject, it focuses on delegate itself. Obviously foundational knowledge, but pretty rough as an entry and with tricky'ish syntax. I've found it's much easier to get people started with Action

steel stirrup
queen adder
rich adder
#

they expect you to kinda know all this

steel stirrup
#

delegates are one of those areas where i think it's most helpful to work backwards honestly

rocky canyon
steel stirrup
#

and understanding predicate is really helpful for using linq

rocky canyon
steel stirrup
#

or setting up your own extensions

rich adder
rocky canyon
steel stirrup
#

linq is my god

#

it's also probably singlehandedly responsible for 90% of my cpu time

queen adder
#

Linq is good but it creates a lot of garbage and garbage is an enemy for game developers

rich adder
steel stirrup
#

new syntax?

rich adder
queen adder
#

Naa it already creates it's first garbage on conversion of IEnumerable > XXX.Enumerator

steel stirrup
#

It doesn't really matter 99% of the time, and it's easy to just convert everything away from linq when you're done and ready to optimize

rich adder
steel stirrup
#

ohhh

rich adder
#

I shoudn't say "verbose" but too much close to english, me no likey

steel stirrup
#

wasn't that to make it close to some database query or something

rich adder
#

feels pythony

rocky canyon
eternal needle
queen adder
rich adder
#

yeah its like SQL or any other weird query lang

#

ill keep my . chains thank you very much

steel stirrup
rocky canyon
#

not quite the same..

rich adder
steel stirrup
rocky canyon
eternal needle
final arrow
#

can someone please help with hand coding😭 the hands on the character is funky

steel stirrup
rich adder
steel stirrup
#

try making a console to control your project

rocky canyon
#

oh like dis?

steel stirrup
queen adder
mighty goblet
#

is that fine

rocky canyon
rich adder
mighty goblet
#

oki

steel stirrup
mighty goblet
#

one mine then itll show the dragging n automoving

rocky canyon
rocky canyon
steel stirrup
rocky canyon
#

i believe my static commands do use reflection

#

but the shell part was robbed from a github

mighty goblet
#

this is all i could send cuz of the limit

rocky canyon
#

weird.. theres a huge limit here.. 100mb + ircc

mighty goblet
#

mine says 50 mb limit

rocky canyon
# mighty goblet

alrighty. now explain. what is it that u wish to happen.. whats not happening.. and what are we lookin at

mighty goblet
#

the first 5 secs is automoving

rich adder
mighty goblet
#

second five is when i tried moving right its like somethings blocking me from doing so

steel stirrup
#

I love streamable so much

rich adder
#

check the velocity

#

you can also use physics debugger

#

see if there are colliders or anything there ?

mighty goblet
#

ill check now

mighty goblet
#

havent used debugger before, is that okay?

#

also another separate issue ive been having is i cant start a timeline, like i press play with a component in and it doesnt run at all , even as a preview

rich adder
mighty goblet
#

the clip is with the drag thing like preventing me from going right and left

#

i can show the normal movement and how its meant to look if thatll help

steep rose
#

are you limiting speed in any way?

mighty goblet
#

before i made my cutscene it worked smoothly, but after it, its been like that

steep rose
#

can we see some movement code

rich adder
#

the rigidbody is probably fighting the transforms with the animator

steep rose
#

or any code that affects velocity

mighty goblet
#

maybe

mighty goblet
#

ill check

steep rose
#

well your movement code should affect some sort of movement

mighty goblet
#

!code

eternal falconBOT
mighty goblet
#

forgot to save as C# for that ^

rich adder
#

transform.rotation * new Vector3 🤔

steep rose
#

this is a different way to apply movement to a rigidbody 😅

mighty goblet
#

first unity project

steep rose
#

you are not in trouble or anything lol

mighty goblet
#

looool

mighty goblet
mighty goblet
ivory bobcat
#

Can you show the inspector for the object when it's misbehaving?

mighty goblet
#

i fixed it

#

was the dumbest thing aswell oops

#

now just need to get my timeline to work

rich adder
mighty goblet
#

i had a tester world with x and z ticked n movement worked there

#

did the same for this n it works now

graceful crystal
#

anyone know the visual studio shortcut key that turns my mouse into a yellow block that replaces writing

#

really bugging me

graceful crystal
#

yes thank you

#

spent 10 minutes seaching all visual studio shortcuts

summer stump
#

It is from the operating system itself

graceful crystal
#

probably why i couldnt find it then

cosmic dagger
rocky canyon
#

those are the cases i think ive heard to avoid lol

#

but who knows.. the misinformation is real sometimes

#

can you do Class : SO, MonoBehaviour ?

cosmic dagger
#

nah . . .

dusky quartz
#

hello everyone, so im trying make obstacle on tilemap, already use tilemap collider and still not working

rocky canyon
#

whats not working? the code?

dusky quartz
#

im still can pass obstacle

cosmic dagger
#

it's how other systems can talk to it without needing a dependency . . .

rocky canyon
#

ya, i mean it makes sense.. i myself cant see nothing wrong with it.. i might think of that for my own purposes now.. at some point in my journey lol

cosmic dagger
#

you've done a lot of things though. bits of pieces here and there that add up . . .

rocky canyon
#

im debating on whether this code related.. or belong somewehre else

dusky quartz
rocky canyon
#

how do you move the player??

summer stump
dusky quartz
carmine lagoon
#

I just wanna ask. I have a "private transform target" in a detection tower and I wanna use it as a reference so that another game object can target the object that is called, specifically an enemy. Do i just change it and call it like public transform target and declare it on the other game object??

dusky quartz
rocky canyon
#

!code what moves ur player

eternal falconBOT
rocky canyon
#

is it transform.position = .. aka translation..

summer stump
rocky canyon
#
  • does it have a rigidbody?
  • should it?
    .. just a few questions that eventually need answered..
summer stump
rocky canyon
#

just show the code and we'll know most of it

dusky quartz
#

aight wait

cosmic dagger
carmine lagoon
#

then use getcomponent?

cosmic dagger
#

no, no, no . . .

#

create a property called Target with a get accessor that returns your private field . . .

#

then you need to figure out how to reference the script to access the property (using the link from Aethenosity) . . .

carmine lagoon
#

okay okayyy, thanks

dusky quartz
solemn fractal
#

hey guys. I have 2 scripts in one object I have. The second one. WaveController. I thought that just creating like Private WaveController _waveController, I wouild be able to have access to it as it is already inside the object. But it is giving me null execption. If I turn it into serialized.. I cant drag the script into the field on inspector.. what is the fix for that? Thank you

dusky quartz
steep rose
solemn fractal
#

it doesnt. I removed the serialized and I am using on Awake cs _waveController = GetComponent<WaveController>();

#

and its working now

summer stump
carmine lagoon
summer stump
#

Nevermind pedro. I see

solemn fractal
carmine lagoon
cosmic dagger
carmine lagoon
#

is that how it works?

solemn fractal
#

!code

eternal falconBOT
oblique gale
#

I don't really understand? why can't I change the transform of the viewport of a scrollview???

solemn fractal
#

Hey guys.. I have 2 classes. 1 - WaveController, 2 - TimeController. Inside wave controler i checked with Debuglog, and time is always starting at 0 and working fine.. but the game is going inside my IF statement where it says time need to be greater or iqual to 120 already at the start of the game. What could it be. ```cs if (_timeController.elapsedTimeGet >= _addTwoMinutes){}{
_waveCount++;
_addTwoMinutes += 120;

    }``` Full 2 classes code https://paste.ofcode.org/XDG9gDYYjrsjrGEec6SNAa
solemn fractal
#

wdym?

solemn fractal
# rich adder wdym you always start with 120

_addTwoMinutes I always start as 120, but the if says if the time is greater than 120 go inside the if. and the time starts at 0.. so it should not go inside it until the time is 120.

rich adder
#

where are you checking elapsedTime value

solid lark
solemn fractal
#

debug.log for _timeController.elapsedTimeGet, it shows correct the time starts at 0 and it goes up normally as time should workl. Debug.log for _waveCount++; and it increased like crazy since the start of the game as well _addTwoMinutes, and the only place they are incremented is inside the IF

solid lark
#

Can you possibly send a screen shot of the whole function?

solemn fractal
solid lark
#

Oh i see your issue

#

The issue is the brackets

#

you're doing
if(){} {}

solemn fractal
#

omg

solid lark
#

remove one set of brackets

solemn fractal
#

I didnt see that

rich adder
#

oh wow

solemn fractal
#

hahahaha

solid lark
#

Lol

solemn fractal
#

now it works hahahaha

rich adder
#

not a fan of that style of brackets

solid lark
carmine lagoon
#

yea... programming things lol

solemn fractal
rich adder
#

the c# standard tbh

solid lark
rich adder
#

{
//
}

carmine lagoon
#

i do it like this
if
{
}

solemn fractal
summer stump
rich adder
#

do whatever is comfortable for you

solemn fractal
solid lark
#

They are much more compact like this

void HelloWorld() {

}

mint remnant
carmine lagoon
rich adder
summer stump
#

Just basic dot notation

carmine lagoon
#

thanks~

carmine lagoon
summer stump
#

But if I am right about what you mean, yeah, other objects need the reference to the class instance

#

If you are calling it from INSIDE that class, just write Target

solid lark
#

you can just use target

carmine lagoon
# summer stump I dunno what you are asking

ohh wait. so basically the code I sent is like a detection tower. I wanted to use the target within the code so that it can be called out in the other game object(basically which shoots the target). That's why they told me to make a get property.

summer stump
solid lark
#

I see that

summer stump
# solid lark I see that

You don't ever want to directly reference the backing field
If you go modify the behavior of the getter or setter, you would have to change a lot of code in the future
It is the whole point of making it a property

solid lark
rich adder
#

so that it is only modified within that script

summer stump
rich adder
#

the getter is public

#

the backing field is private so it can only be changed in that script

summer stump
#

Looks like the setter is too

rich adder
#

yeah in this case they (OP) fdup the point of props

summer stump
#

Could just be an autoprop

solid lark
rich adder
#

yea but I think the point here to find it at runtime not set in inspector

summer stump
solid lark
#

Ohhh, I think I missunderstood the issue

#

I understand now

summer stump
#

Yeah, for just the inspector, may as well do a serialized private

rich adder
#

no clue how they wrote this whole script without knowing how to access it from another script 😅

solid lark
#

I didnt know he was trying to get the value from another script

summer stump
#

Honestly, I wasn't sure at first either haha

graceful crystal
#

anyone know how i would get this to actually show up green

eternal falconBOT
cosmic dagger
# solemn fractal

You're repeating the exact same code. Just call ResetTime in Start . . .

carmine lagoon
rich adder
carmine lagoon
#

so i'm learning everything rn

summer stump
#

Then !learn after

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

summer stump
#

The junior programmer pathway specifically

carmine lagoon
#

thank you guys

cosmic dagger
#

Honestly, I watched the Unity beginner and intermediate tutorials, read RB Whitaker's C# tutorials, and was good to go

As long as you follow along and manually write the code yourself, you'll understand the concepts and terms . . .

mint remnant
#

why would you not use an event system for a timer functionality?

solid lark
#

You can save performance

summer stump
teal viper
mint remnant
#

just curious why you and nav reacted with not like this

summer stump
#

At least for me. Not gonna speak for nav

mint remnant
#

oh is he bad to reccomend?

summer stump
rich adder
#

not a fan of the videos

mint remnant
#

I tend to watch them all, glean the good stuff and reject the bad stuff

rich adder
#

being passed off as "clean code" when its not

#

its all over the place if you ask me, but clearly it works for them so whatevs

mint remnant
#

ok fair enough, just thought the idea of a timer on events was somehow bad

rich adder
#

nothing wrong with timers and events

summer stump
#

Not bad, but certainly a new level of knowledge I don't want to get into. I generally try to fix what someone has, not completely recommend a different method (unless it is REALLY called for, which, sometimes it is)

mint remnant
#

ok, was more thinking hey if you want to try expanding your horizons, try this next

solemn fractal
#

hey guys. I have a simple code here. I have 2 objects.. both with circle collider 2d.. both with rigidbody 2d Dynamic. One is the bullet the other the enemy. I am just trying first to achieve a simple task. My enemy class name is CircleEnemy and the bullet class is PlayerBullet. Both have tags with the same name of the class. In the bullet script I just have that: private void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("CircleEnemy")){ Destroy(this.gameObject); } } The bullet hits the enemy and bounces instead of being destroyed. What Am I missing here?

mint remnant
#

Destroy(this.gameObject); destroys hte current object that script is on

solemn fractal
#

exactly.. it should destroy the PlayerBullet

#

But it doesnt.. and the script is on the PlayerBullet.

#

    private int _playerBulletSpeed = 2;
    private int _playerBulletDamange = 1;


    void Start(){
        
    }

    void Update(){
        
    }

    private void OnTriggerEnter2D(Collider2D other) {
        if (other.CompareTag("CircleEnemy")){
            Destroy(this.gameObject);
        }
    }```
mint remnant
#

read up on what "this" keyword means

#

oh you are trying to destroy the bullet

solemn fractal
#

exactly

#

but the bullet bounces

#

instead of being destroyed

mint remnant
#

perhaps you want other.collider?

solemn fractal
#

I have another game that I made and it works there, i just did the same.. there works but here not. I am missing something I cant find

summer stump
devout flower
summer stump
devout flower
#

Instead of trigger (depending on the collider settings)

solemn fractal
#

AHH YEAH that is it.. the isTrigger is not ticket.. let me test .. that should be the problem

#

yes that was the issue. Thank you. I forgot completly about that

summer stump
#

If you would rather it not be a trigger, then iLikePizza's suggestion is best

solemn fractal
#

Got it, thank you guys.

mint remnant
#

Litterally, you can't put too many debug logs in your code, they only help you, comment them out after resolved, leave them hang around a while, remove them later when you are thoroughly convinced you understand the issue

solemn fractal
#

True.. OnCollisionEnter, I do not need to check for Tags correct?

#

It just fires whenever .. or whatever it collides with a collider i imagine.. that will be more random.. trigger is more specific.

summer stump
#

The only difference is that it would be for neither object being a trigger

solemn fractal
#

becase CompareTag is not allowing me to check with OnCollisionEnter2D

summer stump
rich adder
#

are you sure you're not trying to do it on Collision type?

summer stump
#

Simply have to access the collider from the collision struct

solemn fractal
rich adder
#

yeah you're trying to do it from Collision type

summer stump
solemn fractal
#

Yeah, ok thank you!!

rich adder
#
if(other.TryGetComponent(out PlayerBullet playerBullet))
...
playerBullet.stuff
etc..```
#

no need for tags

solemn fractal
#

Got it, thank you!! ❤️

rich adder
#

btw Destroy (playerBullet) you're only destroying the component not the gameobject

solemn fractal
#

Destroy(playerBullet.gameObject);
Just corrected

#

Thank you.

frigid schooner
#

hello I saw this one video about this guy making a game that deletes itself when you die, just curious how would you do it? I would like to try / understand how he did it, because from what I know, it is not possible to delete an application that is running, but you need it to be running in order to detect deaths and activate the script that deletes the game
https://www.youtube.com/watch?v=nIdO1Z8mD7Q 9:22

wintry quarry
timid quartz
#

I can't seem to get my 2d collisions to report. here's a screenshot showing the code, the project settings showing that the layer collides with itself, and the collider2d and rigidbody 2d settings.

#

ah, just realized I am comparing tags and looking at layers, but even after fixing that no dice unfortunately

solemn fractal
#

Hey guys. More newbie questions for you. In my past game I used scriptable object to manage my enemies Damage and Health. Worked fine.. Now I am trying different ways to see if that works too. I have this code for the EnemyHealth where it says if the enemy health is 0 or less he will be destroyed. It is working fine. But the issue is. I am using it on 2 dif enemy prefabs. So when I hit the first enemy all the other enemies in the screen that were already instantiated will be 0 HP too. Is that a way to fix that simple or I really need to use scriptable object to achieve that? https://paste.ofcode.org/SaADfF2peHfRCi3vQiVwEv

summer stump
#

Treat scriptable objects as immutable

solemn fractal
#

I used for my past game worked like a charm even tho prob is not the correct way. But I hated to use scriptable objects to be honest and I was trying a more direct simple way.

summer stump
#

Show EnemyHealth component

timid quartz
#

correct

#

it should print twice, even, since I am dragging these over themselves

solemn fractal
summer stump
rich adder
wintry quarry
timid quartz
#

because I am dragging and dropping UI elements within the canvas, they are hitting each other in theory

#

imagine a MMO hotbar, I am building the "drag to another ability to swap" part of that

rich adder
#

you should not be using colliders / physics in UI

#

use EventSystem n such

wintry quarry
#

That's not right at all

timid quartz
#

I wasn't aware there was another way

summer stump
#

That is an.... interesting name for health

wintry quarry
solemn fractal
summer stump
timid quartz
#

I am actually using event triggers for drag/drop stuff

#

how would I check if I am hovering over the right place though if I don't check for collisions?

solemn fractal
wintry quarry
rich adder
summer stump
timid quartz
#

Ok, I'll give that a try, thank you!

wintry quarry
solemn fractal
#

Ignore that name that is there now.

#

public int enemyHealthGetSet{ get { return _enemyHealth; } set { _enemyHealth = value; } }

summer stump
#

I believe that is the issue.

#

See what happens when you comment out that line

solemn fractal
#

I am not using this Get set anywhere for now.. just commented nothing happened. I am controlling the lost of health in the same script..