#💻┃code-beginner

1 messages · Page 690 of 1

sonic arch
#

i verified from within the script using
this == array[x,y]

naive pawn
#

from within what script?

sonic arch
#

within the plant script itself

#

in the method that sets its position

#

and then ive just tested this within addplant

#

they are not equal>

#

even after just assigning it

naive pawn
#

oh it's unity equality there

#

should still work for the same object though

wooden hill
naive pawn
#

oh damn

hidden marten
#

the pivot is my enemy.transform, 1 endpoint is where my enemy is facing (transform.forward) and the other is where my player is....(sorry for not mentioning) i want to animate the enemy to face my player when the angle is higher than 30 degress

sonic arch
#

so thats true

wooden hill
sonic arch
#

omd so they are the same

#

but the fields are still unset

naive pawn
#

if you want to also account for vertical displacement i think you'd have to get the normal of the plane formed by the vectors? that's be Vector3.Cross(vectorToPlayer, transform.forward)

hidden marten
naive pawn
#

yes, i'm not saying to use Cross directly as the angle

#

the cross product gets you a vector that's perpendicular to both other vectors, i'm saying to use that as the axis of rotation in SignedAngle

naive pawn
#

you can omit the axis altogether with that

hidden marten
#

i want to ignore the y displacement... i want the angle in just the x-z plane... i want the angle to be the same no matter where the player is vertically... so can i use angle for that?

naive pawn
#

i also want it to work when the player is higher or lower than the enemy.
so.. what's up with that then

round glade
hidden marten
naive pawn
naive pawn
hidden marten
naive pawn
#

@round glade you've been told already where and how to ask for help. put some effort in

round glade
#

I asked someone not whole chat

rich ice
naive pawn
hidden marten
naive pawn
#

thonk maybe im misunderstanding the axis, one sec

#

ok yeah signedangle is already on the plane of the 3 inputs, the axis just determines the direction

#

you'll have to project the inputs onto the same plane or zero out the y component of the inputs

hidden marten
#

it works perfectly... thanks a lot!!!

naive pawn
#

also footnote on the vectorToPlayer, you can do b - a instead of -(a - b)

hidden marten
wet monolith
#

i am using unity's new input system
is there a way to check when button is released if my playerinput component has behaviour set to send messages

sonic arch
naive pawn
naive pawn
sonic arch
#

oh wati thats legit the same as what im alrady doing nevermind

wet monolith
fickle plume
#

@wise quartz !collab

eternal falconBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
Collaboration & Jobs

tight fossil
#

how can I add a number of int variables into a list or array?

slender nymph
#

could you be more specific about what you mean by that? because adding something to a list is literally as easy as calling the Add method on the list

sonic arch
#

omd all this time it was because i had both the parent and child class attached to the gameobject omd 😭 thx guys

tight fossil
#

if i have 18 ints, and I want to add them all to a list, how would i go about doing so? i assume theres a simpler method than just .Add 18 times

eager elm
#

AddRange()

slender nymph
tight fossil
#

each int is for the difficulty of a separate enemy, and yes all 18 of them are different and exist independent of each other.

polar acorn
#

Do you have a list of the enemies?

tight fossil
#

also how do i make AddRange work in this context it only takes one argument so I can't just feed it all 18 ints

slender nymph
#

AddRange is not the solution to this

tight fossil
#

well then

slender nymph
#

what is the actual purpose of putting these ints into a list like this? it seems like there is definitely a better way to go about whatever it is you are actually trying to accomplish

polar acorn
#

Where are the numbers coming from? Is there a list of enemies?

#

Do you just need to basically convert "List of enemies" into "List of difficulties"

tight fossil
#

its fine i solved it, just used a loop ofr it

#

removed the 18 variables

slender nymph
#

you should give https://xyproblem.info a read because this is absolutely an XY Problem and whatever you are doing can absolutely be done in a better way

naive pawn
#

well, if you ever worry about your naming...
fun fact, inputsystem has interfaces IInputActionCollection and IInputActionCollection2

stone gulch
#

i'm completly new to unity and i heard about "tutorial hell" so i'm afriad to watch tutorials, what do i do?

naive pawn
#

tutorial hell isn't watching tutorials

#

tutorial hell is solely relying on copying tutorials and not actually learning

polar acorn
dim yew
#

what are += and -= in relation to void statements? ie. Position.OnValueChanged -= OnStateChanged;

naive pawn
#

what you have there is adding or removing delegates

#

OnValueChanged is some delegate, probably an Action or UnityEvent
+= basically subscribes to an event, -= removes the subscription

dim yew
#

and thanks, i'm not privy on events either

naive pawn
# dim yew what are += and -= in relation to void statements? ie. `Position.OnValueChanged ...
acoustic belfry
#

hey, im having a problem and i dont know why
for a weird reason my second enemy doesnt die when health is less than zero, yet my first enemy does, why this happens?

this works

    {
        enemyCry(trooperhurt1, trooperhurt2, trooperhurt3, audioSource, 1f, 1.5f);
        currentState = MortemState.Pain;
        health -= damage;
        if (health <= 0)
        {
            mortemExplode(RifleRoto, transform, attackposition, 3);
            moon.comboReload();
            Destroy(gameObject);
            int cantidadPoints = Random.Range(cantidadminpoints, cantidadmaxpoints);
            for (int i = 0; i < cantidadPoints; i++)
            {
                mortemExplode(RifleBulletspointPrefab, transform, attackposition, BlastForce);
            }
        }
    }```

this not
```    public override void TakeDamage(float damage, int type, float pushForce, float BlastForce, Transform attackposition)
    {
        enemyCry(sargenthurt1, sargenthurt2, sargenthurt3, audioSource, 1f, 1.5f);
        currentState = MortemState.Pain;
        health -= damage;
        if (health <= 0)
        {
            mortemExplode(RifleRoto, transform, attackposition, 3);
            moon.comboReload();
            Destroy(gameObject);
            int cantidadPoints = Random.Range(cantidadminpoints, cantidadmaxpoints);
            for (int i = 0; i < cantidadPoints; i++)
            {
                mortemExplode(RifleBulletspointPrefab, transform, attackposition, BlastForce);
            }
        }
    }```
#

health goes minus, i dont know why

hallow sun
#

are there any errors on the log?

#

maybe one of the lines in between health -= damage and Destroy() is failing so the code stops

acoustic belfry
hallow sun
#

also make sure the script on the object is the correct one, maybe it has BaseEnemy instead of mortemshotgunner?

acoustic belfry
#

no, or else wouldn't even move

polar acorn
#

How about adding a log after you deal the damage?

Debug.Log($"{gameObject.name} has taken {damage} damage and is now at {health} health", this);
eternal needle
acoustic belfry
#

i added one of the kill objects to the enemy, and died

#

but this is whati find weird

#

when an enemy dies, it drops 3 prefabs

#

the one who works, only has 1 set

#

this one had none, it died when i added that one

#

why?

polar acorn
#

What does the log say on one of the ones that doesn't die when you expect it to

acoustic belfry
#

says the value "objetive" hasn't been set, but is weird, cuz is set

polar acorn
acoustic belfry
polar acorn
#

If you have an error, the function ends immediately. You need to fix that first.

acoustic belfry
#

o h

#

wait, the whole thing?

#

even if is small?

#

o h

polar acorn
#

What do you mean "is small"

acoustic belfry
#

a small prefab that will not use

polar acorn
#

If there is an error, execution halts.

acoustic belfry
#

but well, now the not-exploding enemy issue have been fixed

but now i have another, the constant error log that is making me feel confused

polar acorn
#

If something unexpected is happening and you have an error, fix the error

acoustic belfry
#

ok, but how do i fix an error i can't see

#

i mean

naive pawn
#

are you getting an error or not

acoustic belfry
#

"Objetive haven't been set" meanwhile Objetive is happily set

acoustic belfry
naive pawn
polar acorn
#

There exists at least one tuetue_script that does not have objetivo set

naive pawn
#

runtime errors are logged just the same as compiler errors in the editor

polar acorn
#

The one in your screenshot does have it set, so the error is not talking about this one

naive pawn
#

go to enemy_base:46 (which probably shouldn't be named that*) and add a debug above it, with context included, so you can find which instance has it as null
-# * types in c# are in PascalCase by convention.

acoustic belfry
#

so my game is crashing bc a mere bird doesn't have the objetive value, uh

naive pawn
#

it isn't, but some function is early-exiting

acoustic belfry
#

yeah, i select all of em, and yeah, the objetive variable wasn't equal, wich meant some didnt had it, i fixed it, now works, yey

polar acorn
acoustic belfry
polar acorn
#

There's no such thing as "small error". If there's an error, fix it.

acoustic belfry
#

makes sense

#

yeah was it, that single tuetue didnt knew where i was

#

now everything works

#

thanks

naive pawn
#

if all of them are supposed to target the single player you could probably have it be a singleton or have some other singleton provide a reference

acoustic belfry
#

yeah makes sense

#

but i mean, the player differs on scenes

#

but yeah makes sense

naive pawn
#

if you had the player as a singleton it wouldn't change per scene

#

just a design thing

keen fiber
#

How could I have procedural recoil (which I already have) with a procedural sway and walk animation? The procedural recoil and sway override themselves and the solution I found seems to be to make a ton of childs and that just got confusing real fast. I saw a post about using IK for this but I'm not too sure how to go about doing that

acoustic belfry
#

sorry for bother, but now after fixing this, for a reason i dont understand everytime i do a melee attack the game crashes, and is frustating

naive pawn
acoustic belfry
#

i dont know what i did wrong

#

oddly

naive pawn
acoustic belfry
#

this occuredd after fixing them

acoustic belfry
naive pawn
#

the error tells you what line it's happening on

acoustic belfry
#
    {
        Vector2 MacheteRange = new Vector2(attackRangeX, attackRangeY);
        Collider2D hitEnemy = Physics2D.OverlapBox(machetepos.transform.position, MacheteRange, 0f, demons);
        Collider2D hitProyectile = Physics2D.OverlapBox(machetepos.transform.position, MacheteRange, 0f, proyectile);
        if (hitEnemy != null)
        {
            if (hitEnemy.TryGetComponent(out EnemyBase enemy))
            {
                if (enemy.CanDodgeMelee == true)
                {
                    enemy.dodge();
                }
                else
                {
                    enemy.TakeDamage(meleeDamage, 0, 2, 4, machetepos.transform);
                }
            }
            if (hitProyectile.TryGetComponent(out MortemRifleProyectile enemyProyectile))
            {
                enemyProyectile.Parry();
            }
        }
        if (hitProyectile != null)
        {
            if (hitProyectile.TryGetComponent(out MortemRifleProyectile enemy))
            {
                enemy.Parry();
            }
        }
    }```
