#πŸ’»β”ƒcode-beginner

1 messages Β· Page 621 of 1

jaunty bay
#

that means, the problem relays on the button not actually executing the function

candid plover
#

so what do i do ?
is the code the problem .

jaunty bay
#

and thats the one that u can figure out now that you know the trouble after troubleshooting

#

give me the screenshot of your project

candid plover
#

what part ?

#

all of it ?

#

the hierarchy ?

#

the assets ?

jaunty bay
#

your whole screen ig

candid plover
#

dont lie is my brain cooked ? 😭

timber tide
#

I forget the exact details of it all, but you basically need to negate the bits and add one to the bitfield to grab the lowest bit. Then flip that one and repeat. It's not exactly some 0(1) operation as it requires a bit of back and forth

#

Still quicker than iterating over a 64 bit enum that's for sure

bright zodiac
#

you can just Enum.GetValues(typeof(MyEnum)).ToList() and iterate it

#

check if it has Flag

timber tide
#

Why do that when you can just do what I said above and cut out the allocation ;p

bright zodiac
#

sorry I dont follow?

timber tide
#

GetValues would return all bits, you'd have to checkflag each bit, no?

bright zodiac
#

thats how you're supposed to iterate an enum, based on the original question

timber tide
#
int lowestBit = bits & -bits; 
bits &= ~lowestBit; //remove lowest bit

I think that's the idea assuming you can use unary minus works otherwise I think it's just ~bits+1

#

and the lowest bit would be a selected choice^

bright zodiac
#

remove? proly you meant masking?

timber tide
#

from the mask ye

bright zodiac
#

from what?

timber tide
#

I've done this before somewhere but can't recall what project that's in. I don't usually iterate over the bits

sour fulcrum
#

thank you guys

rugged beacon
#

anyone used aaron's a* and have adjusted the pathfind width before ?

wintry dew
#

is it reasonable to make a static version copying a method that accesses an instance variable like "timer" in a class whose GameObject will be deleted when I want to access the instance data?

ebon sapphire
#

Can someone help with this code? I'm trying to make it to where if i press escape while in the settings menu (which is a button in the pauseMenu) it goes back to the pause menu. Here's a screenshot of what it looks like:

heavy knoll
#

!code

eternal falconBOT
ebon sapphire
hot harbor
#

is there a reason that overlapCircleNonAlloc uses arrays and not lists?

#

You wouldn't need to reinitialize the list every time either, or am I misunderstanding what list.Clear does

cosmic dagger
hot harbor
#

Makes sense

#

however, would having a list instead be better if your collision results vary from hitting 1 vs 500 gameObjects?

#

Or is that not where the performance drops come from

charred spoke
#

Then it will not be a nonAllock version

hot harbor
#

I see

charred spoke
#

Resizing the list would result in a memalloc

cosmic dagger
charred spoke
#

The trick here is to supply an array with a size of the max result you would expect

cosmic dagger
charred spoke
#

To answer your question it would work the same way with a list that has a preset capacity. I would say it uses an array to make the intention of not resizing the collection clear

hot harbor
#

does clearing and adding items to the list invoke the garbage collecotr?

cosmic dagger
charred spoke
cosmic dagger
# hot harbor does clearing and adding items to the list invoke the garbage collecotr?

Yes and no. References to the objects within the list are released and will be garbage collected (only if no other references exist), but the list itself is not. The list maintains its capacity; adding new items will not incur additional memory until the capacity is reached. Then it will reallocate memory, copy over the elements, and increase its capacity . . .

heavy knoll
hot harbor
#

Thanks!

eternal needle
#

You can also use the debug draw ray or line method to visualize your raycasts

heavy knoll
#

u have any ideas on why this happens? Shouldn't they both just happen at the same time?

eternal needle
#

Also it might be better if you setup that raycast a bit different, like is it possible that some of those raycasts dont hit or start inside the terrain? If you're using navmesh you can randomly get a triangle on the navmesh then just spawn the object there

heavy knoll
#

ooh alr, ill look into improving the raycast too.
is there a way to have the terrain mesh be generated before the game starts? So it's already there when my Objects spawner try's to raycast for each object, and i dont have to put a 1 second delay before my objects spawn in

eternal needle
#

Having a terrain before the game starts would imply it's an asset that you make now, in editor

heavy knoll
eternal needle
#

it's the same result though

cold forge
#

I need a code

#

When target hits 0 in seconds (add stuff like months, days hours minutes seconds) (time target like date 2025-03-12) it will make the gameobject become invisible and have no colliders, game object can be any name

sour fulcrum
#

feel free to write it

cold forge
#

Wdym

sour fulcrum
#

this is a channel for teaching and helping people write code not for people to make you code

cold forge
#

i dont know how to make the code

#

Is there any code helper extension for unity

patent quarry
cold forge
patent quarry
#

not what i mean

#

look at other scripts to understand how unity c# works

#

and search for documentation and other stuff related to your script

sour fulcrum
#

people have made scripts that do things when something reaches 0
people have made scripts that make gameobjects invisible and disable colliders
people have made scripts that look at what time it is

patent quarry
#

ill try find some stuff to give you an idea on how to do it, but people here wont make the script for you

cold forge
#

exactly

#

Ghostys got it

#

i needed

#

h*lp

sour fulcrum
#

that's not help that's free labour. if someone is happy to do that for you that's fine but not the point of the channel

patent quarry
#

can you make variables for datetime

#

ive only used it once for something different

cold forge
#

This is a variable

#

target="2025-03-17 7:15:00"

#

i keep it for notes abt coding

#

that might be in bash

#

Not c#

patent quarry
#

lemme open unity and do some testing rq

cold forge
#

if [ $remaining_seconds -le 0 ]; then

#

that also

patent quarry
cold forge
#

if seconds 0 it will do smth

patent quarry
#

youd need to declare that its a string

cold forge
#

wait i think i got another one

patent quarry
#

do you plan to make it specifically take inputs for hours minutes seconds? would be alot easier otherwise

cold forge
#

or maybe not

patent quarry
#

to be fair

#

you could probably

cold forge
#

Ok, since i know already how to add months

patent quarry
#

find how many seconds are in a month etc

#

then in start multiply the months by that value

cold forge
#

86400 x 30.44?

#

Is the amount of seconds in a month

patent quarry
#

so id guess something like this