naive pawn
#

go check that line and see what could be null

acoustic belfry
acoustic belfry
#

and i checked all

#

everything should be fine

#

there's only one player

#

and all values are set

naive pawn
#

well clearly not

acoustic belfry
#

i know, but i have checked stuff

naive pawn
#

go check the error to see what line it's pointing to

acoustic belfry
#

i already did, is when does a melee attack

naive pawn
#

no, that's the method

#

see what line

acoustic belfry
#

yeah, this line

keen fiber
# naive pawn you sure this is a code question? sounds like you're asking about animation

It's sort of both. I'm wondering how I could have a procedural recoil and sway without them overriding each other but I'm also wondering about the IK part. In my recoil and sway I'm setting the result to transform.localRotation and transform.localPosition so I'm assuming that's why they're not working together but I'm not sure how to fix that without needing tons and tons of children game objects

naive pawn
#

go to your error, click the error, look at the message in the window at the bottom

#

there is a stacktrace

#

check the first line of the stacktrace, the one that's mentioning MeleeAttack
look at the end of that line, where there's a path to the file of the script

acoustic belfry
naive pawn
#

the part with :number is the line

acoustic belfry
#

or i dont get it one of both

naive pawn
#

look at the message in the window at the bottom

#

it's also telling you in the preview but the line happens to be too long

naive pawn
keen fiber
acoustic belfry
# naive pawn > look at the message in the window at the bottom

ooooh i didnt noticed that

ValeriaController.MeleeAttack (UnityEngine.Transform machetepos, System.Single attackRangeX, System.Single attackRangeY, System.Single meleeDamage) (at Assets/DaStuff/Valeria stuff/scripts/characters/valeria/valeria_playercontroller.cs:553)
ValeriaController.HandleValeriaMachete () (at Assets/DaStuff/Valeria stuff/scripts/characters/valeria/valeria_playercontroller.cs:360)
ValeriaController.Update () (at Assets/DaStuff/Valeria stuff/scripts/characters/valeria/valeria_playercontroller.cs:102)
#

is........is the same line of the method

naive pawn
#

it's pointing to line 553

acoustic belfry
#

do you mean, where the function is working?

naive pawn
naive pawn
keen fiber
acoustic belfry
#

holup

#

i think is this on

#

if (hitProyectile.TryGetComponent(out MortemRifleProyectile enemyProyectile))

naive pawn
#

is that line 553?

polar acorn
acoustic belfry
polar acorn
#

(you should absolutely turn them back on)

acoustic belfry
acoustic belfry
polar acorn
naive pawn
naive pawn
acoustic belfry
acoustic belfry
keen fiber
# naive pawn could you show an example of how you're assigning to the value (and yeah assigni...
private void SetRotation()
{
    _targetRotation = Vector3.Lerp(_targetRotation, Vector3.zero, returnSpeed * Time.deltaTime);
    _currentRotation = Vector3.Slerp(_currentRotation, _targetRotation, snappiness * 10f * Time.deltaTime);
    transform.localRotation = Quaternion.Euler(_currentRotation);
}

private void SetPosition()
{
    _targetPosition = Vector3.Lerp(_targetPosition, defaultPosition, returnSpeed * 5f * Time.deltaTime);
    _currentPosition = Vector3.Slerp(_currentPosition, _targetPosition, snappiness * 10f * Time.deltaTime);
    transform.localPosition = _currentPosition;
}

This is for the recoil, the functions run in Update()

acoustic belfry
#

im not sure cuz i havent tested, but...looks like was tring to check if the enemy was a proyectile after checking was an enemy, to wich wouldn't make sense unless it mutated into a proyectile

#

yeah, that is it

#

maybe

#

no, it wasnt

polar acorn
#

Instead of guessing, check

acoustic belfry
#

ok

polar acorn
#

Look at the line number the error is on

acoustic belfry
#

i been hovering on them like for 2 mins

#

maybe 5

naive pawn
acoustic belfry
#

but yeah

#

that was it

naive pawn
#

take that with a grain of salt though, haven't done that kind of thing before

acoustic belfry
#

i fixed it

#

thanks :3

naive pawn
#

cool, now go learn how stacktraces work for god's sake

keen fiber
acoustic belfry
#

ok ;-;

#

hey btw, where i can ask gaming questions?

naive pawn
keen fiber
#

Alright

acoustic belfry
#

i mean cuz i wonder if is funnier a proyectile or a hitscan

#

what feels more... "destructive"

naive pawn
#

i forget what the new channels are

#

go check there

acoustic belfry
#

archived?

#

ok

#

thanks :3

naive pawn
acoustic belfry
#

its ok

naive pawn
#

that doesn't even make sense, everything's a value lol

#

but yeah go learn how to read stacktraces

keen fiber
# naive pawn yeah for the quaternion, forgot to mention that

Seems like the recoil is still overriding the sway even after this. Here's how I'm assigning it now:

// Sway
transform.localRotation = Quaternion.identity;
transform.localRotation *= Quaternion.Slerp(transform.localRotation, targetRotation, speed * Time.deltaTime);

// Recoil
transform.localRotation = Quaternion.identity;
transform.localPosition = Vector3.zero;

transform.localRotation *= Quaternion.Euler(_currentRotation);
transform.localPosition += _currentPosition;
naive pawn
#

you'd have to do the reset from some central part, only once, before the effects are applied

#

here you're resetting the effect from the sway then applying the recoil

keen fiber
#

Ah

proper cloud
#

I am currently using the unity player input to detect player inputs. I am also Using UI buttons.
Is there a way to get the ui-buttons to "eat" the OnClick from the mouse? or alternatively a check weather the mouse is currently over any ui image so I can filter the player input?(this seems like a bad workaround tho)

naive pawn
#

are you using UI buttons at the same time you want to be able to.. click in the world or whatever?

proper cloud
#

yep, the ui sits around the screen, so no deactivating anything in certain situations unfortunately

naive pawn
#

and what would clicking normally do?

proper cloud
#

depends, mostly select somthing on a board

#

problem is when I press a ui-button it also does the select on the board

naive pawn
#

you end up clicking something behind the button on the board, or...?

#

and show an example there

proper cloud
#

ah, makes sense

fair dirge
#

Hey, I feel like I'm blind. Is there any documentation that explains the bindings in the input system's input map? For example the binding PrimaryTouch/TouchContact? exists but I don't seem to be able to find anything on what values it returns? I thought this could be used to detect touch contact and touch release states. I've been searching for this since yesterday and just can't seem to find anything on the input system docs that might help me find out when a touch is released. I realize I could probably do this easier with a proper c# script but I've been trying out the visual scripting graphs lately and wanted to do it that way this time

fair dirge
naive pawn
fair dirge
#

Oh thanks! I didn't have that channel yet 🙂

latent sedge
#

I know && represents and, but what represents Or?

keen fiber
# naive pawn you'd have to do the reset from some central part, only once, before the effects...

Hey, I came up with this:

using UnityEngine;

public class Combine : MonoBehaviour
{
    [SerializeField] private Sway sway;
    [SerializeField] private Recoil recoil;
    
    private void Update()
    {
        transform.localPosition = Vector3.zero;
        transform.localRotation = Quaternion.identity;
        
        sway.SetRotation();
        recoil.SetPosition();
        recoil.SetRotation();
    }
}

The sway is still being overriden by the recoil. The SetPosition() and SetRotation() are only adding to the transform

rough granite
vocal quiver
#

!code

eternal falconBOT
vocal quiver
#

guys im trying to create this zoom in effect using the FOV feature on my camera but for some reason the script isnt doing anything. Gotta be honest with you I have no idea what I am doing with the handleAim function that part is chatgpt but basically I have a normal MainCamera with a cinemachine brain attached to it. pls help

https://paste.mod.gg/agttgumdjqzb/0

wintry quarry
#

You can also just make a second, more zoomed in, CM Camera and transition to that one and back as needed

hazy cliff
#

stupid question but how do I access something i just got from the asset store?

lavish violet
#

um ive never like made a game or scripted before like i just got into it and was wondering like where to start and if yall have any tips

#

i dont really wanna become a big game developer i just wanna make some cool little games

cosmic dagger
solid cairn
#

I'm a beginner and im making a story game. This is the dialogue UI script. I don't know why I can't click the continue button and i added the debug.log after the AdvanceDialogue() and it doesn't show it in the console. If anyone wants to help and knows how to help, please dm me.

wintry quarry
solid cairn
wintry quarry
#

You can't interact with UI without an Event System in the scene

solid cairn
#

Huh

#

okay

digital parcel
#

help me please bro i just following unity tank tutorial and when i wanna but healthSlider it's not appear in my screen and whenever i tried to place it this error appear :v, stuck for last hour please someone help meeeeeee

wintry quarry
digital parcel
wintry quarry
#

restart the Unity editor

digital parcel
#

ok i'll try it

#

uhmm i think still same when i tried to place healthslider this error appear

digital parcel
wintry quarry
digital parcel
#

so i following unity tank tutorial and when i finally came to this step so i follow the instructure then idk why that's didn't work for me

wintry quarry
#

which part causes the error

digital parcel
#

when i want put healthbar on canvas

wintry quarry
#

which step in particular

digital parcel
#

the third one

wintry quarry
#

the third one is broken down into three smaller steps below

#

Is it the click and drag part?

digital parcel
#

i mean the 5

#

when i wanna drag it

wintry quarry
#

Ok - maybe something is wrong with the health bar prefab

#

it's corrupted or something

digital parcel
#

yeah i think so

wintry quarry
#

well- can you show it?

digital parcel
wintry quarry
#

I mean show the prefab itself

digital parcel
#

is this look normal?

wintry quarry
#

not sure - did the tutorial have you create this? Or was it already there as part of the project or whatever

#

I'm not familiar with this project

solid cairn
digital parcel
#

they just ask me for download the project resource

wintry quarry
digital parcel
#

ok i'll try it so should i start over my project?

digital parcel
#

excuse me yeah i've another question, i saw some different button from tutorial and my editor how to spawn that's button thanks

#

and this my editor looks like

pulsar pelican
#

im using UnityTest but I need a OneTimeSetUp and OneTImeTearDown

I'm currently faking the setup by doing