cold forge
patent quarry
#

so you set the hours minutes and seconds

#

you create an empty variable time

#

you calculate how many seconds are in the minutes and hours

#

then add them together

cold forge
#

for what

#

also the target time is it somewhere there

patent quarry
#

i may be confused here

#

are you attempting to have it so at a specific time something will happen and countdown to then

#

or do a countdown of a specific time when they start the game

cold forge
#

no so let me say

#

the countdown is automatic for everyone not when they start the game

#

instantly when a new update drops this is gonna be there

#

Even if some people are off the game

#

Its still gonna count down no longer what

#

To the target

patent quarry
#

so the timer will end at a specific date?

cold forge
#

then it will make the game object (aka any name) invisible and no colliders

patent quarry
#

ah

cold forge
#

and then when target hits 0

patent quarry
#

lemme find out how time stuff works rq

cold forge
#

It will make a gameobject or any name for the object become invisible and no colliders

brazen cedar
#

help guy my code is not working πŸ™„πŸ˜ŸπŸ˜Ÿ

patent quarry
teal viper
brazen cedar
hot harbor
#

I just debugged the stupidest bug I've ever written
I wrote Mathf.sign instead of sin

modest dust
brazen cedar
modest dust
#

Alright, and how are you trying to do that?

#

What do you expect to change in order for that to happen

patent quarry
# cold forge Yes

cant figure out how really, try find something online similar to what u want

brazen cedar
modest dust
#

And how is setting a float supposed to change a bool?

brazen cedar
#

do you want to see the code

modest dust
#

I already see the code

#

Show the animator

brazen cedar
#

ok

#

this is the code

modest dust
#

Do you have a parameter called Velocity in the animator?

#

Also !code

eternal falconBOT
patent quarry
brazen cedar
patent quarry
#

fun

modest dust
wild parrot
#

i found a solution... Character controller!

brazen cedar
modest dust
#

Your answer is within my question.

#

There is no Velocity parameter in the animator, is it supposed to guess which one you meant?

#

There's only Velocity X and Velocity Z

cold forge
#

back

#

dang it

brazen cedar
modest dust
#

You should take a look at !learn because you don't seem to understand how your own animations even work

eternal falconBOT
#

:teacher: Unity Learn β†—

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

modest dust
#

Why would a velocity bool help here at all

#

Your animations are controlled by Velocity X and Velocity Z, change these if you want the state of your animator to change.

#

Not some random Velocity which isn't even a parameter

brazen cedar
modest dust
#

What does a bool have to do with a float and why would changing the name in the animator help with anything?

#

Change the damn code so that the hash corresponds to the correct parameter in the animator

brazen cedar
#

show me the pic of the code pls

modest dust
#

No, go !learn

eternal falconBOT
#

:teacher: Unity Learn β†—

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

modest dust
#

If you can't follow simple instructions then I won't be helping anymore, I already explained everything that had to be explained.

wild parrot
brazen cedar
#

πŸ˜’πŸ‘

mortal ginkgo
#

i'm having a small problem (won't take much of your time) and i need to screenshare to show it to you so you can tell me what to look at
the problem is how do i make the attack i coded actually attack when i click
so i'm sorry to ask you but can someone join a vc with me so i can screenshare? you don't have to talk

modest dust
#

No one will join a vc, explain your issue here, send a video if necessary

mortal ginkgo
#

but what screenshot do i show?

modest dust
#

Show the related !code and the issue you're facing with it

eternal falconBOT
mortal ginkgo
#

i don't even know if the thing i need is about code or just unity menu stuff

modest dust
#

Well, you're asking about executing an attack on click, seems like a code issue from that alone

#

What are you having an issue with? Executing the attack, making the click work (old/new input system)?

mortal ginkgo
#

how do you want me to show my code exactly?
do i take a screenshot or do i copy paste it here?

modest dust
mortal ginkgo
#

public class Melee1Attack : MonoBehaviour
{
    [SerializeField] public Animator anim;

    [SerializeField] public float meleespeed1;

    [SerializeField] public float damage;

    float timeUntilMelee1;


    private void Update() {
        if (timeUntilMelee1 <= 0f) {
            if (Input.GetMouseButtonDown(0)) {
                anim.SetTrigger("Attack1");
                timeUntilMelee1 = meleespeed1;

            } else {
                timeUntilMelee1 -= Time.deltaTime;
            }

        } } 

        private void OnTriggerEnter2D(Collider2D other) {
            if (other.tag == "Enemy") {
            // other.GetComponent<Enemy>().TakeDamage(damage);
            Debug.Log("Enemy hit");

             }

    }





}```
modest dust
#

format it correctly, the first using statement should be in a new line

#

```cs
// code here
```

rough lynx
#

Wrong symbol it's ` lol

modest dust
#