public IEnumerator SetUp()
{
    if (!_oneTimeSetup)
        // do stuff
        oneTimeSetup = true
{```

Is there actually a better way to do this? And how can I do it for the teardown?
slender nymph
main elbow
#

i'm trying to create a gif making software but recorder is editor only and not supported with c#

pulsar pelican
slender nymph
#

sorry the only golden path i'm familiar with is the one that saves humanity thousands of years in the future. perhaps create a thread in #1390346827005431951 with more info about what you are trying to do 🤷‍♂️

pulsar pelican
main elbow
pulsar tapir
#

&& is for checking if two condition are true

#

Example

slender nymph
#

They were asking about what operator is used for the conditional OR, which I provided a link to answer them

pulsar tapir
#

If (Input.GetKeyDown(KeyCode.w) && Input.GetKeyDown(KeyCode.alt))

naive pawn
#

and they already got answers

#

you don't need to repeat what two other people have already said

pulsar tapir
#

So | | is really same to &&

pulsar tapir
naive pawn
#

yes

pulsar tapir
naive pawn
#

that message was a good 15 hours ago

#

you're just giving them unnecessary pings at this point lmao

pulsar pelican
pulsar tapir
#

I was not talking to you

slender nymph
#

doesn't matter, Chris is still right. you unnecessarily pinged someone who already got an answer and weren't even going to provide an answer to the question they asked

naive pawn
gaunt bluff
#

Hello everyone !
Someoen can tell me what's the official way to serialize a binary file in the resources folder ?
com.unity.serialization ?

Thanks !

gaunt bluff
runic lance
#

had some issues with the source generation option though

gaunt bluff
slender nymph
#

i personally use and recommend messagepack for binary serialization, but i also have no experience with unity's serialization package so i don't know how it stacks up (i'd bet that message pack is better overall though)

gaunt bluff
slender nymph
#

there's a github repo that has the package. it's also available through open upm

split plover
#

if a game would have multiple playable characters would each of the characters have a seperate script or would they have a parent script for most of the stuff like movement

brazen crescent
split plover
#

but i dont know if its possible to seperate it into just whether i use a parent class or not

#

because on one end i might be able to get away with using a parent class for some characters if they're very similar like if a character unlocks some other mode or sommething, but at the same time i dont know if i get a situation like that if i should just add that in the code itself instead of making a new script for it

#

I think ill just seperate the characters into seperate scripts because i'm not that confident in using parent scripts

brazen crescent
#

just use a parent classthen like thike

public abstract class PlayerBaseClass(){
protected abstract void AbilityQ()
protected abstract void AbilityW()
protected abstract void AbilityE()
protected abstract void AbilityR()
}

and then in each class you implement these classes as you wish, you can also add non-abstract classes for the things that are similar like health calculation. This is just a pseudocode.

cosmic dagger
#

If a character has special movement, like a dash or a jump, I'd create a separate script to handle that and attach it. The scripts are small components that when combined build the functionality of your character . . .

split plover
#

Mostly because I don't want a different movement script for every single character based on the way the characters move

cosmic dagger
#

Yes, you can add a dash and a jump to the Movement script but it becomes difficult the more functionality you add to a script . . .

cosmic dagger
split plover
wooden hill
#

🤔

split plover
#

I will do that for basic things but if a character moves completely differently then I will have to make a different movement system for it

#

Which might happen a couple times

cosmic dagger
split plover
#

I already got my answer a bit earlier anyways so I'm just going to go

#

My neck is hurting anyways

woven crater
#

is there a better way to put text on object rather than put canvas as a child of it.and should i worry about it chewing up my performance

silk night
woven crater
#

yeah dynamic

dense sparrow
#

My inventory needs to store up to 300 inventory items. This means that each item needs a monobehaviour that implements IBeginDragHandler, IDragHandler, IEndDragHandler to handle swapping items in the UI. Would this be too expensive for performance considering im only using unity events?

woven crater
#

stuff like health ui on an entities that move around

dense sparrow
silk night
woven crater
#

i see . thank

silk night
#

you can ofcourse to that with every text/ui element like health bars that are bound to on-screen entities

#

its common practice to have a single canvas that contains all health bars for example

eternal needle
woven crater
#

my bad, and thank you👍

sand gate
#

are cs (player) and ```

player != null``` the same?

#

in an if statement

slender nymph
#

assuming player is an object that inherits from UnityEngine.Object then yes

naive pawn
#

then yes, they are the same

sand gate
wooden hill
sand gate
wooden hill
#

describe your problem

#

not just "why is this happening"

#

we can not mindread

sand gate
#

i am using Navmesh according to the rollaball tuotorial

frail hawk
#

i only see a purple cube and a ball, which one is the player?

wooden hill
#

also show inspector of enemy and enemybody

#

guessing that you offset the model while the agent is on the parent

sand gate
#

thats what happened

#

thanks alot

dull grail
#

How can i make movement with new input system to not override external velocity like knockback and not leaving player with unchangeable speed if it was applied? I've tried to use code below but it will instantly nullify x-vector and if i wrap it to if (vector2.normalized != 0) then character will move in the last used direction

Rb.velocity = new Vector2(_moveDirection.x * maxSpeed, Rb.velocity.y);
frail hawk
#

are you using AddForce for the knockback?

dull grail
#

I've tried to do so but then decided it will not work if initial speed would be too high. At this moment i use this method

protected virtual void KnockbackYourself(Vector2 threatPosition)
    {
        var knockbackDirection = ((Vector2)transform.position - threatPosition);
        Rb.velocity = new Vector2(knockbackDirection.x * 12.0f, 5f);
    }
sharp jay
#

Magic numbers

#

Remove them

#

For a knockback I would assume you'd want Addforce with an Impulse forcemode

solar yoke
#

I have a question, I am new developing games and I have a problem that I cant fix it. The main camera is in the main player but when i start the game it was somewhere else and i can see the capsule in front of me instead of the camera being inside. I dont know if it a problem in coding or in the hierchy

rich adder
dull grail
wooden hill
solar yoke
wooden hill
dull grail
wooden hill
#

where is it on, and what's the transform that you have there

sharp jay
#

It's not very often you'd manually change the velocity.

solar yoke
sharp jay
#

knockback is an instant burst of force in a direction you choose, add force with Forcemode.Impulse would do exactly that

wooden hill
solar yoke
wooden hill
sharp jay
#

playerCam is set to -9.x units behind the cam holder

wooden hill
#

on PlayerCam

sharp jay
#

so it's going to be that far behind the player

solar yoke
wooden hill
#

yes

#

you're moving the parent with your script

#

but the camera is a child of that and always offset relative to the parent

solar yoke
#

ur so good thank you very much i thing that is fixed

dull grail
dull grail
#

Using bool for temporaly disable move method helped but now it's looking like i'm beating against of air if bool switched before i'm landed. What can i do to fix it?

private void Move()
    {
        if (!IsImmobilized)
        {
            Rb.velocity = new Vector2(_moveDirection.x * maxSpeed, Rb.velocity.y);
        }
    }

protected virtual void KnockbackYourself(Vector2 threatPosition)
    {
        ... // I use IEnumerator to switch IsImmobilized state
        var knockbackDirection = new Vector2(
            horizontalForceAmplifier * Mathf.Sign(transform.position.x - threatPosition.x), 
            verticalForce
            );
        Rb.AddForce(knockbackDirection, ForceMode2D.Impulse);
    }
echo cradle
#

Hey everyone!
I’m working on a Unity inventory + equipment system for a lewd dungeon crawler RPG and could use some guidance.

Here’s what I need:

Inventory holds item prefabs with an Item component (CursedGear, Consumable, KeyItem, etc.)

Equipment tracked by slot using an enum (EquipmentSlot → GameObject)

Equip logic moves items between inventory and equipment, unequipping old items properly

UI shows equipped item icons per slot, icons come from a sprite field on the Item component (not from the GameObject’s Image component)

Uses an OnEquipmentChanged event to update the UI

Some items apply status effects like curses

My problem:
Icons don’t always update reliably, event triggers can be inconsistent, and syncing prefab data with UI is tricky. I want a simple, clean, open-source example or tutorial to emulate, especially one that clearly separates item data from UI representation.

If you have or know:

Good example projects or repos

Tutorials that cover this well

Assets or patterns that handle equip/inventory + UI cleanly and reliably

Please point me in the right direction! Thanks!

rich ice
#

but also, game dev guide usually has some consistantly good tutorials. they have a tutorial on inventories too. just from a quick skim I believe it fits most of your criteria

Download Core to create games for FREE at 👉🏻 https://bit.ly/Core-GameDevGuide and join the Game Creator Challenge 👉🏻 https://itch.io/jam/gcc - Inventory Systems are a key part of most games, so let's look at how to create one!

Want to support the channel...

▶ Play video
#

if you have any issues feel free to come back here and we can help you debug them cat_thumbsup

wooden hill
#

could have just left the "lewd" out of it notlikethis

ivory bobcat
dull grail
#

Once IsImmobilized switched to false player make a jump in the air and fall to the ground while x-axis velocity reseting to 0 since there is no input from me

ivory bobcat
#

Is that what you are wanting?

dull grail
#

Nope, i want it to fall naturally unless i'd try to move character by input

ivory bobcat
#

I'm not understanding the question. I'm assuming you're wanting the bool to be false before the yield from the coroutine finishes. If so, just set it to false elsewhere.. like when landing etc.

dull grail
#

I want to achieve smooth speed deceleration rather than just immobilize player until it hit the ground. Like this

#

Red is how it's working now*

ivory bobcat
#

Are you assigning to velocity anywhere else other than Move? Your velocity with regards to x shouldn't go to zero if you aren't modifying velocity.

#

Especially in the air as there very likely isn't any resistance-friction

#

(unless you've got some move dampening built-in or something)

dull grail
#

Move method is in update so if i don't use movement buttons then it will just multiply rb velocity to 0 and kill all speed. I've tried to wrap it to if (vector2.normalized != 0) but in this case character would just move with last achieved speed in the last direction until i input another value and it'll just change direction

#
private void Update()
    {
        _moveDirection = _move.ReadValue<Vector2>();
    }

    private void FixedUpdate()
    {
        Move();
    }

private void Move()
    {
        if (!IsImmobilized)
        {
            Rb.velocity = new Vector2(_moveDirection.x * maxSpeed, Rb.velocity.y);
        }
    }
ivory bobcat
#

Show where you're assigning velocity other than move. I'm assuming your character is immobilized and that movement isn't what's causing your velocity (relative to x) to become zero

silk night
dull grail
#

Oh, there's only this methods and knockback itself change velocity in one way or another

protected virtual void KnockbackYourself(Vector2 threatPosition)
    {
        float horizontalForceAmplifier = 3.0f;
        float verticalForce = 2.5f;
        StartCoroutine(nameof(Immobilize));
        var knockbackDirection = new Vector2(
            horizontalForceAmplifier * Mathf.Sign(transform.position.x - threatPosition.x), 
            verticalForce
            );
        Rb.AddForce(knockbackDirection, ForceMode2D.Impulse);
    }

    protected virtual IEnumerator Immobilize()
    {
        IsImmobilized = true;
        yield return new WaitForSeconds(.3f);
        IsImmobilized = false;
    } 
silk night
#

also depending on if you want to keep a "stun" on knockback you can then remove the IsImmobilized as you cant airbreak instantly anyways

dull grail
#

As it's made now it's more of workaround than stunning mechanic

silk night
#

i mean you can keep it as a stun

#

just dont apply the movement force on the player while the "stun" is active 😄

dull grail
#

Oh, got it

silk night
#

oh and dont forget to multiply the movement force by deltatime if you apply it, constant force via ForceMode2D.Force should be deltaTime sensitive

dull grail
#

I see, thank you again

torn night
#

jo guys what is a good approach on creating bosses in unity 2d?

teal viper
#

If you need a better answer, you'll need to make a better question.

rugged beacon
#

i seen alot said that co routine is bad and invoke is worse, what usually used instead?

naive pawn
#

coroutines are fine

#

don't just take "bad" at face value, actually do some questioning about why that's presented

rugged beacon
#

yea how do i determine that

#

i can guess invoke is bad since it pass in a string so like maybe it search for that funciton

naive pawn
#

Invoke is generally regarded as bad because it uses magic strings and doesn't give you precise control over queued calls

rugged beacon
#

idk co routine

naive pawn
#

coroutines.. idk, create garbage?

rugged beacon
#

that new waitforsecond ?

naive pawn
#

i guess that's technically a bad thing, but it's not gonna matter unless you're creating a few thousand of them in a second

naive pawn
#

but it really is not at a scale that matters

rugged beacon
#

ok but what used instead

naive pawn
#

coroutines are fine, you can write timers yourself that are updated in Update (basically the same thing written in a different way) or you can use other systems like tasks or async

#

just use what makes sense to you, that gives you an easy time reading and writing

rugged beacon
#

currently i know invoke is bad but really easy to use, the function can be reuse easy too
for coroutine i hate setting it up and to only use it through start coroutine
so really want aternatives

naive pawn
#

i gave you alternatives

rugged beacon
#

yea just explain i cant really settle with them 2

naive pawn
#

hell, use invoke if you want to, i can't stop you
just know that there's debugging hell waiting for you if you ever mess up

dull grail
#

I've never used async functions and don't know a lot of them but aren't whole game work asynchronously?

naive pawn
#

it's a specific kind of async

#

haven't worked with them before, can't really say much

naive pawn
rugged beacon
#

i think you are thinking too much, that sentence i said just only to explain that i dont really want to keep using those 2 only. but not for want to keep you going

naive pawn
#

you said, "just explain", that's a request lmao

rugged beacon
teal viper
teal viper
#

But to be honest, async can be more complicated for a beginner(has some pitfalls that you need to know and handle), so maybe stick to coroutines.
Your own system in update is fine too.

rugged beacon
naive pawn
#

what answer are you expecting?

teal viper
rugged beacon
#

not really one tbh lol

dull grail
naive pawn
#

what are you trying to get from us

rugged beacon
#

you show the alternative and thanks you my question end there

eternal needle
# rugged beacon not really one tbh lol

your problem with coroutine is that you dont want to use it because you dont find it easy basically. learn to use it or just stick with invoke which you've said yourself, its worse.

teal viper
naive pawn
rugged beacon
#

ok i see

teal viper
#

I think you both just misunderstood each other at some point and kept on developing that misunderstanding. 😅

naive pawn
#

if you were clarifying a previous message/question you need to put something that specifies that (ie "to clarify") or use past tense (ie "so i wanted alternatives")
ideally both

rugged beacon
plush chasm
#

Coroutines are easier to use if you have a snippet for it. For example I write coroutine in visual studio then it outputs below with my cursor at Name so its easy to change the name.

        {
            yield return null;
        }```
#

my favorite snippet is "sf" which outputs [SerializeField] private int myField;

vale owl
#

In unity6 is there a way to view read-only properties on components? I want to see some internal state without spamming logs for a property defined as public float seenHeat { get; private set; }

polar acorn
#

[field: SerializeField]

vale owl
#

That works, however makes the property appear like it's meant to/can be set in the unity UI (is it actually forceably assigning the value?). Id like to maintain it being read only

vale owl
#

Yeah that actually does just straight up let you mutate readonly fields, which at that point might as well just make it a public property

wintry quarry
#

(btw readonly field is different from a property without a setter)

vale owl
#

Oops replied to myself

vale owl
wintry quarry
#

If you have Odin Inspector that has a similar attribute as well, and can work directly on properties. But that's a paid asset (and Odin Serializer happens to be notoriously non-performant)

vale owl
#

Im using a custom unity runtime so im trying to avoid libraries/packages as much as possible as theyre a bit of a pain to setup

wintry quarry
#

You can also just write your own PropertyDrawer (which is how the NaughtAttributes lib above works)

radiant ferry
#

I have an object with a single AuidoSource attached and two AudioClips referenced, the first clip works but the second one doesn't. The first clip is played here:

if(Input.GetKey(KeyCode.Space))
{
     PlayerAudio.PlayOneShot(Fire);
}

The second one is played here:

void DestroyPlayer()
{
     if(HasPlayedSound == false)
     {
           PlayerAudio.PlayOneShot(LargeExplosion);
           HasPlayedSound = true;
           gameObject.SetActive(false);
     }
}

If I move the LargeExplosion sound to where the Fire sound is played, it works perfectly fine. Does anyone know why this isn't working?

#

The sound is played before the object is set inactive so I don't think that has to do with anything

rich adder
radiant ferry
ashen geode
#

Hi, may anyone help me?
So i started doing 3d animation just now, and my animator controller logic already settled correctly, when its idle and walking, so the problem is not inside the controller i guess. However when i press play, the idle animation is playing in controller but not in the game directly, what could be wrong?
Ive asked ai, and watched basic animation in youtube, nothing helped

#

The rig also settled to humanoid not generic

teal viper
ashen geode
#

Do you have any clue what should i look at

#

Even in my script, i already assign the gameobject to the correct one,

teal viper
teal viper
ashen geode
#

Sigh, guess let me try from beginning

solemn crypt
#

Need help making aim code

#

I made one version today but it gave me an error saying top was not accepted when I typed serialized field

#

So that one version won’t work

#

Gun aiming btw not just aiming in general

wintry quarry
#

Can you be more specific about this?

#

Also how is "gun aiming" different from "aiming in general"?

#

What kind of game is this?

wooden hill
#

otherwise yeah show some footage

ashen geode
#

Thank you all, but the problem is in the 3d model ig, while when i use mixamo sprite its all alright, for now thats fine as im testing mechanism of unity.. ty !

wooden hill
#

are you trying to run a mixamo animation on another character?

#

make sure you have the animation with a humanoid rig and your character model also it's own humanoid rig for easy retargeting

ashen geode
#

I mean it worked in mixamo but for some reason its not accepted in unity

wooden hill
#

download in mixamo with skin once

ashen geode
#

I spent 3 hour to figure out ong

ashen geode
wooden hill
#

and then select the mixamo rig in the mixamo animations

#

click model in project -> inspector -> rig and then set to humanoid (from this or from other which has the rig "skin")

#

again showing these will tell us more

ashen geode
white terrace
versed bronze
#

hello

#

ı watched a tutorial but when i tried it didnt worked

#

there is no error but not working

fickle plume
eternal falconBOT
versed bronze
#

how can ı do that

fickle plume
#

"not working" is not a description of the problem. Think about what you asking.

versed bronze
#

this is the code

#

there is a button when i click it it supposed to be hostlobby and show me the lobby creators name

tawdry rock
#

Might worth a try to ask i have been struggling with my rigidbody. Im using object pooling. At first when the gameobject created it fly to the right, when it gets taken back to the pool second time, the force is not applied and just falls off.

Rigidbody rb = bulletcase.GetComponent<Rigidbody>();
if (rb != null)        
    rb.AddForce(spawnPoint.right * 5f, ForceMode.VelocityChange);
slender nymph
#

you need to provide more context than just that

tawdry rock
#

wdym?

slender nymph
#

i mean exactly what i said. that is not enough context to know what is causing your issue

tawdry rock
#
 private BulletCase CreateBulletCase()
 {
     string path = "Main Camera/ObstacleAvoidenceRotator/Weapon Camera/WH/Primary/idle1(Clone)/gun_rig/main/bullet_case_spawner";
     Transform spawnPoint = Reference.i.thePlayer.transform.Find(path);

     //Spawn new instance of the bullet
     BulletCase bulletcase = Instantiate(bulletcasePrefab, spawnPoint.position, this.transform.rotation);
     bulletcase.transform.SetParent(poolParent.transform);      

     //Assign the bullet's pool
     bulletcase.SetPool(_bulletcasePool);

     return bulletcase;
 }

 
 private void OnTakeBulletCaseFromPool(BulletCase bulletcase)
 {
     //Reset the transform position and rotation     
     string path = "Main Camera/ObstacleAvoidenceRotator/Weapon Camera/WH/Primary/idle1(Clone)/gun_rig/main/bullet_case_spawner";
     Transform spawnPoint = Reference.i.thePlayer.transform.Find(path);

     bulletcase.transform.position = spawnPoint.position;
     bulletcase.transform.rotation = UnityEngine.Random.rotation;        

     //struggling part
     Rigidbody rb = bulletcase.GetComponent<Rigidbody>();
     if (rb != null)        
         rb.AddForce(spawnPoint.right * 5f, ForceMode.VelocityChange);       

    
     bulletcase.gameObject.SetActive(true);
 }
#

Whats is wierd that it works for the first time but when recycled it's not. I tried to reset the velocity but rb.velocity is deprecated and it suggest velocity linearVelocity instead, but it doesnt work with that.

keen dew
#

You have to activate the object before applying force

tawdry rock
#

oh my god....

#

Thanks, that seems like was the problem. I need to take a break, been coding since 6 hour straight, my mind is hazy.

trim anchor
#

hello everyone. I am doing that a character grabs and drops a cube. Grabbing works but when I drop the cube it doesn't collides with the floor. I've been trying for a long time but I can't figure out what is happening. If anyone can help me here is the code. Also the components in the cube and in the floor.

wooden hill
#

before picking do the cubes fall and collide with the floor? use gravity is unticked at start?

#

@trim anchor

trim anchor
#

before picking the cube the gravity is unabled but i have to enble gravity so when i drop the objects fall

#

so yes the gravity at start is unticked

wooden hill
#

show the colliders on the box and the floor( scene view)

trim anchor
wooden hill
#

and if you start with gravity enabled without picking them they also fall through?

trim anchor
#

yes

wooden hill
#

hmm...
what about project settings then physics. is it disabled in the matrix there? default to default layer collision

trim anchor
#

I have all enabled

wooden hill
#

also that script is the only one and it's on the player right?

trim anchor
#

yes

wooden hill
#

what if you make the floor 1 thick instead of 0.1

#

also what if you set interpolate to something else on the cube

trim anchor
#

What does interpolate is used for?

wooden hill
#

ok it's probably not interpolate

trim anchor
#

the interpolate in my cube is none

wooden hill
#

so if you enable gravity what happens after a like 5-10 seconds

#

where is the cube then

trim anchor
#

The cubes falls, passes through the floor and keep going lower

wooden hill
#

floor collider center y is offset by -1. shouldn't that be 0?

#

other than that I can't spot anything rn kind of sleepy

trim anchor
#

it doesn't work but anyways thanks for trying to solve it

wooden hill
#

what I'd try is with a new scene just floor and a cube with rigidbody and see if it works and if yes then re-add the things one by one

trim anchor
#

ok

#

I've tried many things in a new scene still don't works

wooden hill
#

even just a cube falling onto a stationary cube?

#

and no other scripts/objects

trim anchor
#

if is not trigger it works but i can't grab the cube if it isn't trigger

wooden hill
#

oh..

#

i didn't even see that

#

yea trigger is trigger

#

no collisions then

#

you would either have to add a child with box collider trigger on the cube or maybe have a trigger on the player itself

#

and definitely uncheck trigger on the rigidbody collider itself

#

how could i miss that lmao

trim anchor
#

but for grabbing the cube i use ontriggerstay. Is there any other method that works with collision

wooden hill
#

there are 6 important ones

#

ontrigger enter/stay/exit
and same for collision

#

as i said you can try adding a child box collider on the grabbable object and set that to trigger (and maybe make it a bit bigger)

trim anchor
#

i've tried putting the cube with a child that is triggered and the parent without is trigger and the cube just acts like a cube without is trigger

wooden hill
#

does ontrigger not get called? add a Debug.Log("ontriggerstay called") there

#

make sure you set the tag

#

also make the child (trigger) is a bit bigger than the parent because you may be pushing the whole thing without being able to enter the trigger box

trim anchor
#

I've made the child bigger but it seems that in physics it acts like a cube without trigger

wooden hill
#

what if you put a rigidbody on it too but set it to always kinematic

trim anchor
#

I have put the cube in kinematic. It just stays static and you can't grab and drop it

wooden hill
#

otherwise you probably need to use another logic. like oncollisionenter and then track last collided grab object in a variable (+ check distance when pressing grab key)

trim anchor
#

ok

#

the cube goes fliying

wooden hill
#

huh

#

show me setup of the grab object in hierarchy and inspector of them

unique nexus
#

like goes upward instead of how gravity should work?

trim anchor
#

yeah

unique nexus
#

almost certain its about the settings of the rigidbody

#

just forgot what it was exactly

trim anchor
wooden hill
#

that's the parent?

trim anchor
#

yes that is the parent

wooden hill
#

and child?

trim anchor
#

that is child

wooden hill
#

try to send bigger picture btw can't see collider on these

trim anchor
#

ok

#

this is the parent

#

and the child

wooden hill
#

use gravity on child makes no sense but idk if that affects anything because you have kinematic checked anyway

#

oh check is trigger on child

#

otherwise they are literally inside eachother and the cube collides with it and flies

trim anchor
#

i've checked is trigger now it doesn't flies

wooden hill
#

ok and is it bigger than parent?

#

or try if you can grab it now

#

hmm although maybe it won't work with your code since you're getting the child

#

would need to change it a bit

trim anchor
#

how?

wooden hill
#

A bit hacky but in ontriggerstay where it says other change it to other.parent

#

other.GetComponent... becomes
other.parent.GetComponent...

#

do that with all the lines where you wrote "other"

#

since you want to change the parent collider

#

not the child trigger

trim anchor
#

it shows that is an error

wooden hill
#

how so?

open apex
#

https://discussions.unity.com/t/solved-how-to-detect-double-tap-on-ui-button-and-change-interval/562655/12

Quick question on double tapping. I am developing a mobile game don't know how to do double tapping, I looked it up only and it looks like this is better practice then what I thought of doing. I thought having a timer where if button x was clicked twice within the same second the player would dash. Which is better practice here? How much of a difference would and does it make?

the link is the source I was following for reference to learn how to do a double tapping system

wooden hill
#

just show the error

trim anchor
wooden hill
wooden hill
# trim anchor

ah other is collider yeah right.. it has to be other.transform.parent 🙂

#

mkv not working on mobile here

trim anchor
#

@wooden hill thanks it works

wooden hill
wooden hill
#

btw you could also put a child like that (with kinematic rigidbody and trigger) on player instead of every grab object

trim anchor
#

ok

wooden hill
#

but then you would again have to adjust code

#

at least need the trigger stay message script on the trigger child

wooden hill
# open apex thanks

no problem basically just try to not overengineer/overthink if it's not too critical like this

open apex
#

But I don't want to stick to the stuff I already know I want to move a step forward so I can learn and do more stuff

#

And I want to learn how to do it the right way

wooden hill
#

there are multiple ways as you can see from that thread

#

which one is perfect? idk.. would have to run profiler and check if coroutine way is some micro/nanoseconds slower than the update method

open apex
#

something I keep on the side and read at my free time

#

that will move me onto beginner-intermidiate level

#

or help me move onto that

wooden hill
eternal falconBOT
#

:teacher: Unity Learn ↗

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

open apex
#

(and sugar coatting it)

wooden hill
#

I haven't had a c# book only read some c or cpp at my uncles place long ago and got interested in making games around that time too. in unity i started with tutorial hell 😄 but slowly transitioned to learning and doing more by mself

#

i did other programming languages too and experimented a lot so I can't really call myself to have an idea how to go about it other than just keep trying 😛

slender nymph
open apex
#

Can you send me an invite for the discord community by any chance?

slender nymph
#

it is geared towards people new to the language and programming, but has summaries you can skim through to skip ahead to the more intermediate stuff

open apex
#

as a beginner I sit down and spend like 2-3 hours, 70% of the time is doing research and chatting to more experienced people and 30% is actually coding 😭

open apex
slender nymph
#

coroutines are a unity thing

open apex
slender nymph
#

yes, it is purely c#

open apex
#

should I start with the 1st edition?

slender nymph
#

lol no, they aren't sequels but rather updates that include restructuring of the content and newer language features. just get the latest one, but be aware that it teaches some stuff that isn't available in unity at the moment (there are some specific c# 10 features that cannot be used in unity yet)

open apex
#

ohhhhh

#

appriciated

#

cheers

twilit jolt
#

hi y'all, quick question
i'm trying to use the splines package, to generate a path that connects 2 points smoothly

when i set the spline up in the editor it works as expected (pic1), but when i set the spline up from code, its fully straight (pic 2)
i set the rotation of both start and end knots to match the rotation of a transform that points into, and out from the objects i want to connect
(i also tried setting both in and out tangents on the start and end points, and that didn't help either)

is there something i'm not getting here?

wooden hill
open apex
# wooden hill no problem basically just try to not overengineer/overthink if it's not too cri...

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class HoldButtonHandler : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
public bool isHolding;
public bool slide;
bool dash;
public Text Debug;
int x = 0;

void Start ()
{

}

void Update()
{
    if (isHolding)
    {
        doubleTap();
    }
}


IEnumerator doubleTap()
{
    if (x == 1)
    {
        dash = true;
        Debug.text = "doubleTap coroutine run";
        yield return new WaitForSeconds(0.5f);
        if (x >= 2)
        {
            Debug.text = "Dashed and bool dash turned false";
            dash = false;
        }
        else
        {
            dash = false;
            x = 0;
        }

    }
    else
    {
        dash = false;
        x = 0;
    }
}
public void OnPointerDown(PointerEventData eventData)
{
    isHolding = true;
    x++;
    if (dash == false) 
    {
        StartCoroutine(doubleTap());
    }

}
public void OnPointerUp(PointerEventData eventData)
{ 
    isHolding = false; 
}

}

how does this look?

slender nymph
#

!code

eternal falconBOT
open apex
#

it works fine

twilit jolt
# slender nymph show code

oh yea, sorry

public SplineContainer handledSpline;

public Vector3 startPos;
public Vector3 startDir;
public Quaternion startRot;

public Vector3 currentEndPos;
public Vector3 currentEndDir;
public Quaternion currentEndRot;

void Update(){
  Spline spline = handledSpline.Spline;

  BezierKnot start = spline[0];
  BezierKnot mid = spline[1];
  BezierKnot end = spline[2];

  start.Position = startPos;
  start.Rotation = startRot;
  start.TangentIn = startPos - startDir;
  start.TangentOut = startPos + startDir;

  mid.Position = Vector3.Lerp(startPos, currentEndPos, 0.5f);
  mid.Rotation = Quaternion.Lerp(startRot, currentEndRot, 0.5f);

  end.Position = currentEndPos;
  end.Rotation = currentEndRot;
  end.TangentIn = currentEndPos - currentEndDir;
  end.TangentOut = currentEndPos + currentEndDir;

  spline[0] = start;
  spline[1] = mid;
  spline[2] = end;

  handledSpline.Spline = spline; 
}

i am setting the positions, rotations and directions from a separate script that handles building the path, but that part shouldn't matter

slender nymph
#

make sure the code is actually running and that the values being used are what you expect them to be

wooden hill
rancid crow
#

Anyone got a script where the monster walks around trying to find you

wooden hill
#

"Inline code" or if really long then use a paste site

wooden hill
#

anyway this is not a script dispenser

rancid crow
#

i have the agent an he just sits in his idle pose

slender nymph
bitter spruce
#

i think this might be abit unrelated to direct code, but how do i parent child something without my object being stretched weird and all. Im trying to make a lever.

#

uh the first image needs to be clicked in

polar acorn
bitter spruce
#

everything is defaul

twilit jolt
polar acorn
bitter spruce
polar acorn
#

If any direct parents have non uniform scale, rotating the object will skew it

bitter spruce
#

I guess ill make it in a empty gameobject

#

Thank you for the help

wooden hill
bitter spruce
#

ill separate the base and the lever itself

wooden hill
wooden hill
#

SetDestination

open apex
#

Funny question, when I put these Text boxes too close to the player they affect the movement of the player making it fly

#

why and how?

#

yes the player is 2d but that's supposed to be an on screen UI rather than something in the game

wintry quarry
#

But you also cut off the hierarchy so it's a bit hard to see what's going on there

rancid crow
open apex
#

Have made player the parent of canvas

these are my scripts:

hold button script, meant to detect button being pressed

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class HoldButtonHandler : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
    public bool isHolding;
    public bool slide;
    public bool isDashed;

    bool dash;

    //public Text Debug;
    int x = 0;

    void Start ()
    {

    }

    void Update()
    {
        if (isHolding)
        {
            doubleTap();
        }
    }


    IEnumerator doubleTap()
    {
        if (x == 1)
        {
           // Debug.color = Color.red;

            dash = true;
            //Debug.text = "doubleTap coroutine run";
            yield return new WaitForSeconds(0.3f);
            if (x >= 2)
            {
              //  Debug.color = Color.green;
                //Debug.text = "Dashed and bool dash turned false";
                dash = false;
                isDashed = true;
                yield return new WaitForSeconds(1f);
                isDashed = false;
            }
            else
            {
                dash = false;
                x = 0;
                //Debug.color = Color.red;
            }

        }
        else
        {
            dash = false;
            x = 0;
           // Debug.color = Color.red;
        }
    }
    public void OnPointerDown(PointerEventData eventData)
    {
        isHolding = true;
        x++;
        if (dash == false) 
        {
            StartCoroutine(doubleTap());
        }

    }
    public void OnPointerUp(PointerEventData eventData)
    { 
        isHolding = false; 
    }
}
#

the game manager script was too long to send here

#

You're always here helping me and other people out

eternal falconBOT
open apex
#

really appriciate it praetor

wintry quarry
eternal falconBOT
open apex
wintry quarry
#

Looks more like a movement controller than a game manager but alright

#

Ay other scripts involved?

open apex
#

this is all

wintry quarry
#

Anyway why is the canvas a child object of the player

#

Another thing i see is that the logic for the left button in the game manager is probably pretty problematic

#

Because you're multiplying the whole velocity vector by -speed

#

That's going to negate the y velocity, which could easily lead to your object flying

open apex
#

tbh I'm doing my best 😭

humble rain
#

I have a question, what is the internet speeds at your place ? My avg speed is around 5 - 7 Mbps.

open apex
#

that is the speed for 2000s

#

we are in 2025

#

but it depends where you live aswell

humble rain
open apex
#

what does it say on your contract

humble rain
#

oh whoa, it been like this for 7 years or so.

open apex
#

what's the speed written the on your contract like

wooden hill
#

had 1000 now moved and got 70 mbps 🙂

wooden hill
humble rain
#

haha..

#

i don't think there is at this place. And I thought it's already really fast lol..

wooden hill
#

Patience is a virtue

#

btw what part of the world is that in?

humble rain
#

yes, rural area of vietnam.

#

I only got computer back when 2021 - 2022 as well

#

if you look at my discord creation date

wooden hill
humble rain
#

yes, vietnam is still pretty much a third world country.

#

better than laos and campuchia a little bit but still is

#

like for most of the country.

wooden hill
#

well good luck with your path 🙂

humble rain
#

well, most of my friend already left to go to japan already since they want to do like physical work, since wage in here is so low and they don't want to live in the jungle all the time.

atomic holly
#

Hi, I have an error to get a Singleton. I want to add a Action from my Player class to a PlanManager. So, I add the reference of my method to the action in the OnEnable() method like here : https://pastecode.io/s/hw03ao1q. But, I have this error on the OnEnable line : NullReferenceException: Object reference not set to an instance of an object. I don't get the error in a awake when I get the reference of Player.Instance. Otherwise, I tried to put Player.Instance direclty in the OnEnable and now it works. Why ?

wooden hill
#

also if your player will always be a singleton then why not make the event "public static" ?

#

like
public static event Action TransitionPlanChanged;

sour fulcrum
#

i think you might need to manage your static events if you disable domain reloading though

atomic holly
atomic holly
wooden hill
#

not sure why that tis

wooden hill
wooden hill
mild lake
#

I have several different scripts, (mana, health, attack, move, animations, ect) and i want to edit the values all in one place (like a scriptable object almost). What's a good way to go about this

#

For more context, i'm trying to make it easier to add enemies to my game, so all the settings are cleanly laid out (preferablly in a scriptable object)

mild lake
#

I'd have to make almost every variable and method in my script that would need to be edited public

#

or i guess i could supply every script that would use the SO with the SO

celest shadow
#

hello unity bros. I'm currently struggling with a very basic problem. I have a 100x100 cell grid for my game and I'd like it rendered at run time to show where a player can build. whenever the grid is enabled, my editor starts to lag signifiganty.

the grid is just 100x100 quad prefabs with a transparent square texture. I even tried culling ones not on screen but it didnt seem to do much.

any tips on how to handle this scenario?

wooden hill
teal viper
mild lake
#

yeah i think i'll do that

#

thank you

cosmic dagger
wooden hill
mild lake
#

Yeah but i wasn't sure it was the right approach: eg it could work but not the best

celest shadow
#

I jsut stepped away from my pc so I cant profile for a bit. All I know is that I tried it with gl lines and it ran fine, but I couldn't get the lines to depth test so they always rendered through everything. Then I switched to quads and got lag. Is there a way to get gl lines to depth test in URP?

#

I can also cook up a grid display pretty easily in shader graph but I can't figure out a way to dosable/enable individual cells that route

celest shadow
# mild lake I have several different scripts, (mana, health, attack, move, animations, ect) ...

So you can use a plain old c object to store entity data. If you Tag the class with [serializable] attribute you can then edit the POCO in the Unity editor. You can use this to build up a list of EnemyDefinitions, then at runtime build a dictionary from the list, dict<Id, enemy definition>, and you can look up enemy stats in the table in o(1) and set the Various values from the defition to your base enemy script

#

The poco can store all numbers and values, like ID of model and animations and all stats

cosmic dagger
celest shadow
#

My technique is basically a crappy dB in a unity object

#

With the POCO as the rows

#

If you have a ton of stuff to store you could even in theory roll in an sql lite dB but you'd need pretty intense requirements to need that

cosmic dagger
#

I usually have an EnemyConfig SO and create many assets in the project folder for each type of enemy. Then I make a Database SO that holds a list and dictionary of those EnemyConfig SOs for easy access . . .

celest shadow
#

Yeah same result, different route

rugged beacon
#

how do i get current playing animation length

celest shadow
#

Big old list of definition objects you do lookups against

restive kettle
#

guys is how to share my codes to github? last time i tried it didnt cuz it litrly uploaded the whole app file

#

and its too heavy

naive pawn
#

make sure you have the proper .gitignore

frank lion
#

Hi, is there any way to solve this? I regenerated my files once and it solved it, but then I installed the Input package, and it note even the regenerate files does anything.

#

And I did select visual studio as my editor

median hatch
#
public void ChangeFrame(int destPosition)
    {
        MMF_Position position = changeFrameFeel.GetFeedbackOfType<MMF_Position>();

        RectTransform verticalLayoutRect = frameVerticalLayout.GetComponent<RectTransform>();

        position.InitialPosition = new Vector3(-858, verticalLayoutRect.anchoredPosition.y, 0);
        position.DestinationPosition = new Vector3(-858, destPosition, 0);

        changeFrameFeel.PlayFeedbacks();
    }

im trying to change the position of my RectTransform but for some reason its setting it to 0, 0, 0 anyone knows why?

#

im using Feels Feedback Asset but that shouldnt be relevant

rocky canyon
eternal falconBOT
rocky canyon
#

just work thru the steps again

frank lion
#

Imma just reinstall all

odd grotto
#

I like vscode and I recently tot back into unity dev but I hate the way visual studio looks is the development experience in vscode that much worse than visual studio?

odd grotto
#

Hmm then I might try it

wooden hill
#

a few stuff might be missing like alt+mouse to mark multiple lines

#

what i like is how quick it opens compared to vs(2022)

#

and autocomplete etc works just fine

odd grotto
#

I never realized how ugly the vs editor was until I used vscode and got a good theme and everything

wooden hill
#

yea vs can feel rather clunky

#

but well it's just built different

odd grotto
#

Yeah that's my main problem with it

wooden hill
#

you can try both and then decide

odd grotto
#

And the editor itself and the font rendering looks a lot worse for some reason

wooden hill
#

or even try rider too while at it lol

wooden hill
#

anyway just try

celest shadow
#

just unity being unity I guess

wooden hill
#

would try to profile a build

celest shadow
#

I'm not too concerned any more

wooden hill
#

alright

odd grotto
wooden hill
#

ig just stick to what works for ya

#

i recently switched to vsc too from vs

odd grotto
#

yeah right now visual studio isnt working for me so im going to try out vscode

wooden hill
#

make sure to install the right things

#

!ide

eternal falconBOT
odd grotto
#

thanks

naive pawn
odd grotto
#

yeah

#

I use it all the time in vscode

wooden hill
#

oh I haven't learned it yet then

#

neat

#

as you can see really new to vsc

slender nymph
cloud walrus
#

didn't know that it's a rule not repost mb

frank lion
#

Seems like the "Miscellaneous Files" problem only solves when I check one of the boxes here

fallow wind
celest shadow
autumn fjord
#

how do i make a camera move together with an object😭

#

or just how to move the camera

wooden hill
eternal falconBOT
#

:teacher: Unity Learn ↗

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

autumn fjord
#

ty

echo copper
#

guys, is it a chat to ask for help?

rich adder
eternal falconBOT
echo copper
#

okay

urban sluice
#

was I stupid for making my own lerp function accidentally cause I was trying to figure out how to make a variable go between two points, but I didn't know that's exactly what lerp does?

#

It took me like 3 hours to figure out

#

😭

polar acorn
urban sluice
rich adder
urban sluice
rich adder
#

lerp is just short for interpolation

grand snow
#

linear interpolation to be exact

urban sluice
rich adder
#

yea cause you also have Slerp (spherical)

urban sluice
#

And I've used it in unreal before too so I probably should've expected it to also be a part of unity.

rich adder
#

indeed, so many usecases for it

urban sluice
rich adder
#

there is also one for colors which is cool to play around and mix
Color.Lerp

ember saffron
#

learning unity at the moment for the first time

#

and following this tutorial

#

at 24:29 he goes through this script to spawn in pipes (flappybird) and ive followed his exact script, but mine is getting an error?

#

let me show side by side

#

(the black one is mine, white one is his)

#

is there something i overlooked?

rich adder
north kiln
#

Also a missing semicolon

ember saffron
#

what does this mean..

teal viper
ember saffron
#

what would compile errors be

#

like errors in microsoft studio

#

(i think it was called so)

teal viper
#

Errors in your code.

#

They would be visible in visual studio if it's configured properly.
!ide

#

!ide

eternal falconBOT
rich adder
rich adder
#

ops wrong msg but yea lol

teal viper
#

Probably somewhere above the errors in the screenshot

ember saffron
#

omg now a brand new "error" is happening 😭

#

or more like

#

bug

#

code is working fine

#

but its not working correctly

#

let me take a screenshot wait

#

its spawning 5000 tubes at the same time but it should be like in the 2nd pic

#

heres my reedited script compared to his again:

rough granite
# ember saffron

your problem is with the timer update it should be

void Update()
{
    timer += Time.deltaTime;
    if (timer>= spawnRate )
    {
        spawnPipe();
        timer = 0;
    }
}
#

wait uh

ember saffron
#

but i did exactly as he did it

#

and it worked 4 him

#

why isnt it working for me 😭

rough granite
rich adder
#

spawnRate

ember saffron
#

oops.. i forgot to put one LOL i think thats where the problem was

rough granite
rich adder
#

they probably had it initialized it with 0

ember saffron
#

im just starting to learn unity (literally today) so im not sure 😭

rough granite
#

fair not hating just curious

rich adder
#

the values in the initializer area (where you defined those variables there)
those are only used when the component is created (when you put a script on gameobject)
otherwise you'd have to reset the script or reattach it if you wanted the values to be like in the script (if not using inspector to change em)

naive pawn
ember saffron
#

but with this tutorial im like.. barely understanding alot

#

it feels like im just copying off code

#

he does explain well but

#

it goes so fast i cant keep up 🥲

#

gonna try to complete it tho and see if it changes

rich adder
#

learning multiple things at once is never easy

rough granite
quick cove
#

Am I missing something here about getters and setters?

public class Moves
{
    public List<string> GetMoves { get { return m_LearnedMoves; } }
    private List<string> m_LearnedMoves;

  public void InternalTest()
  {
    Debug.Log($"m_LearnedMoves count is {m_LearnedMoves.Count.ToString()}");
  }
}
public class Other
{
  public Moves moves;

  public void ExternalTest()
  {
    Debug.Log($"moves.m_LearnedMoves count is {m.GetMoves.Count.ToString()}");
  }
}

Why does the internal method debug the correct count, but the external method debug 0?

wintry quarry
#

Your code sample is incomplete. We don't see how the instances are created or what calls the test methods

quick cove
#

Was trying to simplify the code as there's a lot.

wintry quarry
#

We also don't see where and when the list may be populated

#

Well you've simplified out the relevant context unfortunately

quick cove
#
public class Warrior : MonoBehaviour
{
    /*[HideInInspector]*/ [Sync][OnValueSynced(nameof(OnLevel))] public int level;

    public HP hP { get; protected set; }
    public Stats stats { get; private set; }
    public Moves moves { get; private set; }

    private void Awake()
    {
        motor = GetComponent<Motor>();
        hP = GetComponent<HP>();
        stats = GetComponent<Stats>();
        moves = GetComponent<Moves>();
    }


    public void Init(int level, Vector3 spawnAreaCenter, float spawnAreaRadius)
    {
        this.level = level; 

        hP.Init(this);
        stats.Init(this);
        moves.Init();

        SetupAI(spawnAreaCenter, spawnAreaRadius);
    }


    private void OnLevel(int oldLevel, int newLevel)
    {
        if(oldLevel == 0)
            moves.Init();
        else
            moves.LevelUp(newLevel);
    }
}
#
public class Moves : MonoBehaviour
{
    public List<Move> GetMoves { get { return m_LearnedMoves; } }

    [SerializeField] private List<Move> m_Moves;

    private List<Move> m_LearnedMoves;

    private CoherenceSync m_coherenceSync;

    private Warrior m_warrior;

    private void Awake()
    {
        m_coherenceSync = GetComponent<CoherenceSync>();
        m_warrior = GetComponent<Warrior>();
    }
    private void Start()
    {
        m_LearnedMoves = new List<Move>();
    }

    public void Init()
    {
        if(m_LearnedMoves == null)
            m_LearnedMoves = new List<Move>();

        for(int i = 0; i < m_Moves.Count; i++)
        {
            if(m_warrior.level >= m_Moves[i].GetLevelLearned)
                m_LearnedMoves.Add(m_Moves[i]);
        }

        if(SimulatorUtility.IsSimulator)
        {
            Debug.Log($"Simulator ran Init() and learnedmoves count is {m_LearnedMoves.Count.ToString()}");
        }
    }
    public void LevelUp(int newLevel)
    {
        for(int i = 0; i < m_Moves.Count; i++)
        {
            if(newLevel == m_Moves[i].GetLevelLearned)
                m_LearnedMoves.Add(m_Moves[i]);
        }
    }
 }
#
public class Motor : CharacterMotor
{
    [SerializeField] private float m_movementSpeed = 1.5f;
    [SerializeField] private float m_runMultiplier = 2.0f;

    private Warrior m_warrior;

    protected override void Awake()
    {
        base.Awake();

        m_warrior = GetComponent<Warrior>();
    }

    //THIS COMMAND IS SENT FROM THE CLIENT TO THE SIMULATOR
    [Command] public void Cmd_UseMove(int index)
    {
        Debug.Log($"GetMoves.Count is {m_warrior.moves.GetMoves.Count.ToString()}");
        Debug.Log($"index sent was {index.ToString()}");
        if(m_warrior.moves.GetMoves.Count - 1 >= index)
        {
            //CanMove(false);

            m_warrior.moves.UseMove(index);
        }
        else
            Debug.Log("Server GetMoves.Count is not greater than the index sent.");
    }
}
#

The debug in the Motor is always returning 0 for the count. Inside the Move Init() the count is correct.

#

I think it goes without saying, but, all classes exist on the same GameObject at instantiation.

hybrid wagon
#

hlsltools isnt working in visual studio, no idea why. c# highlighting and errors work just fine

#

i got a vague warning but its not really telling me a lot

teal viper
# hybrid wagon

The error means that the hlsl tools are built in into vs(as a component), yet you also installed an extension manually.

quick cove
#

And Cmd_UseMove is called long after the Init methods.

hybrid wagon
#

yeah disabled extension and it works now nvm

#

its not highlighting nearly as much as would be preferable though

#

does it have syntax highlighting

#

no errors shown

teal viper
ember tangle
#

I have a Vector3 direction pointing at something outside of the camera view and I am trying to find the Vector3 position where the line intersects the edge of the screen. Whats the best method to do so / can someone give me bread crumbs?

quick cove
ember tangle
magic compass
#

Does anyone have a guide for Wheel Collider value callibration? I can't really seem to get any values that dont make the object wig out. The only time i can get it to not bounce like crazy it goes crazy when it finally rests on the ground, and when i can get it to not go crazy on the ground, it bounces like crazy
edit: to anyone who sees this message in the future, i based it off the "default" values for a 1500kg car and scaled. but for my purposes i had to change automatic tensor off

wicked fiber
#

can anyone tell me why this is making my object move on axis other than z?

#

transform.position = Vector2.MoveTowards(transform.position, player.transform.position, 100000000);
Vector3 mousePos = (Vector2)cam.ScreenToWorldPoint(Input.mousePosition);
transform.LookAt(mousePos, transform.up);
transform.position += transform.up * GunHover;

ivory bobcat
wicked fiber
#

that's on purpose, it's so the gun slightly hovers.

ivory bobcat
#

Maybe rephrase your question.

wicked fiber
#

(It's just while I draw the art)

#

ok