```, not ''' ...

mortal ginkgo
#

damn

rough lynx
#

Under your esc key for US and UK keyboard

mortal ginkgo
#
// using UnityEngine;

public class Melee1Attack : MonoBehaviour
{
    [SerializeField] public Animator anim;

    [SerializeField] public float meleespeed1;

    [SerializeField] public float damage;

    float timeUntilMelee1;


    private void Update() {
        if (timeUntilMelee1 <= 0f) {
            if (Input.GetMouseButtonDown(0)) {
                anim.SetTrigger("Attack1");
                timeUntilMelee1 = meleespeed1;

            } else {
                timeUntilMelee1 -= Time.deltaTime;
            }

        } } 
rough lynx
#

Awesome

mortal ginkgo
#

yay i did it

modest dust
#

Alright, now, what exactly is the problem? Is the animation not starting?

mortal ginkgo
#

when i click nothing happens

modest dust
#

Just to be sure, you're pressing the left mouse button, right?

mortal ginkgo
#

yes

modest dust
#

Put a Debug.Log just before you call SetTrigger to make sure it's actually called

mortal ginkgo
brazen cedar
#

this is the error

modest dust
rough lynx
#

Also gonna need to see the line from the script called iloveyouGod lol

brazen cedar
#

this is the error

rough lynx
#

I need to see the line of code not the error

brazen cedar
#

ok

mortal ginkgo
#

i need what it would look like complete so i stop being dumb

#

sorry

modest dust
#

It's literally... the entire Update method

#

You can just replace the existing one if you're struggling with it for some reason

#

But essentially I just added one line before anim.SetTrigger

mortal ginkgo
#

still nothing happening when i left click

modest dust
#

Show your current code

rough lynx
#

Wait just to be sure

#

Did you actually put your script on an object

#

All of that code looks functional

mortal ginkgo
#

it's on the player character

#
// using UnityEngine;

public class Melee1Attack : MonoBehaviour
{
    [SerializeField] public Animator anim;

    [SerializeField] public float meleespeed1;

    [SerializeField] public float damage;

    float timeUntilMelee1;


    private void Update() {
        if (timeUntilMelee1 <= 0f) {
            if (Input.GetMouseButtonDown(0)) {
                Debug.Log("Left mouse button pressed, animation should start...");
                anim.SetTrigger("Attack1");
                timeUntilMelee1 = meleespeed1;

            } else {
                timeUntilMelee1 -= Time.deltaTime;
            }

        } } 
rough lynx
#

The brackets are throwing me off lol hold on

modest dust
#

Then place another debug, right before the first if statement, to log the value of timeUntilMelee1

#

Debug.Log($"Time left: {timeUntilMelee1}");

mortal ginkgo
#

(it's not making any errors)

rough lynx
#

Could it be this

#

I think you're putting the else a bit too late in

modest dust
#

oh wait, the brackets threw me off too

rough lynx
#

This is basically saying if timeUntilMelee1 is less than zero and we're not clicking then decrease the timer

mortal ginkgo
#

let me send the full thing sorry

#
// using Unity.VisualScripting;
using UnityEngine;

public class Melee1Attack : MonoBehaviour
{
    [SerializeField] public Animator anim;

    [SerializeField] public float meleespeed1;

    [SerializeField] public float damage;

    float timeUntilMelee1;


    private void Update() {
        if (timeUntilMelee1 <= 0f) {
            if (Input.GetMouseButtonDown(0)) {
                Debug.Log("Left mouse button pressed, animation should start...");
                anim.SetTrigger("Attack1");
                timeUntilMelee1 = meleespeed1;

            } else {
                timeUntilMelee1 -= Time.deltaTime;
            }

        } } 

        private void OnTriggerEnter2D(Collider2D other) {
            if (other.tag == "Enemy") {
            // other.GetComponent<Enemy>().TakeDamage(damage);
            Debug.Log("Enemy hit");

             }

    }





}
modest dust
#

Yeah, the else shouldn't be nested inside the first if, it should be after it

mortal ginkgo
#

i need to see it

modest dust
#
    private void Update() 
    {
        if (timeUntilMelee1 <= 0f) 
        {
            if (Input.GetMouseButtonDown(0)) 
            {
                Debug.Log("Left mouse button pressed, animation should start...");
                anim.SetTrigger("Attack1");
                timeUntilMelee1 = meleespeed1;
            } 
        } 
        else // If timeUntilMelee1 > 0f
        {
          timeUntilMelee1 -= Time.deltaTime;
        }
    } 
#

Your code checks if timeUntilMelee1 is less or equal to zero, and if that's true then it goes deeper, checks if you press the mouse button, otherwise decreases the time left

mortal ginkgo
#

i was following a guide and his brackets looked like that so to not confuse myself i made it the same

modest dust
#

Show me the guide

mortal ginkgo
#

it was exactly what i needed so uhh

modest dust
#

timestamp?

mortal ginkgo
#

idk

rough lynx
#

9:18 is probably what you want

#

I think your brackets were a tad bit off

mortal ginkgo
#

the first 10 minutes

modest dust
#

Alright I see it

#

Yeah, if you compare the two, it's not the same

mortal ginkgo
#

oh so it's my fault sorry

modest dust
#

the else corresponds to the first if, not the nested one

real grail
#

Also if you are gonna follow the tutorial like that try to understand the code that is given to you and not just copy paste πŸ˜„

mortal ginkgo
#

i was trying to

modest dust
#

The brackets are even colored differently here depending on how nested they are

mortal ginkgo
#

ah

modest dust
#

It's blue for both the first if and else

mortal ginkgo
#

umm...
it's still not working

modest dust
#

Show your code

mortal ginkgo
#
//using Unity.VisualScripting;
using UnityEngine;

public class Melee1Attack : MonoBehaviour
{
    [SerializeField] public Animator anim;

    [SerializeField] public float meleespeed1;

    [SerializeField] public float damage;

    float timeUntilMelee1;


    private void Update() 
    {
        if (timeUntilMelee1 <= 0f)
        {
            if (Input.GetMouseButtonDown(0))
            {
                Debug.Log("Left mouse button pressed, animation should start...");
                anim.SetTrigger("Attack1");
                timeUntilMelee1 = meleespeed1;

            }
        }
        else
        {
            timeUntilMelee1 -= Time.deltaTime;
        } 
    } 

        private void OnTriggerEnter2D(Collider2D other) {
            if (other.tag == "Enemy") {
            // other.GetComponent<Enemy>().TakeDamage(damage);
            Debug.Log("Enemy hit");

             }

    }





}
modest dust
#

Are you getting the log message?

mortal ginkgo
#

what?

#

yes

modest dust
#

The Debug.Log that's right before SetTrigger, is it appearing in the unity console

#

If yes, then are there any errors or warnings?

mortal ginkgo
real grail
#

Then its working ?

mortal ginkgo
#

animation is not playing

hexed terrace
#

Why is your anim called Attack1 but the tutorial is called Attack ?

mortal ginkgo
#

brb

brazen cedar
#

pls can some one help my code is not working

hexed terrace
#

That string has to be exactly correct, if it doesn't match what's setup in the animator controller.. then it won't do anything

hexed terrace
eternal falconBOT
brazen cedar
#

this is my code

modest dust
brazen cedar
#

this is the error

modest dust
modest dust
#

Dear lord

hexed terrace
mortal ginkgo
brazen cedar
modest dust
# brazen cedar pls explain again

Your Animator does not have a parameter called Velocity but for some reason you're getting a hash from "Velocity" and trying to use that

hexed terrace
#

not the code you shared

modest dust
modest dust
#

I struggle to find what you can't understand in that

brazen cedar
#

I CHANGED IT TO VELOCITY Z

modest dust
#

Sure, but the code you keep on sending still uses Velocity, not Velocity Z

mortal ginkgo
modest dust
#

Alright, this might actually be the first time I'm blocking someone here.

modest dust
eternal falconBOT
#

:teacher: Unity Learn β†—

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

modest dust
mortal ginkgo
#

ok

brazen cedar
modest dust
modest dust
#

What about "stop asking me" is unclear to you?

mortal ginkgo
#

sooo
back to me...

modest dust
# mortal ginkgo ok

What you can do is open up the animator controller for the player, start the game, and press the player instance with the Animator on it, that should show you the current state of the animator belonging to that instance of the player if I remember correctly...
Then press the left mouse button while looking at the animator to see if it changes.

modest dust
#

Also send a screenshot of the animator

mortal ginkgo
modest dust
#

Show the transition for Any State -> Melee

#

and Melee -> New State

mortal ginkgo
#

so it's only letting me click one a second which is intended
and now that i look at this it doesn't look right

#

ok

mortal ginkgo
modest dust
#

When you look at the animator, does it go through the entire Melee animation? That is, does the progress bar go from 0 all the way to 1?

brazen cedar
#

it is still not working

modest dust
#

Also send the inspector for the Melee state

mortal ginkgo
modest dust
#

Check if the Animation frames are set up correctly

brazen cedar
#

i changed it

mortal ginkgo
mortal ginkgo
#

hold on it uhhh

#

@modest dust so the swing attack is spawning in front of the player character and not where he's aiming

modest dust
#

That seems like a separate issue, show the code for instantiating the swing attack

mortal ginkgo
#
// using Unity.VisualScripting;
using UnityEngine;

public class Melee1Attack : MonoBehaviour
{
    [SerializeField] public Animator anim;

    [SerializeField] public float meleespeed1;

    [SerializeField] public float damage;

    float timeUntilMelee1;


    private void Update() 
    {
        if (timeUntilMelee1 <= 0f)
        {
            if (Input.GetMouseButtonDown(0))
            {
                Debug.Log("Left mouse button pressed, animation should start...");
                anim.SetTrigger("Attack1");
                timeUntilMelee1 = meleespeed1;

            }
        }
        else
        {
            timeUntilMelee1 -= Time.deltaTime;
        } 
    } 

        private void OnTriggerEnter2D(Collider2D other) {
            if (other.tag == "Enemy") {
            // other.GetComponent<Enemy>().TakeDamage(damage);
            Debug.Log("Enemy hit");

             }

    }





}
modest dust
#

That's only triggering the animation, there is no aiming involved here whatsoever

#

Nor there is any spawning happening here

mortal ginkgo
#

i have a cursor the circles around the player aiming at the mouse

#

how do i attach the attack to it?

hexed terrace
#

Aren't you following a tutorial? Surely you should carry on with that, it will probably eventually tell you

mortal ginkgo
hexed terrace
#

If it works in the tutorial, you did it wrong, or missed something .. go back and do it again

mortal ginkgo
#

hold on i'm waiting for caesar's response

modest dust
#

Well, your cursor and your attack are probably separate entities I would assume. You'd have to adjust your attack to whatever state your cursor is currently in... but if it's part of the tutorial then your answer should be there.

mortal ginkgo
#

give me a couple of minutes and try to figure it out with the tutorial

#

i wanna cry

mortal ginkgo
hexed terrace
#

the tutorial shows you how to do it

mortal ginkgo
hexed terrace
#

no one here can show you.. it'll take more time than we have to learn your setup, work out the implementation for it, and type it up

hexed terrace
mortal ginkgo
hexed terrace
#

You're not following it exactly as it is - you called your animation Attack1 instead of Attack for example.

Follow it to the letter, and don't skim anything

mortal ginkgo
#

damn

mortal ginkgo
hexed terrace
#

such lies

mortal ginkgo
#

WATCH THE VIDEO

modest dust
#

The tutorial shows you how to rotate it.. although from the first seconds of it I can see him rotating the weapon, you're on the other hand rotating the cursor. So if your weapon and cursor are separate then simply copy the rotation of the cursor onto the weapon. Or attach the weapon to the cursor.

#

If your cursor rotates, then he did in fact show how to turn it

mortal ginkgo
#

damn

modest dust
#

Then... you're turning the wrong thing

mortal ginkgo
#

damn

modest dust
#

Show the hierarchy

#

player, cursor, weapon, etc

mortal ginkgo
modest dust
#

Just... attach Melee1 to CursorNotScript, and make it so that it aligns correctly

mortal ginkgo
modest dust
#

or to RotatePoint

mortal ginkgo
modest dust
#

It shouldn't matter where you attach it.. unless you're deactivating certain gameobjects when you start the attack

#

if you parent the attack under the cursor but deactivate the cursor then obviously the attack will also deactivate, etc

mortal ginkgo
#

i'm gonna have a heart attack before someone vc's with me and shows me things

modest dust
#

If you don't want to change the hierarchy then copy the rotation from RotatePoint onto Melee1, making sure that it acts as a rotation point for GFX

mortal ginkgo
#

i give up

#

i shall return to unity another day

modest dust
#

Taking a break is also an important step of the process.

steady locust
rugged beacon
#

i have taken a week break before, looking back to current project like alien

steady locust
#

Then realizing you named your scripts Testv1 and whatnot

random iris
#

hi, can someone tell my why the counter still goes up even when button is clicked?

public class UIBlock : MonoBehaviour
{
private int counter = 0;
[SerializeField]
private Button button;
[SerializeField]
private TextMeshProUGUI text;

// Start is called before the first frame update
void Start()
{
    button.GetComponent<Button>();
    text.GetComponent<TextMeshProUGUI>();
}

// Update is called once per frame
void Update()
{
    // Check if there is a touch
    if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)
    {
        // Check if finger is over a UI element
        if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
        {
            Debug.Log("Touched");
            counter = counter + 1;
        }
    }

    text.SetText(counter.ToString());
}

}

timber tide
#

what button method

#

Should just use the button component

cosmic dagger
eternal falconBOT
wintry dew
rich ice
#

when i use the code snippet for switch, in visual studios, there's a case for default at the bottom. what is that used for?

wintry quarry
rich ice
#

oh right, i normally use it with enums, forgot that might be needed for ints or something though

wintry quarry
#

It's for anything

#

Enums are just ints anyway

random iris
rich ice
topaz sandal
#

oh sry about mis posting

#

I saw that I should not ask in multiple channel.. So I'll delete it in this channel then
thx for notice me!

warm jackal
#

!code

eternal falconBOT
tulip stag
#

Continuing what I was saying in #πŸ’»β”ƒunity-talk

Right now I’ve reached two points in my Unity project that I think events would help.

The first is in my 'Helper' classesβ€” I have a set of static classes that modify POCOs instead of accessing the POCO directly to change it. For instance, I can call SourceHelper.SetName(source) and the name is set. Sure. I think an event system would be nice to call the other functions that are meant to be run every time you change a variable of these POCOsβ€” for instance, the variable PB that’s set by SheetHelper.SetPB(sheet) is used in a lot of player stat calculations; so whenever the SetPB function is called it should send an event that lets other scripts know they should recalculate anything that depends on PB.

Another implementation I think I need, way more straightforwardβ€” Im working on a custom editor for such POCOs, and I’d want the editor to call these helper functions instead of directly modifying the POCOs. I did some research and apparently the only way to do this is with unity events

wintry quarry
tulip stag
#

Sorry I mispokeβ€” I meant a property drawer, but I think the implementation is the same for both

#

But yeah, thanks!

last radish
#

I am trying to make a simple ai enemy using navmesh, however, i dont know how to bake the surface. I do not actually have any surfaces until the game is started because i have a maze generator that spawns everything in. How do i bake a navmesh at runtime?

last radish
#

Wait and is there anything else to do? like do i just put public void BuildNavMesh() into any script that runs at runtime and then the ai will work?

wintry quarry
snow cloak
#

whats the easiest way to implement vertical movement

#

im trying to recreate pong

rich adder
#

velocity

snow cloak
#

yea i added that

last radish
rich adder
#

creates the area your agents walks on

last radish
#

to what do i add that component?

neon forum
#

For the load method I use, I clear my grid and replace it with gameObj, this works, and is able to make 1:1 replicas as far as I can see.

the current issue atm is that my 2draycast collider doesn't find anything, even when clicking on the new gameObj's spawned, with the function that uses the raycast2d collider saying the following error

#

what am I doing wrong here?

rich adder
#

empty one is fine

#

read the options on the Object Collection to how you want to bake

last radish
#

oh okay

rich adder
rich adder
# last radish oh okay

link it in the inspector to run that function after generating maze
[SerializeField] NavMeshSurface navSurface;
void Method(){ navSurface.BuildNavMesh();

last radish
#

the namespace NavMeshSurface could not be found

rich adder
last radish
#

i do have the navmeshsurface component so idk why thats happening

rich adder
wintry quarry
neon forum
last radish
#

oh sorry, i did have using unity.ai, without the .navigation

neon forum
#

The original game OBJs are deleted and replaced with new game OBJs that are stored in a dict with the key being their x,y

rich adder
rich adder
#

dont just copy the correct one off mine lol

last radish
#

no dw i got it from mine

#

i just didnt expand the show potential fixes

rich adder
#

yea ok. Cause that part is probably even more important than code you writing lol

final scarab
#

Hello everyone, can I ask a short quick question?

rich adder
#

nah delete these use a paste site

#

πŸ‘‡ here

eternal falconBOT
final scarab
#

I want to create an Android game and I have a problem. Everything looks good on the computer until we enter the settings. I am a beginner and I do it 4fun, thank you in advance for your help haha

final scarab
#

Oh sorry, but also thank you ❀️

neon forum
rich adder
neon forum
# rich adder so which line is throwing NRE ?

this one

 hit.collider.gameObject.GetComponent<SpriteRenderer>().sprite = _draggedObj.GetComponent<SpriteRenderer>().sprite;

The first time I try to get a component from the hit gameObj it gives me an err

rich adder
#

put at very least inside an if(hit != null) statement

#

its either hit is null or it did find something that doesn't have SpriteRenderer or _draggedObj i null

#

most likely the former

#

why its null thats for you to find out, but you shouldn't be doing anything outside of a null check unles you know beyond a doubt its going to always be 100% not null

verbal dome
#

It's a struct so it can't be null

#

but it has an implicit bool comparison

rich adder
#

ya normally its struct and never null

verbal dome
#

Normally? Always

neon forum
rich adder
#

unless nullable πŸ€“

wintry quarry
wintry quarry
#

or if (!hit)

neon forum
#

it threw an error

wintry quarry
#

yeah because you did hit.collider.gameObject without checking

neon forum
#

I tried if(hit) and now it's not running, so it's definitely false

rich adder
#

thats why it was null

wintry quarry
#

you cannot access that .gameObject until you do if (hit) or if (hit.collider != null)

rich adder
#

it didnt hit

neon forum
#

but how is it not hitting anything? my mouse pointer is literally on the game obj

verbal dome
#

Should also only raycast when you click, since you don't seem to be using the hit otherwise

rich adder
#

that screentoworld looks sus

wintry quarry
rich adder
#

itsnt for 2D better using intersect ot whatever

wintry quarry
#

yeah they're using that aren't they?

#
        RaycastHit2D hit = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition));
rich adder
#

Oh right im blind forgive me

wintry quarry
#

but yeah all of the rest should be inside the check

neon forum
#

the first image is initial creation and the 2nd image is post load method

wintry quarry
#

on the second

neon forum
#

dies

#

why is it always the stupidest things

rich adder
#

fr

neon forum
#

is there a quick "enable all components of this gameObj" method?

rich adder
#

You could foreach them but sounds like you need to fix it where you set it to disabled no ?

neon forum
#

but I never set it to disbaled

rich adder
#

well something is

neon forum
#

well since I'm already doing an instantiation of them from my dict tileStorage(for looping already), there shouldn't be anything wrong just enableing that component in that same loop

verbal dome
#

Are you sure you aren't enabling/disabling the boxcolliders instead?

rich adder
neon forum
#

I have no method that disables boxcolliders

verbal dome
#

Show the tile prefab

rich adder
#

not sure how unity would just set .enabled = false by itself unless a specific reason
I only know Start() disables the script checkmark if NRE occurs there.

neon forum
#

tile prefab here, it's enabled

#

mind you, the intial load has all the tiles enabled using instantiate

#

for load, I instantiate a gameObj from a dictionary, so maybe the dict doesn't hold enabled?

#

just ran the code, brute forcing enabled to be true after all the other methods fixed it

rich adder
#

dictionary has no control over that

neon forum
#

I thought so

#

does setActive tamper with components when using it on a gameObj? No, right?

rich adder
#

maybe you could send the entire Tile script and what instantiates it through link, we can take a look if anything is a miss

neon forum
#

okay, I will do that

neon forum
#

and this is the script attatched to the tile prefab

rich adder
neon forum
#

If you are, then I am as well. I have no clue how c# does dict when it comes to the specifics

rich adder
#

_tilePrefab are you 100% sure the one you linked in the inspector is the correct prefab with the component enabled?

neon forum
#

yes, I double clicked it

rich adder
#

the dictionary just stores the object, it shouldnt touch the components

neon forum
#

double checked it*

rich adder
#

hmm yeah unless at some point the one stored gets touched, updateTile() or something

neon forum
#

oh, rats.

rich adder
#

you should also start using Components rather than GameObject type

#

if you have Tile you shouldn't need to store them as GameObject, you can directly use Tile

neon forum
#

that was the thing I was trying to attempt, but I can't convert gameObj hit by the raycast to a tile

rich adder
neon forum
#

ah I had no idea there was a trygetcomponent, I tried try/catch but it complained lol

#

let me make some adjustments

rich adder
#

out is the result stored if the if returns true

neon forum
#

wait, tile is a component?

rich adder
#

if it inherits from MB yes

neon forum
#

I thought it was a subtype of gameobj

rich adder
#

GameObject is just a container, think like a Box that holds all the components in it

neon forum
#

right, which is how it can be empty

rich adder
#

except for Transform but yeah

#

GameObject and Transform are basically inseparable best friends lol

#

so through any component you can access both
tile.gameObject & tile.transform

neon forum
#

that makes sense... since every gameobj MUST have a transform, the transform is guaranteed to exist/have functioning methods

#

now I'm trying to serialize the dict into a json and export it as a save file

#

unfortunately, I already wrote code for this, and I'm looking at it and it's illegible

#

this is a travesty

steel smelt
rich adder
#

there is an official release

#

This repository was archived by the owner on Oct 6, 2023. It is now read-only.

neon forum
#

so do I just add this through the package manager?

steel smelt
#

Ah, been a while since I had to use

rich adder
neon forum
#

okay I added it

rich adder
neon forum
#

it's over

rich adder
#

i accidentally cut the c from .com lmao

#

myb. fixed

#

everything is pretty much same as JsonUtility

neon forum
#

ah got it, I just need to replace it with JsonConvert

rich adder
#

yup

neon forum
#

does it have an export?

rich adder
#

wdym an export?

neon forum
#

like an export method to create a json file and insert it into a specified folder?

rich adder
#

SerializeObject makes the json string

#

well you use System.IO there same as you would in JsonUtliity

#

this just converts an object into a json string and vice versa

#

(this doesn't auto create folders so be aware of that)

last radish
undone dragon
#

can anyone help me out with this physics based movement? im following a tutorial and i did the code right but its saying theres an error. someone please help https://www.youtube.com/watch?v=f473C43s8nE

FIRST PERSON MOVEMENT in 10 MINUTES - Unity Tutorial

In this video I'm going to show you how to code full first person rigidbody movement. You can use this character controller as final movement for your game or build things like dashing, wallrunning or sliding on top of it.

If this tutorial has helped you in any way, I would really appreciate...

β–Ά Play video
#

errors are in the bottom

rich adder
#

use links to share code

rich adder
#

at some point they created that float and you didn't

undone dragon
#

he js never mentioned a airmultiplier

rich adder
undone dragon
rich adder
#

either that or the tutorial is bad

undone dragon
#

im new to coding

rich adder
#

its a float

undone dragon
#

mb im trying to use big boy words in this new stuff

#

first time developing

rich adder
#

float = decimal number

#

it not a big word

#

its a math word

undone dragon
#

big boy words

verbal dome
undone dragon
#

πŸ˜‚

#

ill rewind a minute or 2

last radish
#

atleast i think so

rich adder
undone dragon
#

ill see if i missed sum bc the comments are all thanking him

rich adder
#

many people come with that video here, dont think that has ever been issue

undone dragon
#

its a great tutorial

#

alrighty time to lock in

#

thank u @rich adder

rich adder
#

must be if its popular lol

verbal dome
rich adder
#

oh nvm its a horrid tutorial

verbal dome
#

(from that video)

last radish
#

idk why i found the tutorial bad

undone dragon
rich adder
undone dragon
#

oop

rich adder
#

You never want to multiply your mouse Input by Time.deltaTime

#

you mouse delta is already the distance moved between each frame

#

therefore its already frame-rate independent

undone dragon
#

thats what i heard from yesterday

#

i followed the same tutorial

undone dragon
last radish
#

also im not exactly sure what i was meant to attach to the navSurface field in the navmesh script

undone dragon
rich adder
last radish
#

How to check both?

rich adder
# last radish How to check both?

start with checking if it even baked it correctly.
pause the game or switch into scene view after regen, and see if its blue and correct

last radish
#

im in scene view with show navmesh activated and it is infact not blue

#

nothing is baked in that case

undone dragon
#

no way now my jumping is bugged

#

i even configured settings right and there are no errors in the code

#

🀦 game dev is so hard

rich adder
undone dragon
#

i feel for the ppl who are professional game devs

rich adder
rocky canyon
#

its not really hard as much as "involved"

rich adder
#

thats development for ya

undone dragon
#

mhm

#

well im too invested now

#

already planned out a whole game

rocky canyon
#

hellz yea!

rich adder
#

that could take years

rocky canyon
#

have u got to teh scope creep part?

rocky canyon
undone dragon
rocky canyon
#

good on you πŸ‘

last radish
#

hmm didnt have this before

last radish
#

yessir

#

atleast something similiar

rocky canyon
#

yea somethings wrong with ur entire navmesh surface..

verbal dome
#

It will be stuck calculating a path

rich adder
rocky canyon
#

the error means ur navmesh agent isn't even near a navmesh

rich adder
#

there isnt even a reference runnign Bake on

last radish
last radish
rich adder
#

lets not jump ahead..

#

you didnt even bake it..

#

how you expect anything to move on it

rocky canyon
last radish
rich adder
#

you put the field there, and never ran the method cause it would be also NRE

rich adder
#

this would throw a NRE

last radish
#

oh okay

#

so what do i do

rich adder
#

link the reference?

#

drag n drop

#

Your enemies should wait for an event. / bool before starting the SetDestination

last radish
#

so i drag the navmeshsurface on the navmesh game object into the navmesh field on the scriot?

rich adder
#

the script component wants to know which navmesh surface you want to run BuildNavMesh on
it just knows "I have this navmeshsurface , I want to bake on"
computer: Okay WHICH one do you want to bake

undone dragon
rich adder
eternal falconBOT
undone dragon
rich adder
#

this needs to be degugged

undone dragon
rich adder
#

you have 3 conditions which may affect that from running

#

debugging is the process of verifying each one isnt contributing to the issue

undone dragon
#

alrighty

#

lets hope i dont break something notlikethis

#

scary stuff

rich adder
#

Debug.Log inside the if statement to see the function runs at all..

undone dragon
#

it js confuses me how he did all of those and it didnt break for him

rich adder
undone dragon
#

so delete one at a time to see which one isnt contributing

rich adder
#

NO

undone dragon
#

wait what

rich adder
#

why would you delete them?

undone dragon
#

oh so how do i run that code

rich adder
#

wdym how?

undone dragon
undone dragon
#

debug.log

broken nest
#

Hey, I dont know if I should make one big scene with everything in it or different small scenes. What's the pros and cons? I don't think that having every objects loaded at once would be that much of issue considering it's a rather small game

rich adder
# undone dragon the debug.og

First you see if its not printing the Log you know if statement is the problem, then you can verify each one before if statement

undone dragon
#

please

undone dragon
#

wait i got it

rich adder
undone dragon
#

i think i js simply missed a space

#

i checked the lightbulb to the left

#

it said fix formatting

#

wasnt it

rich adder
#

no

#

there is no compile errors

undone dragon
#

where would i put the method

rich adder
#

thats only thing to wrroy about

rich adder
undone dragon
#

fixed it

#

it needed to be unityengine.debug.log

#

wait so if it doesnt log in the console, is that make it the bad one

rich adder
rich adder
#

so jump() will not run

undone dragon
#

like literally nothing

rich adder
#

yes thats why we established its not printing then its not running

undone dragon
#

now i gotta find out why its not printing

rich adder
rich adder
#

jumpkey will just give you a Keycode, that isn't useful

undone dragon
#

well nothings coming thru with anything

#

i did all of those

rich adder
#

because if statement isnt running

undone dragon
#

readyToJump, grounded, and jumpKey were all in there

rich adder
#

meaning one of those is false when you press JumpKey

rocky canyon
#

run the debugs b4 the conditional πŸ˜‰

rich adder
#

most likely grounded

undone dragon
rich adder
#

yes.. because there are 2 other bools

undone dragon
undone dragon
rich adder
#

so you need to verify their values at the time Space is pressed

undone dragon
#

so how would i go across that with it being all weird and not logging on the console

rocky canyon
rich adder
#

Debug.Log($"ready to jump : {readyToJump}; is grounded : {grounded}");

rocky canyon
#

^ consolidated

undone dragon
#

this brings that error tho

rocky canyon
#

u have a using statement u dont need

rich adder
rocky canyon
#

^ get rid of that garbage ur not ready for that yet

undone dragon
undone dragon
rocky canyon
#

the using statement

rich adder
#

at the top of the class

rocky canyon
#

this means BOTH of those using statement have a Debug

#

it doesnt know which one ur wanting to use

undone dragon
rocky canyon
#

so remove the SYstem one.. b/c not sure why u even have that

#

keep UnityEngine

#

remove the System or System.Diagnostics or w/e u have extra

undone dragon
#

how do i remove the system one

#

oh i see it

#

delete this thing?

#

the first one?

rocky canyon
#

pay close attention πŸ‘€

rich adder
undone dragon
#

alright

undone dragon
#

i deleted it

rich adder
#

did you put it before the if statement?

#

are the inputs working?

undone dragon
rich adder
#

jesus..

#

before the If statement

undone dragon
#

OMGGGGG

rich adder
#

me and someone else said that

#

pay attention

undone dragon
#

🀦

rich adder
#

we already established if statement isn't hitting, put anything new in there is moot

undone dragon
#

i thought u meant in the if statement

rich adder
#

nah cause if its not hitting , the condition values before it need to be verified

undone dragon
rich adder
#

You cant do that if the log doesnt run

undone dragon
#

what is that mean

rich adder
#

it means you aint ready to jump

undone dragon
#

but im touching the ground and ground check should see that

rich adder
#

you reset jump in ResetJump()

#

but its never true otherwise

#

if Jump cant run, how can resetJump run?

#

readyToJump stays false

#

bool default value is false

undone dragon
#

hmmm πŸ€”

rich adder
#

willing to bet you missed that part at some point in the video

undone dragon
#

prolly right'

#

im rewatching the whole jump segment

#

thank u for dealing with my nonsense

undone dragon
#

do i switch to this?

rich adder
#

it tells you why right there ^

undone dragon
#

so switching the code is safe

rich adder
#

yes because its telling you to do it

undone dragon
#

alright sorry..

#

ill try to do the rest on my own

rich adder
#

if you use Ctrl + . / quickactions, it should help you replace them already

undone dragon
#

alright im gonna apply everything it wants me to apply

rich adder
#

lmk

last radish
#

sorry for being late again, i had to go to dinner, but the navmesh still isnt spawning.

rich adder
last radish
#

yep

rich adder
#

make sure the gizmos is on

last radish
#

you can see it ticked on the right

rich adder
# last radish

are you sure that function is
A: running
B: running at the correct time (aka after the build)

sand mesa
#

left click spins the minute hand, right click spins the hour hand

#

i managed to get the hour hand to work, but I htink its overriding the minute hand's collision

last radish
#

This is the code:
void Start()
{
Invoke(nameof(BuildNav), 1f);
}

void BuildNav()
{
    navSurface.BuildNavMesh();
}

}

#

so i think so

sand mesa
rich adder
rich adder
#

!screenshots

eternal falconBOT
#

mad No

Be mindful, if someone requests your code as text, don't send a screenshot!

rich adder
#

dont ever send code as screenshots

sand mesa
#

one sec

rich adder
#

use the proper way πŸ‘‡

eternal falconBOT
last radish
rich adder
#

use links

#

com on dude, no one wants a wall of text in discord. use the links provided.

#

hence the "Large code" section in the bot message

sand mesa
#

its inline!

rich adder
#

inline should be 4-5 lines max..

#

not an entire class

sand mesa
#

wouldnt code that goes over the char limit warrant large block?

rich adder
#

thats why there is a "Large Code" section. which an entire class is

rich adder
sand mesa
#

oh ffs

rich adder
#

easy

#

dont get kicked by bot

#

edit your message and put both links..

#

unless you got automuted already lol..

fickle plume
#

!unmute 386689882182909965

eternal falconBOT
#

dynoSuccess vagustruman was unmuted.

fickle plume
last radish
rich adder
last radish
#

sorry i dont really understand the question

sand mesa
last radish
#

wdym by added meshes into my level

#

like spawned the maze?

rich adder
last radish
#

the debug message does come one second after the maze is built, so if thats the question yeah

rich adder
sand mesa
#

I can move the hour hand with right click

#

but it overlaps the minute hand, which I control with left click

#

I set both box colliders to "is trigger" but its not helping matters

rich adder
rich adder
sand mesa
#

left click rotates minute hand, and then right click rotates hour hand

rich adder
#

yes I get that but what is the main issue

#

i dont get it

sand mesa
#

right click works, left click doesn't

rich adder
#

ohh I see

sand mesa
#

is it because im using raycast?

#

or something to do with box colliders?

rich adder
#

OverlapPoint is correct

sand mesa
#

yeah, theyre based on the z rotation of the images

rich adder
#

do a Debug to see whats actually overlap

sand mesa
#

whats the command?

#

the doc doesnt exactly say

rich adder
#

overlapPoint returns a Collider2D

#

so
var overlapHit = Physics2D.OverlapPoint(etc.. Debug.Log(overlapHit.name)

last radish
#

is there any chance that there is something wrong with the objects in the maze because of which it cant be baked?

#

like do they need to have some component maybe?

rich adder
#

you can try checking the asset it generated to see what kind of size it has and all that

#

(NavMeshData)

last radish
sand mesa
#

okay. so update: after putting the debug code in the if statements of each class, it returns that the right click is working

last radish
#

im pretty sure this is fine, as the maze is 10(.01)x10 and the hwight is 0.5

rich adder
#

seems like its baking something big enough

#

are you sure gizmos are selected?

rich adder
#

did you verify the important part? aka printing what Physics2D. is grabbing?

last radish
last radish
# last radish

and also ofcourse if navmesh is checked but its all the same as in thsi screenshot

sand mesa
rich adder
sand mesa
#

just those two variables are what dictates if it rotates

#

so why is one overriding the other based on physics?

rich adder
#

is actually grabbing anything at all to rotate on

last radish
#

and anyway i doubt it, as the ai is still "too far" from any navmeshes

rich adder
last radish
#

yep its all checked

rich adder
sand mesa
rich adder
#

you have to PRINT what is actually grabbed

sand mesa
#

debug is on bottom left

last radish
rich adder
#

also print which script is showing that

#

Debug.Log($"{name} says we grabbed : {grabbedItem}")

last radish
rich adder
sand mesa
rich adder
sand mesa
#

yes

rich adder
#

yes it works or yes it doesnt?

sand mesa
#

yes the one doesnt work

last radish
sand mesa
#

best assumption is that somehow the box colliders are cancelling one another and the hourhand collider is coming out on top

rich adder
#

I bet if you did -90 X on the Surface it could probably bake it

undone dragon
rich adder
#

if the surface is at -90 on X why would surface be 0

last radish
#

yep sorry my bad

#

one slight problem its a quad and the bottom doesnt have a texture

rich adder
#

navmesh surface only bakes at specific plane defined in the rotation

rich adder
#

but the surface needs to match the top

last radish
#

still doesnt work though

rich adder
#

even with one side / backface culling Unity bakes both sides

sand mesa
#

maybe my way of determining position is off?

rich adder
undone dragon
last radish
rich adder
last radish
#

it is a child of mazecell which is empty

rich adder
sand mesa
#
Vector3 mousePos = myCam.ScreenToWorldPoint(Input.mousePosition);
last radish
rich adder
#

make sure its the same position as your sprites

sand mesa
#

both z positions of the sprites are the same... one second

#

ill check

rich adder
last radish
#

what would that be

rich adder
#

thats mainly whats controlling how much force to push up

#

Air is just how much resistance you have in air

undone dragon
#

lemme try lowering it to 8

#

6 seems to be the sweetspot

#

thank u nav!

#

now i need a grappling system

rich adder
#

I think because its axis is fucking weird..

last radish
#

okay ill try to it with plane then

rich adder
last radish
#

i really hope it doesnt fuck up the maze

rich adder
#

before you do anything make sure you make a backups

#

When i bake with plane it works fine, the Quad doesnt bake

#

its axis being all fucked up probably has something to do with it

last radish
#

maze still works, but no baking 😦

sand mesa
#

okay weird discovery... its stuck in camera position

#

not folloiwng my mouse

rich adder
#

also -30 seems pretty sus

sand mesa
#

not really once I figured out what its actually tracking

rich adder
#

yes u wouldnt want that to be the mouse Z tho

#

your objects at are , ideally at Z of 0 ?

#

var mousePosWorld = Camera.main.ScreenToWorldPoint(etc. mousePosWorld.z = 0

#

I always do this

sand mesa
rich adder
#

not saying thats it 100%

#

while Z is mainly important for rendering sorting if you dont use Order in Layer, in 2D iirc for the Physics overlap Z is depth

#

maybe its not within that depth

last radish
#

oh also nav, forgot to mention but whether or not the quad was a part of the problem is slightly irrelevatn, as the walls (which are cubes) are not baked either

#

so there has to be a problem elsewhere

#

i actually have no clue why this is happening

#

losing my mind

rich adder
#

remember surface is only looking for a PLANE

sand mesa
#

... crap. Okay, mouse position has nothing to do with it, I think

last radish
#

oh nevermind me then

rich adder
#

its not gonna bake side of walls unless the navmesh surface was with the same rotation of wall

last radish
#

so i have to eventually once i get this working do another one for walls?

rich adder
sand mesa
#

maybe OverlapColidder is what I need

#

no that ant it

rich adder