#💻┃code-beginner

1 messages · Page 619 of 1

rich adder
#

or that

naive pawn
#

but you could also just make a struct that holds your values and make a list of that

rich adder
#

to tbh you can easily just make a List and custom struct

naive pawn
#

lmao

rich adder
#

jinx

fleet venture
#

sounds hard

naive pawn
#

really isn't

rich adder
#

nah its easy

fleet venture
#

i dont really know how structs work

rich adder
#

same as a class

naive pawn
#

do you know how classes work?

fleet venture
#

yes

#

its like diff with memory tho

rich adder
#

you use structs all the time

naive pawn
#

structs are classes but a little different

rich adder
#

Vector3 is a struct

fleet venture
#

oh

naive pawn
#

float is a struct

fleet venture
#

they are like value types

naive pawn
#

yeah

rich adder
#

its just for grouping fields and methods togther

fleet venture
#

is that the only difference?

naive pawn
#

value types and structs are synonymous in c#

rich adder
#

yea they live on the stack usually

fleet venture
fleet venture
naive pawn
fleet venture
#

stack instead of what?

#

heap?

rich adder
naive pawn
#

yes

rich adder
#

heap stores the address to the location

fleet venture
#

ohhhhh

rich adder
#

reference types

fleet venture
#

ye

#

thats the reference

#

makes sense

naive pawn
#

values of reference types are stored as references to the actual object, that's on the heap
values of value types are stored as the value directly

fleet venture
#

ah okay

rich adder
#

ofc you can do this with a class too..

fleet venture
#

ye

rich adder
#

i honestly prefer when working with reference types but thats just preference

naive pawn
#

local variables are on the stack, so if you have a local variable with a value type, the struct value is directly on the stack

fleet venture
#

but idk how i make it serializable

#

also i would have to use linq to filter or what?

naive pawn
#

you slap a [Serializable] on it

grand badger
#

Fixed yet?

fleet venture
#

no im working on it

#

but i mean if anormal dictionary works why cant i just use that?

grand badger
#

Damn.. alright ping if you need help

fleet venture
#

i mean im getting helped rn

naive pawn
grand badger
#

Yes but for the past hour or so xD

rich adder
#

so the idea is

public struct CustomProp {
public string Name;
public Prop TheProp; ```
fleet venture
#

only the editor script needs to assign permanent values

naive pawn
#

oh...ok

fleet venture
#

idk if it has to be serializable for that

naive pawn
#

i don't know your original issue lol, i was going with what nav said lol

rich adder
#

it could make it easier for sake of serializing into files

#

or showing / configuring future props in the inspector

#

so always good to use Serializable

fleet venture
#

cuz like that you have to use linq to filter which doesnt sound like its super ncie

grand badger
#

No. Custom serializable classes are easier to work with in Unity

rich adder
#

you can override your own == and all that

fleet venture
#

i mean i would want to have []

rich adder
#

or Contains

fleet venture
#

like how dictionaries work

fleet venture
#

the Name is the key

grand badger
#

It’s just dictionaries aren’t serializable by default

rich adder
#

you can do that with Contains too..

#

just make it look for the string instead

fleet venture
#

oh

rich adder
#

you implement the IComparer

#

i think thats what it was called

naive pawn
rich adder
#

my b just meant finding by object in general not Contains

#

pass the object but it looks for the name via string

fleet venture
#

is it possible to do like an operator overload in the struct though so i can just use [] like a dictionary?

fleet venture
naive pawn
#

no

#

that's a list method

fleet venture
#

it looks like it

#

oh

#

i thought it was on IEnumerable or whatever

#

hold up is === a thing in c#

naive pawn
#

nah this is too specific for linq

naive pawn
fleet venture
#

LMAO ok

#

good

#

i thought i fucked up all my code just now

naive pawn
#

didn't even notice that

fleet venture
#

ok let me try

#

so how do i fillthe list in here

naive pawn
#

btw, aren't fields usually camelCase

fleet venture
#

idk unity uses stupid naming

#

its diff from c#

#

and it confuses the hell out of me

#

c# uses stupid naming hto

#

java has a good naming scheme

#

C# is like

naive pawn
fleet venture
#

ok lets just make EVERYTHING PascalCase cuz why not

rich adder
#

thats because instanceId is a enum

fleet venture
#

classes are pascal case, properties are pascal case, public fields are pasdcal case, methods are pascal case, constants are pascal case

#

like STOP

#

its so stupid

naive pawn
#

i mean.. c# differentiates between interfaces and classes/enums...

not sure it's a very useful thing though

fleet venture
#

i think they are

#

in C#

naive pawn
#

public props are

#

not public fields

fleet venture
#

fields too i thought

rich adder
#

either way you should be making it a prop if its public

slender nymph
naive pawn
#

or... should those be properties..?

rich adder
#

I still make them pascal

slender nymph
#

doesn't matter, structs should still use properties for things that are public facing

naive pawn
#

damn

rich adder
#

but yeah if you gotta do it "correct" general opinion is to just use props

naive pawn
#

good lord

fleet venture
naive pawn
rich adder
slender nymph
#

if it is accessible outside of the object it should be a property so you can have fine control over how it is accessed and what happens when it is

sour fulcrum
#

[field: SerializeField] get; private set; is my default bread and butter

fleet venture
#

unpopular opinion, people are excessive with encapsulation

rich adder
#

that can work too. just makes an ugly backing field name for it @sour fulcrum

naive pawn
#

you could do theDictList.Add(new CustomProp() { Name = obj.Name, Prop = obj }); i think?

fleet venture
naive pawn
#

i don't remember the exact syntax there

fleet venture
#

idk how i get a reference to Room tho

naive pawn
fleet venture
#

the file name

naive pawn
#

so.. they do have names

fleet venture
#

yes they ahve names

naive pawn
#

why did you say no then lol

fleet venture
#

sorry i didnt realize

#

sometimes im a bit confused sorry haha

rich adder
naive pawn
sour fulcrum
#

Got enough perceivable problems anyway

naive pawn
#

might need semis

fleet venture
#

the issue is how do i get theDictList

naive pawn
#

you need to have it somewhere

fleet venture
#

no theDictList is located on the Room script in my scene

naive pawn
#

(and name it better)

fleet venture
#

idk how i get it in the editor script

naive pawn
#

ah that's what you meant

rich adder
#

making accessible through a Singleton or something

fleet venture
#

ye

#

noooo

#

i dont want to make this a singleton

#

i could but

rich adder
#

depends what needs access to it

fleet venture
#

a whole lot

#

but i dragged it in everywhere

rich adder
#

Singletons are very good if you have DDOLs and stuff
cross scene references etc

fleet venture
#

i dont rly want to change it everywhere

#

ye but this isnt a cross scene reference

#

its only used in the same scene

#

and i need to access it in the editor script

rich adder
#

as long as you have a reference linked then wahts the problem

fleet venture
#

how do i get it in the editor script

rich adder
#

the one from the scene?

sour fulcrum
fleet venture
#

i have a Room inthe scene that i need to access in the editor script

#

thats my question

rich adder
fleet venture
#

in Editor folder

#

directly in assets

rich adder
#

oh.. I thought you were doing the Menu Item thing

fleet venture
#

oh nah

#

that was confusing

rich adder
#

using an editor script is less confusing?

fleet venture
#

i thought that was the same thing honestly

rich adder
#

no

fleet venture
#

i just have this

rich adder
#

MenuItem lives on a MB

#

usually

#

it just makes it so it appears above your toolbar menu

#

where you see File,Edit, Tools, Help etc.

fleet venture
#

this IS a MB

#

should this not be a MB

rich adder
#

when you want to do stuff from a gameobject you need it to be MB to be attached

fleet venture
#

So i should do the MenuItem

#

so where do i put the function then?

rich adder
#

You want to toss this stuff in this same script, all your doing is using MenuItem so you dont have to drag them all..

fleet venture
#

inside of the ROom Class?

rich adder
#

though frankly you can just Mass select them and drop them in

fleet venture
#

and i would have to put 300 strings in myself

#

for the names

rich adder
#

You just loop through the items in the inspector , the process is the same

fleet venture
#

i am pretty lost as to what to do and where im at. How do i do the menu item thing

#

because apparently thats different from what im doing rn

#

oh i can run it like this if its a menu itme

rich adder
#

[serializefield] private Prop[] props; //drag n drop

then do
foreach(var prop in props){

if(prop.name.Contains("barrel")
barrelsList.Add(prop)

obv not real code but just the idea of it

#

or you need a nasty switch

fleet venture
rich adder
rich adder
#

unless you had like Enums for each Prop type, you have no choice but to check their name contains a specific thing to group them

fleet venture
#

my question still stands tho how do i get this instance field prefabs in the static fill method

grand badger
#

you can use a scriptable object (singleton)

fleet venture
grand badger
#

ScriptableObject singletons are super common in Unity -- especially for editor functionality or general configs

rich adder
grand badger
#

primarily because while you may choose to use it as a singleton, you may also opt to replace it with something else for whatever tests you might have in mind

fleet venture
#

would this work?

grand badger
fleet venture
#
[MenuItem("fill")]
    public static void Fill()
    {
        var objects = FindObjectsByType<Prop>(FindObjectsSortMode.InstanceID);
        var room = FindFirstObjectByType<Room>();
        foreach (var obj in objects)
        {
            room.prefabs.Add(new PropKeyValue() {name = obj.name, prop = obj});
        }
    }```
#

would this work?

fleet venture
#

thing is i use it in a lot of places

fleet venture
grand badger
fleet venture
#

kind of a pain

#

all to run this script 1 time

rich adder
#

wait.. why are you adding to the same object..

grand badger
#

you'd have done it 30-45 times in this 90 minutes you've been discussing about alternatives 😛

fleet venture
#

FindObjectsByType searches in both assets AND scene?

rich adder
#

oh nvm didnt see the Room part for some reason

fleet venture
#

wait FindObjectsByType doesnt work on asssets

#

so this wont work

rich adder
#

FindObjectsByType is only for loaded objects in memory

#

aka the scene

fleet venture
#

so how do i get all the prefabs then?

rich adder
#

I been saying use the inspecttor drag n drop but if you refuse to do that, use the method to find AssetDatabase

fleet venture
#

no i dont refuse to do that

#

i just do not understand

#

how

#

where do i drag it too

rich adder
#

You grab them ALL , CTRL + A

#

and in the same field of that editor script List<Props>

#

dont make the function static

fleet venture
#

oh i dont?

#

uh it doesnt like that

#

i dont have an editor script

#

i have the menuitem thign

#

i changed it like you said

rich adder
fleet venture
#

WHAT

rich adder
#

just use ContextMenu

fleet venture
#

oh

#

ok

rich adder
#

with static you cannot use fields from same class

fleet venture
#

so now i create a new thing

rich adder
#

replace the attribute from MenuItem to
[ContextMenu("MyCoolFunction")]

#

then right click component on gameobject, in the editor to run it

#

remove the Find part

fleet venture
#

ye i did remove that

#

omg ty it worked

#

thats great

#

this was so easy how was this so hard

#

this was 8 lines of code 💀

#

T-T

rich adder
#

probably a mix of misunderstandings lol

fleet venture
#

most definetly

small dagger
#

is there a better way for two script components of mine to reference the same script? Right now I have an audio manager script, but I also have a movement script that needs to reference it to play the movement sounds, and my collision handler script also accesses it to handle collision sounds, basically I just have them both get the component on start

grand badger
#

GetComponent on Awake() is the optimal method

small dagger
#

thanks

grand badger
#

np

small dagger
#

what is the difference between start and awake?

rich adder
#

Start for example cannot run if disabled script, Awake doesnt have disabling cause it will run as soon as object is active

timber tide
#

Awake -> as soon as the object is instantiated
Start -> Right before the first time it enters the update loop

#

Also start may or may not be called on the same frame so take that into account

small dagger
#

gotcha, thanks guys

rotund bolt
#

I clicked "enable Debugging" on this and now it has that setting everytime i press "attach to unity". how do i disable this setting?

rich adder
rotund bolt
#

yes

#

how do i disable that

#

maybe its just for this sessions like it says tho so maybe it iwll be gone when i close out and come back lemme try

#

it just makes saving my project when i make changes slower so its annoying to change something and then test it over and over

rich adder
rotund bolt
#

im gonna be real, i dont really know what the debugger does lol cus unity seems to work just fine when i click the "cancel" option 😭 so i just click cancel each time

rich adder
#

debugger is used for Breakpoints so it pauses at that point in the code, so you inspect values

hushed hinge
#

I happen to have a problem (while i have fixed the jumping which the player can jump normaly, but for the jumping frog power-up, when i hold down to charge up to perform a high jump, it doesn't perform a high jump for some reason. what do i do to fix this? or should i explain more?

private void FrogJump()
{

    if (Input.GetButton(_jump) && _isGrounded)
    {
        _jumpBufferCounter = 0;
        _coyoteTimeCounter = 0;
        _currentJumpForce += (Time.deltaTime * _currentJumpForceMultiplier);
        _currentJumpForce = Mathf.Clamp(_currentJumpForce, _jumpForce, _frogJumpForce);
        _ani.SetBool("Jump", true);
        _ani.SetFloat("JumpPower", (2 *_currentJumpForce)/ _frogJumpForce);
        _rb2D.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;
    }

    if (Input.GetButtonUp(_jump) && _isGrounded && _rb2D.velocity.y < 0.01f)
    {
        _jumpBufferCounter = 0;
        _coyoteTimeCounter = 0;
        _ani.SetBool("Jump", false);
        _rb2D.velocity = new Vector2(_rb2D.velocity.x, 0.0f);
        _rb2D.AddForce(new Vector2(0.0f, _currentJumpForce), ForceMode2D.Impulse);
        _currentJumpForce = 0.0f;
        _ani.SetTrigger("FrogJump");
        _as.Play();
        _isGrounded = false;
        _rb2D.constraints = RigidbodyConstraints2D.None | RigidbodyConstraints2D.FreezeRotation;
    }
    else if (Input.GetButtonUp(_jump) && !_isGrounded && _doubleJump)
    {
        _ani.SetBool("Jump", false);
        _doubleJump = false;
        _rb2D.velocity = new Vector2(_rb2D.velocity.x, 0.0f);
        _rb2D.AddForce(new Vector2(0.0f, _jumpForce), ForceMode2D.Impulse);
        _ani.SetTrigger("FrogJump");
        _as.Play();
    }
}
rich adder
hushed hinge
rich adder
#

!code

eternal falconBOT
hushed hinge
#
private void FrogJump()
    {

        if (Input.GetButton(_jump) && _isGrounded)
        {
            _jumpBufferCounter = 0;
            _coyoteTimeCounter = 0;
            _currentJumpForce += (Time.deltaTime * _currentJumpForceMultiplier);
            _currentJumpForce = Mathf.Clamp(_currentJumpForce, _jumpForce, _frogJumpForce);
            _ani.SetBool("Jump", true);
            _ani.SetFloat("JumpPower", (2 *_currentJumpForce)/ _frogJumpForce);
            _rb2D.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;
        }

        if (Input.GetButtonUp(_jump) && _isGrounded && _rb2D.velocity.y < 0.01f)
        {
            _jumpBufferCounter = 0;
            _coyoteTimeCounter = 0;
            _ani.SetBool("Jump", false);
            _rb2D.velocity = new Vector2(_rb2D.velocity.x, 0.0f);
            _rb2D.AddForce(new Vector2(0.0f, _currentJumpForce), ForceMode2D.Impulse);
            _currentJumpForce = 0.0f;
            _ani.SetTrigger("FrogJump");
            _as.Play();
            _isGrounded = false;
            _rb2D.constraints = RigidbodyConstraints2D.None | RigidbodyConstraints2D.FreezeRotation;
        }
        else if (Input.GetButtonUp(_jump) && !_isGrounded && _doubleJump)
        {
            _ani.SetBool("Jump", false);
            _doubleJump = false;
            _rb2D.velocity = new Vector2(_rb2D.velocity.x, 0.0f);
            _rb2D.AddForce(new Vector2(0.0f, _jumpForce), ForceMode2D.Impulse);
            _ani.SetTrigger("FrogJump");
            _as.Play();
        }
    }
hushed hinge
rich adder
polar acorn
#

See if it's giving the value you expect it to be

hushed hinge
polar acorn
hushed hinge
polar acorn
# hushed hinge

Okay, and is the value smaller if you don't hold it as long

hushed hinge
polar acorn
timber tide
#

Look up depth intersection shaders

hushed hinge
cerulean oyster
#

hi so the game im making uses a raycast to check if you are on the wall, ground etc. For some reason only when I build my triggers count as a wall which they shouldnt because bumping into the wall affects your score. It works fine in the editor but webgl and windows builds both have this issue. All im doing with these triggers is SceneManager.LoadScene() on the OnTriggerEnter2D. My Collison for my player is on continuous and I am checking for the player tag on the OnTriggerEnter2D method. it still loads the scene it's just counting as a hit prior. Ive been working on it for a few hours couldnt find anything but pretty new so probably missing something

frigid sequoia
#

I shouldn't be doing that remove inside a foreach loop right?

cosmic dagger
#

You need a reverse for loop . . .

frigid sequoia
#

I did that last time and I already forgot....

#

It's such a stupid inconvenience.....

#

Like looping a list and removing stuff on it is one of the most common things to do, Remove should support that

cosmic dagger
frigid sequoia
sour fulcrum
#

extra steps and text?

cosmic dagger
hushed hinge
frigid sequoia
#

It would make more sense to me

sour fulcrum
#

because by default they go forward and not backward?

#

Why would it make more sense for it to do it in reverse order by default

cosmic dagger
sour fulcrum
#

also aside from just following the convention of counting numbers it's also generally not the responsibility of something inside an iterating list to modify itself like that

#

eg. in your example it's "odd" that a function just meant to get something out of a specific given list and actually messing with the list. Not intending to dunk on your code just pointing out because it's not ideally a common issue people have

cosmic dagger
frigid sequoia
#

Sure, the use of search for X occurrence on the list and if it happens just move it outside the list is such an odd thing to do right?

#

Like I dunno, feels one of the basic things a list should do

hushed hinge
frigid sequoia
cosmic dagger
cosmic dagger
sour fulcrum
#

gotta understand the scale of how many iterations people use in this programming language and how comparatively uncommon it is to remove stuff from a iterating foreach while also being very trivial to handle that by iterating backwards instead. They aren't going to add additional processing cost for what's a very niche and non-issue

grand badger
#

@sour fulcrum if you wanna remove objects from the list, use an "reverse for" loop instead of foreach. Using a foreach loop would throw an exception when mutating it.

#

"reverse for" (is my ESL term lol) meaning you start from the end and iterate backwards as you mentioned. It's a very common practice when wanting to remove objects from a list.

-- and when you wanna add to it, using just a "standard for" loop.

velvet holly
#

@hushed hinge I think the problem is your code calls initateJump() at the start of each update. That method calls the method preformjump() which checks if you have released _jump button and sets _isgrounded to false. Then later in update, your code calls the movment() method which calls your frogjump() and _isgrounded is already set to false earlier

#

Also you should really consider smaller scripts. Jumping, moving, climbing, etc could all be different scripts cause they don't really need to know anything about each other

#

it makes issues like this 100x easier to debug

hushed hinge
sour fulcrum
velvet holly
#

@hushed hinge Honestly it's kinda hard to suggest exactly what to do because this script is doing so much. The issue I'm seeing is that handlejump() is handling your jump logic before your movement() method is called and so you've already performed a jump before your frog jump script is called

#

What I would do personally is moving jump logic into its own script. The only thing jumping needs to really know is if you're grounded. It doesn't need to be part of the script that handles all the other movement

keen inlet
#

Question for my game(I have no code rn about this topic yet, I've been organizing my plans and what order I should do things with the game dev. of my game)
I'm a beginner in coding kinda and doing stuff in Unity, I wanna know how can I make a reflectivity(aka rain that you see on usual radar apps) radar system where I can open a map and see rain/storms in areas, I have an idea on how to show the storms, but I don't have an idea on showing the map and storms in the exact correct position. So it would be helpful if someone explain how to code smth like this and how to do this stuff, because I can't find anything in tutorials that can be of use except tags

hushed hinge
velvet holly
#

@hushed hinge You'll have to change something around cause currently your code is trying to handle jump logic in multiple different places at different times during each update() cycle

hushed hinge
#

i don't know what to change....

velvet holly
# hushed hinge i don't know what to change....

Your issue is that handlejump() and InitiateJump() are called first thing in your update method, which then calls preformjump(). Then FixedUpdate() calls your Movement() method, which inside of that calls either preformjump() or frogjump() again. But since you already handled jump logic in update, _isGrounded is always gonna be false

#

When you write scripts that get into several hundred lines of code like this that do so many different things, you will run into issues like this a lot and it is a massive headache to debug because you have to look through several hundred lines of code rather than a couple dozen. And you're having to look past logic for unrelated things except sometimes those things do end up intertwining accidentally cause you haven't seperated them

hushed hinge
velvet holly
#

You should have them in different scripts entirely really. Have a script that only handles jumping. The only thing jumping needs to know is if you are grounded, so it doesn't need to exist with all this other code

#

For example, my project I'm working on, the longest script is 112 lines. Now line count in and of itself doesn't mean your code is doing too much, but it's a good indicator

hushed hinge
#

I had it like that before and it always worked. even the high jump always worked. but ever since adding in the buffer and coyote timer, some thngs doesn't seem right

velvet holly
#

Code always works until it doesn't. Your needs change and having code that's this hard to read through and maintain makes change near impossible as you are seeing now. What happens later when you add another suit that's a bird suit that lets you hold the jump button to fly up? Are you gonna add another couple hundred lines of code to this script? In the long run it will save you a ton of headaches if you make your individual scripts do less. There's nothing wrong with having multiple scripts attached to your player or whatever object

#

A rule of thumb I find is that I should be able to write what exactly the script does in the name of the script. This is for my golf game I'm working on so it's not the same as a platformer, but look at my Player controller. Each different input I'm doing is a different script. Each of those scripts is probably less than 50 lines each

hushed hinge
velvet holly
#

Ok well the issue is that your update and fixedupdate both try to handle jumping. You need to remove the jump logic from one of those

#

the one in update goes first and never calls your frogjump ability

#

Update runs every single game frame which can happen up to 100s of time a second if your framerate is high enough, while fixedupdate runs only when physics are updated, which happens at a fixed rate, I think the default for unity is 50 times a second

#

based on how I'm reading it, I would remove handlejump() and initiatejump() from the start of update()

#

and then change frogjump to use Time.FixedDeltaTime instead of Time.deltaTime at line 459

velvet holly
#

the F shouldn't be capital

hushed hinge
#

oh

velvet holly
#

fixedDeltaTime, not FixedDeltaTime

hushed hinge
#

ok, there

cosmic dagger
# hushed hinge

You should have auto-complete. just by using dot notation it should appear . . .

#

Since it says the definition doesn't exist, that's an indication you misspelled it . . .

hushed hinge
velvet holly
#

Try running that and let me know if you have any luck

hushed hinge
velvet holly
#

Idk what to tell you. This script is doing too much and is calling stuff multiple times in multiple places

#

your movement function is called in fixedupdate and update on lines 266 and 198. PreformJump is called inside of Movement at line 368 but it's also being called in initiatejump which is called in update as well

#

It's nearly impossible to read through this and understand what it's doing

mystic ferry
#

!code

eternal falconBOT
velvet holly
#

What did you mean by saying that changing the player2d script will change everything everywhere?

mystic ferry
#
    private void CheckForInteractable()
    {
        Ray ray = playerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, interactionDistance + 0.1f, interactableLayer))
        {
            IInteractable interactable = hit.collider.GetComponent<IInteractable>();

            if (interactable != null && interactable != currentInteractable)
            {
                currentInteractable = interactable;
                currentInteractableObject = hit.collider.gameObject;
                UpdateInteractionUI(true);
            }
            return;
        }

        if (currentInteractable != null)
        {
            currentInteractable = null;
            currentInteractableObject = null;
            UpdateInteractionUI(false);
        }
    }

When UpdateInteractionUI is true it shows the text prompt. My problem is that while the ray is hitting the object it's flipping really fast.

velvet holly
#

@hushed hinge I'm not trying to be rude, I'm just trying to explain that the code is so jumbled that even you, the person who wrote it, can't read through it and understand what it's doing and when. You are gonna have to rewrite something to get this to work

wintry quarry
hushed hinge
mystic ferry
north kiln
#

how have you defined interactableLayer

native thorn
#

I put my inputs basically all in the same script should I not do that

mystic ferry
velvet holly
#

I really think breaking it into smaller scripts is your best option. The amount of time invested upfront in doing that will save you time in the long run. Your script has over a hundred lines just dedicated to declaring the variables at the top. Your jump code doesn't need to know about 95% of those variables

native thorn
#

I've been doing it so anything that's handled that has to be saved and loaded goes in one script and anything that doesn't goes in the other lol

#

For the player controllers at least

velvet holly
#

@native thorn as with everything it really depends. In general having different scripts have single responsibilities makes things a lot easier to work with and test and debug

native thorn
#

I find my UI ends up being a mess with 100 different scripts tho

native thorn
eternal needle
native thorn
#

It definately gets messy when I'm handling the weapons system and the controller and camera all in one file

hushed hinge
mystic ferry
wintry quarry
velvet holly
#

@hushed hinge that might be a good start yeah

native thorn
#

Is there a somewhat easy method to serialising data for saving and loading

velvet holly
#

I do think you are doing well with your variable and method naming. Helps the code readability a lot

eternal needle
hushed hinge
velvet holly
#

@native thorn I've got a save system in my game that's pretty modular, lemme get the github link

native thorn
#

I can make arena shooters and platformers my knowledge ends there lolb

velvet holly
#

@hushed hinge I like the art style a lot for your game too

eternal needle
velvet holly
hushed hinge
mystic ferry
#

Ray casts aren't normally bad with collision or something right?

#

I don't know why it's returning so many falses.

native thorn
wintry quarry
# mystic ferry

Looks like it's hitting the door or the door trigger alternately

#

You should make sure only the colliders you want are included in the layermask

eternal needle
cosmic dagger
velvet holly
#

@native thorn It's implementing a standard unity package. Just go in the package manager, click the + button in the top left, "add package by name" and then paste com.unity.nuget.newtonsoft-json as the package

#

I'm about to leave work so I'll be afk for a bit, but if you wanna take a look through that code and DM me I can explain to you how it works in depth so you can adapt it to your game

#

The great and terrible thing about Unity is there's like no standard way of doing anything. It lets you do things however you want really

mystic ferry
velvet holly
#

@hushed hinge assuming you're using Visual Studio, although this would work in really any ide, you should look into how to use a debugger. It will help a ton with figuring out the issues in your code

mystic ferry
native thorn
#

I'm very beginner I get as far as being able to break down unity specific info(game objects) into regular data
And can use that data to rebuild the game into the state I want

I'm just totally lost on storing and loading that data itself

velvet holly
#

It lets you set breakpoints that can pause your game when you reach a certain line of code and then step line by line through it and read what each variable is

#

@native thorn either tonight after I get home from work or tomorrow I can help you do that. That's what the code I sent should let you do with some tweaking

native thorn
#

Alright thanks I'll have a proper look through it today, I've got no electricity for a week so sort of planning ahead right now lol

mystic ferry
#

Wait. Can it be that it's because the raycast hit's it returns a true but then keeps going through it, hits nothing and returns a false?

velvet holly
#

oh yeah I remember you saying that, that shit sucks

#

just dm me if you don't understand any of it and I'll explain it

native thorn
#

Cheers homie

hushed hinge
velvet holly
#

@native thorn Ignore the scripts in that folder that say "Async" in the title. Those aren't being used at all and are just gonna make it more confusing

mystic ferry
velvet holly
#

@hushed hinge I would look up a youtube tutorial on how to use the debugger in visual studio with unity. I think you'll see quickly how helpful that'll be with fixing your script

#

We all gotta start somewhere. I'm no professional myself. I've just done lots of small game prototypes in Unity for years

hushed hinge
native thorn
velvet holly
#

Hell yeah

native thorn
#

Also just to double check I wouldn't have to be worrying about this during development right?

#

As in, will I have to backtrack and alter a lot, or is it simply just breaking down variables into simple data and then bringing that data back

#

For some reason saving/loading has given me endless anxiety about every decision I've made lol

velvet holly
#

yeah that's all the saving does

#

alright I gotta go for real now tty all later

native thorn
#

Alright, thanks man

tawny grove
#

okay am i stupid or should PathList never be empty if Pathfinding.PathPos was EVER not empty (even if it currently is)

#

because somehow pathlist keeps getting reset to nothing when pathpos is nothing

#

oh is it

#

making pathList a refrence to PathPos rather then setting it

#

yep that was the problem

marsh canyon
#

how can I find this missing script issue?

#

I looked at the scripts in blue and I don't see how it could specifically help me find this "(Unknown)" script

naive pawn
burnt vapor
#

It will navigate to the script

#

As to what script it is, idk. Try and figure out what it might be

marsh canyon
#

well it at least doesn't navigate to the missing object or whatever

hot laurel
#

because its deleted but your component still points to removed script

burnt vapor
#

It should point to the missing script

#

If a script is missing, it specifies it is unknown on the component, and this warning triggers

#

But you should be able to click the warning and navigate to it, no?

astral falcon
#

If its in a prefab, it wont go there

#

As it is crying about your networkprefab from a packagecache, maybe try to readd the package or purge its cache folder

mental prawn
#

Hello everyone, I am new to unity and want to make a simple 2d crouch system in which the size and collider changes, but its bugged and not working. can anyone help me out? this is a part of the code

private void handleCrouch()
{
    if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
    {
        if (!isCrouching)
        {
            isCrouching = true;
            transform.localScale = new Vector3(transform.localScale.x, crouchHeight, transform.localScale.z);
            collider2D.size = crouchColliderSize;
            collider2D.offset = crouchColliderOffset;

            Bob.gravityScale = 0f;
            Bob.linearVelocity = new Vector2(Bob.linearVelocity.x, 0);

            transform.position = new Vector2(transform.position.x, transform.position.y - (normalColliderSize.y-crouchColliderSize.y)/2f);
        }
    }
    else if (isCrouching)
    {
        isCrouching = false;
        transform.localScale = new Vector3(transform.localScale.x, normalHeight, transform.localScale.z);
        collider2D.size = normalColliderSize;
        collider2D.offset = normalColliderOffset;

        Bob.gravityScale = originalGravity;

        transform.position = new Vector2(transform.position.x, transform.position.y + (normalColliderSize.y - crouchColliderSize.y)/2f);
    }
}
#

i wanted to take into consideration the displacement

astral falcon
mental prawn
astral falcon
astral falcon
#

Your collider will get scaled too. so be sure you are not double scaling it or expecting a specific size when using transform.localScale in parallel

mental prawn
mental prawn
astral falcon
#

And I am not gonna download anything from here, sry.

#

If you output mp4, it should embed it correctly I think

mental prawn
#

I will try to change the format

astral falcon
# mental prawn here it is

So as I said, your crouch is already scaling your transform (including the component collider on it). And because you are offsetting and resizing your collider, it will ignore the physics for a frame and get stuck below your 2d ground collider I guess. How about taking away the whole collider resizing and test it with just the transform scale?

mental prawn
#

imma do it

mental prawn
astral falcon
lusty star
#

i always write oncollisionenter like this but now apparently something is wrong because there is a yellow line under it, what happened?

astral falcon
lusty star
#

the same thing thats written at the buttom

#

bottom

mental prawn
lusty star
#

and here its fine for some reason?????

#

update: its because i named the script collision

astral falcon
naive pawn
#

!ide

eternal falconBOT
rugged beacon
#

for colision is there any kind of rule to follow when should i use tags rather than layer colision and vice versa ?

naive pawn
#

you should use layers, generally

astral falcon
rugged beacon
#

can layer colision fully replace tags

astral falcon
#

you can have enemies on the enemy layer but still use different tags on them if you need

mental prawn
#

@astral falcon how should I fix the height difference?

naive pawn
#

hard to say without any context

teal viper
#

You'd usually want to just get component instead of tags

rugged beacon
#

im still dont know when should i use it, just rellize i have 20 layers and 0 tags

naive pawn
#

but yeah generally layers are the way to go for primary control of what collides and what doesnt

astral falcon
#

Oh wait, I just realised you are using transform.position. Thats not gonna work with colllisions

teal viper
#

You don't have to use them

astral falcon
rugged beacon
#

like tried to get into tags a few times but almost everytime switch out cause i rember it compare string

#

i guess its fine to continue with layers like this then fr fr

astral falcon
# mental prawn <@144387642140655616> how should I fix the height difference?

And about your issue with skipping collisions and stuff. Pleae checkout !learn about basic collision2d tutorials. Because you are mixing up transform.position with collisions, which is not going to work, as transform.position basically skips the entire physics check. And thats what you gonna see and learn in the tutorials. How to properly move your character 🙂

eternal falconBOT
#

:teacher: Unity Learn ↗

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

teal viper
sour fulcrum
#

components > tags when it comes to confirm if an object is what you are looking for

#

then layers are used to avoid checking that object in the first place

rugged beacon
#

then now i just think tags are obsolete feels abit wrong

ripe shard
rugged beacon
#

oh yea layers limited, guess it can act as a backup

ripe shard
#

also tags compare strings if you use strings, otherwise they compare TagHandle structs

mental prawn
ripe shard
#

whatever happens inside the engine with tags, 'nobody' knows

sour fulcrum
#

tags are gross, harcodey and pretty unadjustable at runtime. i've yet to see a reason why using a component isn't just superior

astral falcon
# mental prawn looking over some of them, they just pulled out a script and pasted it

https://learn.unity.com/course/2d-beginner-adventure-game so you went through this entire tutorial, yes?

Unity Learn

Immerse yourself in the world of game development with this comprehensive 2D Beginner Adventure Game project, designed to guide you through the fundamentals of creating an interactive experience. Follow along step by step to create your own 2D adventure game, with a choice of assets and options for customization along the way. Explore more 2D ...

sour fulcrum
#

i dont use that 😄

naive pawn
sour fulcrum
#

no thats layers

naive pawn
#

no they both have that limitation iirc

#

or is it an array?

#

thonk i haven't touched tags in a long time, i might be misremembering

sour fulcrum
#

tags are unlimited

naive pawn
#

hmm yeah they're a list

#

mb

sour fulcrum
#

they end up getting baked down into likely fancy hash c++ shenanigans for runtime use though

#

can't add new ones at runtime

jaunty copper
#

Hi guys, i have a problem with 2D colliders, my script doesn't work. I add debug logs but seems not enter OnTriggerEnter(). Can someone help me?

tranquil forge
#

is the Trigger checkbox checked ? are they in same layer or colidable layer?

hexed terrace
#

2d uses OnTriggerEnter2D()

tranquil forge
#

fr

jaunty copper
jaunty copper
jaunty copper
hexed terrace
#

ok, 2 things ..
configure your IDE so that it gives you warnings in it.. and you can use google to go to the docs to find the exact signature required

#

!ide

eternal falconBOT
astral falcon
#

its right there in the console, what you need to do

hexed terrace
#

when you've configured your IDE correctly, it will auto-complete the method for you

jaunty copper
hexed terrace
#

Something you should have goolged to find out how to then..

#

The #1 skill of a developer is knowing how to search the internet

jaunty copper
hexed terrace
#

No, it's more important to have your tools setup correctly

#

You only hinder yourself by not having it setup correctly - see this current problem as an example

jaunty copper
#

I fix it, the problem was here: private void OnTriggerEnter2D(Collider2D other){}
OnTriggerEnter2D requires Collider2D type for other

hexed terrace
#

yep, we know

mystic ferry
bitter apex
#

is there a way to get the button, text of a button, and stuff like that with an OnClick() event? I'm not quite sure how to word it, but I want to reuse a method but for a multitude of buttons ( so I don't have to make lots of different methods for each button). Is there an easy way of getting the button, and text of the button upon the OnClick() event firing?

timber tide
#

Make the method the button calls retrieve the button reference

bitter apex
#

Yeah, that's the bit that I'm unsure of how to do#

tacit vigil
#

Hello everyone, so I currently have a cube with text that can rotate like so. How can I make it so when the cube rotates, the text rotates so it's always is readable? E.G. the text on the sides is always upright and the text on the top also always faces the camera (Assuming the camera position is always locked)

rocky canyon
# tacit vigil Hello everyone, so I currently have a cube with text that can rotate like so. Ho...

that's not gonna be so straight-forward..
as u can't really make the numbers follow the camera at all times.. or else it'll look funny..
and if u only have it rotated at a 45* angle like it is.. theres usually (2) ways the number can face
atleast for the top number.. this is why Dies use dots instead of numbers 😄
thats the easiest solution..

i'll think on it.. i don't really have a solution in my mind atm

#

you could probably wait for the rotation move to be finished.. and then flip the numbers

wild parrot
#

hi, in this 9 second video youll notice the pillar im circling is super jittery cause of the camera. Im not sure how to fix this. should i show my code.

naive pawn
#

upload it as an mp4, discord can't embed mkv

wild parrot
#

i ask chatgpt and me and it tried to something about the the update method

#

i dont really understand it though

#

if you know a youtube video about it, ill go watch it

naive pawn
#

so just the camera is jittery?

#

show your movement code !code

eternal falconBOT
wild parrot
#

using UnityEngine;

public class Movement : MonoBehaviour
{
public float speed = 5f;
public Rigidbody rb;
void Start()
{
if (rb == null) rb = GetComponent<Rigidbody>();
}

// Update is called once per frame
void Update()
{
    float movex = Input.GetAxis("Horizontal");
    float movez = Input.GetAxis("Vertical");

    Vector3 move = transform.right * movex + transform.forward * movez;

    rb.MovePosition(rb.position + move * speed * Time.deltaTime);
}

} (is this a 'large code block?')

rocky canyon
# wild parrot using UnityEngine; public class Movement : MonoBehaviour { public float spe...

negative.. but format it like this next time

public class Movement : MonoBehaviour
{
    public float speed = 5f;
    public Rigidbody rb;
    void Start()
    {
        if (rb == null) rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        float movex = Input.GetAxis("Horizontal");
        float movez = Input.GetAxis("Vertical");

        Vector3 move = transform.right * movex + transform.forward * movez;

        rb.MovePosition(rb.position + move * speed * Time.deltaTime);
    }
}     ```
wild parrot
#

sorry

rocky canyon
#

i didn't its discord formatting..

wild parrot
#

oh u just put 'cs' there

rocky canyon
#

and the back ticks. `

wild parrot
#

'''cs hi'''

rocky canyon
#

nope.. those are apostrophe's

thorn holly
rocky canyon
#

the backticks are usually above the Tab key..

#

on top left side of keyboard for Qwerty

wild parrot
#

theres like 3 updates

naive pawn
#

don't use ai

#

simplified it for you

rocky canyon
#

the camera is probably jittery just b/c the rigidbody runs on the physics tick

#

try using some interpolation on ur player (rigidbody)

wild parrot
#

okay interpolation is an option of rigidbody thing right

rocky canyon
#

a broken clock is right twice a day 😉

wild parrot
naive pawn
#

do you have interpolation on your rb

naive pawn
rocky canyon
rocky canyon
#

it just means "even things w/ bad advice can accidently get things right"

#

lol.. ya chatgpt is a good tool.. just try to not rely on it for things u dont understand

#

it'll screw u over and not think twice about it 😄

#

if that doesn't work you can add some smoothing to ur camera via its code

naive pawn
rocky canyon
#

i see what u did there

naive pawn
#

@wild parrot anyways, did the interpolation fix it?

#

if not, try setting the velocity instead of using MovePosition

rocky canyon
#

or just use cinemachine 😈

wild parrot
wild parrot
rocky canyon
#

this is smoothing i was mentioning

rocky canyon
#

if ur manually setting the velocity..

wintry quarry
#

It doesn't work properly in Update

naive pawn
#

why is that a bad thing lol

rocky canyon
#

(is this a 'large code block?')
i was only responding to this question

wild parrot
#

u say i cant use it

naive pawn
#

you asked if you couldn't use them

rocky canyon
#

he said "no" it "doesn't mean you wont be able to use rigidbody functions"

naive pawn
#

so we're denying the negative part

rocky canyon
#

lol

wintry quarry
#

MovePosition also doesn't respect collisions for the moving object so if you need this thing to not go through obstacles you shouldn't use MovePosition as well

rocky canyon
#

^ this is a big point u might want to consider

naive pawn
#

setting a velocity just sidesteps that

wintry quarry
wild parrot
wintry quarry
#

I mean it will but only after it's been moved inside other objects

#

Resulting in a harsh deconfliction

wild parrot
#

okay it wont predict

wintry quarry
#

Moving with velocity will properly stop it before it goes inside other things

wild parrot
#

okay i change my things to velocity

rocky canyon
#
    // every frame
    void Update()
    {
        //get input
        float movex = Input.GetAxis("Horizontal");
        float movez = Input.GetAxis("Vertical");
        movementInput = (transform.right * movex + transform.forward * movez).normalized * speed;
    }
    // physics frames
    void FixedUpdate()
    {
        //use input
        rb.velocity = new Vector3(movementInput.x, rb.velocity.y, movementInput.z);
    }```
#

-# example code

#

let us know if moving the rigidbody function to fixed fixes ur problem

eternal star
#

Hello all, When my inventory canvas is active, I click on a transparent area to close it, but my character also moves to the spot I clicked. I don't want this to happen.

In short, when my inventory is open, I don’t want anything in the background to be interactive. How can I achieve this?

rocky canyon
#

disable the entire player movement script when inventory is open..
or if thers parts of it that need to be running.. you can use a boolean..

#
if(!canMove)
{ return; }

// the code that should run if you canMove```
eternal star
#

That makes a lot of sense. Thank you so much, I'm trying it now.

rocky canyon
#

another solution would be to make a transparent background image..

#

thats set to Raycast Target

#

that'd block any raycast from getting thru.. (if ur project is setup like that)

eternal star
#

"Raycast Target didn't work for some reason. Since my character is a Rive widget under another canvas, I wonder if that's why Raycast Target didn't work. I couldn't figure it out."

rocky canyon
#

not sure.. maybe something to do with the order of ur hiearchy?

#

Top gets drawn first.. then as u go down each element gets drawn on top of the next one

#

imo, its better to code it in place.. b/c u dont want clicks to do stuff not related to that menu.. but u'd also want keypresses and controller buttons to not affect anything else either..

#

soo maybe the bool would be the best choice.. or disabling scripts

eternal star
#

Thank You!

rocky canyon
#

it'd be a great time to work on a game manager

#

a singleton that would monitor that.. and have control over other things that need toggled

rocky canyon
#

probably b/c of the way UI is drawn.. not too sure.. (so thats why i stressed the other method).. it'd be a better robust alternative

#

i knew that was a bit too cheeky to actually work meow_code

hexed terrace
#

raycasts don't affect UI (I believe), UI uses graphics casting

rocky canyon
#

ahhh makes sense..

#

yup, a boolean be the best way i guess

rocky canyon
#

that reminds me.. I always put off stuff like (disabling this and that when my menus are open)..
my projects get a bit crazy when i have UI open over top of the game itself.. 😄
i need to take my own advice and make me a little game-manager right quick

eternal star
#

I think I'll block the interaction somehow after the inventory is opened, but the UI is causing problems where it overlaps with the walking area. When I click to open the inventory, the character also walks towards that direction because I’m clicking on the collider.

grand badger
#

it's not a one-liner by default, so you'll need to set up a method for it, but it's a one-time setup then you make it a one-liner

late burrow
#

didnt dictionary had support for accessing null keys?

late burrow
#

if dict[5] == null screams that 5 dont exist but im pretty sure i could do that

naive pawn
#

you sure it was c#?

grand badger
#

using dict[5] assumes your dictionary is Dictionary<int, object>

late burrow
#

yes but it errors if 5 int dont exist

grand badger
#

and you're trying to access the object whose key is registered as 5

naive pawn
#

entries with null values and nonexistant entries aren't the same, btw.

grand badger
#

-- this is NOT the 5th element

late burrow
#

yes i know

naive pawn
#

i mean it wouldn't be the 5th element anyways

#

it'd be the 6th if it were an index

grand badger
#

ok yes then you can definitely do dict.Add(5, null);

late burrow
#

of course you can add null but you cant access them if they are null

#

but i think you could do that

grand badger
#

it's just a dictionary -- a map

#

you can add ANY values if the key is correct, and you can retrieve it back

grand badger
#

an entry just needs a key and a value to "exist" in the dictionary

#

the value being null doesn't invalidate its existence.

late burrow
#

like i dont know whats the problem shouldnt it just give null?
KeyNotFoundException: The given key '5' was not present in the dictionary.

grand badger
#

there's something else wrong in your code, likely. If you wanna share more I can try to point it out

#

you just never added a value in the dictionary with key = 5

late burrow
#

yes but im 100% sure i didnt had to add them like that if they are primitie

naive pawn
#

the value being null and the entire entry not existing are not the same thing

grand badger
#

OH sorry you said AREN'T 😄 Yes that's 100% correct then mb

grand badger
frosty hound
#

To be clear, you're conciously aware that you did not add a key 5 to your dictionary and you're asking why it's throwing an exception when you try to access a non-existant key?

grand badger
#

or you can check if key doesn't exist OR is null by doing:

if (!dict.TryGetValue(5, out var val) || val == null) { return; }
late burrow
#

yes i know i didnt added because im doing the loop that puts whatever it finds into dictionary

#

and didnt wanted erase existing contents

grand badger
#

yup! super common practice

late burrow
#

maybe, but i swear it wasnt throwing error before

teal viper
#

You're probably confusing with C++ maps. They can add new elements via the indexer.

late burrow
#

just giving null

naive pawn
#

it'd give null if 5 was present but null

grand badger
#

it likely wasn't throwing an error before because you had an entry added with key = 5

late burrow
#

or i just got brainwashed by json

grand badger
#

maybe 😄 json indeed only parses what matches no problem

naive pawn
#

what...

rocky canyon
#
        if(testDict.TryGetValue(5,out var value5))
        {
            if(value5 == null)
                Debug.Log("Key 5 exists, but its value is null.");
            else
                Debug.Log($"TryGetValue: Key 5 exists with value: {value5}");
        }```
#

ahh dang.. someone beat me to it

grand badger
late burrow
#

just instead of == null containskey

#

and you can indeed then write dict[whatever] = null

bright zodiac
grand badger
bright zodiac
#

ah shiet,, yeah forgot that

rocky canyon
#

we're strictly Lists and Arrays over here bruh

#

😆 j/k j/k Dictionaries are welcome too

grand badger
tacit vigil
# rocky canyon that's not gonna be so straight-forward.. as u can't really make the numbers fo...

I'm now trying to prgramatically add an image to each face object, which I am trying to do as following

 for(int i = 0; i < transform.childCount; i++)
        {
            GameObject Go = transform.GetChild(i).gameObject;
            if(Go.name[^4..] =="Face"){
                Button b = Go.transform.GetChild(0).GetComponentInChildren<Button>();
                var sprite = Resources.Load<Sprite>("pip"+Random.Range(1,10));
                b.image.sprite = sprite;
            }
        }

But the scene loads errorless and imageless. The images I am trying to place on the buttons are under Assets/Resources/pipX.png, with X being a number 1-9

#

I've also confirmed that it enters the if correctly

tawny grove
#

How would i go about more efficiently running a function every other frame? An if statement in update? Corontuines?

naive pawn
#

more efficiently than what?

#

and would it really make a difference lol

#

the work you do is probably more intensive than triggering it

#

sounds lke premature optimization

bright zodiac
tawny grove
#

Most efficiently mb not more

#

Why was “most*” censored lol

grand badger
#

if (++i % 2 == 0) { MyMethod(); } would be fine I think.

tawny grove
#

Alr, ty

naive pawn
#

that's a microoptimization at that point

tawny grove
bright zodiac
bright zodiac
#

its still nice tho

#

callvirt is known to be slower but not as much

rocky canyon
grand badger
rocky canyon
#

if theres no errors i'd guess that the code/logic is correct.. but maybe the images aren't what u expect

naive pawn
#

you're safe with an int32

grand badger
grand badger
tawny grove
tacit vigil
rocky canyon
#

the gameobject, the button, the sprite

rocky canyon
#

all of em lol yea, make sure ur getting those names correctly..

#

im not really sure how u'd debug to see if its selecting the correct image

tacit vigil
#

ok yep, the sprite variable is null

#

so it's not being loaded

rocky canyon
#

👍 first step complete! ⭐

#

now to figure out why.. lol

cosmic dagger
grand badger
#

like this?

if (frameCount == 0 || frameCount == 2 || frameCount == 4 || frameCount == 6 || frameCount == 8 || frameCount == 10 || frameCount == 12 || frameCount == 14 || frameCount == 16 || frameCount == 18 || frameCount == 20 || frameCount == 22 || frameCount == 24 || frameCount == 26 || frameCount == 28 || frameCount == 30 || frameCount == 32 || frameCount == 34 || frameCount == 36 || frameCount == 38 || frameCount == 40 || frameCount == 42 || frameCount == 44 || frameCount == 46 || frameCount == 48 || frameCount == 50 || frameCount == 52 || frameCount == 54 || frameCount == 56 || ...
{
    MyMethod();
}
mental prawn
tawny grove
bright zodiac
#

in what way? 😄

grand badger
#

simple and readable code is often the best

bright zodiac
#

in this case, your coworkers would like to beat you up I think

#

😄

mental prawn
cosmic dagger
mental prawn
#

I believe this would do the job

tacit vigil
tacit vigil
#

so i just need to convert to sprite probably,,, but maybe it's a good idea to see if it can be done with textures

mortal ginkgo
#

how do i make it so that visual studio gives me suggestion to complete my sentence?

eternal falconBOT
mental prawn
#

also I do not get any completion in visual studi

#

do you know why that would be?

rocky canyon
grand badger
rocky canyon
#

same response.

mental prawn
#

oh T_T

mortal ginkgo
#

which visual studio should i use?

cosmic dagger
bright zodiac
tawny grove
#

I need to watcg a video on bitshift i dont understand it at all 😭

bright zodiac
#

you rarely need it, so you're not missing out much 😂

timber tide
#

bitwise enums: "Am I a joke to you?"

bright zodiac
#

you will need it once Unity is done migrating to coreClr..
bitshift is heavily used on vector generics (Vector<T>/Vector128/256) for SIMD stuff

cosmic dagger
bright zodiac
#

nice

burnt vapor
#

You should not assume it works anyway, because null would be a very vague key since it's not a value

bright zodiac
rocky canyon
#

he uses layermask as the example.. but its a good video on bitshifting and stuff imo

bright zodiac
#

also not sure how it would behave in unity tbh

grand snow
#

after learning about bit shifting endianness is a fun next topic! /s

burnt vapor
bright zodiac
#

ah yeah, the second time I forgot this today... my bad

rocky canyon
#

we need someone to come in with their mouse delta's multiplied with deltatime to help remind us

mental prawn
# eternal falcon

I followed it (first one) but nothing seems to be new.
does this look alright?

grand snow
#

"help notepad isnt working for code how do i use" 🤡

#

nooooo

rocky canyon
#

rekt

mental prawn
grand snow
#

that will make it open the visual studio solution (the fancy project file)

mental prawn
#

oh no

#

brb

naive pawn
# rocky canyon we need someone to come in with their mouse delta's multiplied with deltatime to...

why doesn't this work
'''
cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class movement : MonoBehaviour
{
[SerializeField]
public float mouse_Sensitivity;

// Start is called before the first frame update
void Start()
{
    
}

// Update is called once per frame
void Update()
{

transform.position = transform.position +Input.mousePositionDelta *mouse_sensetivity * Time.deltaTime
}

}
'''

rich adder
#

backticks

naive pawn
#

what are those

rich adder
#

`` `

naive pawn
#

woah how did you do that!!1!1

rich adder
#

magic 🌈

naive pawn
#

oh god this is physically painful how do people troll

grand snow
#
#include <UnityEngine>

class MyScript : MonoBehaviour
{
public:
    void Start() {
        int* myInt;
        Debug::Log(std::format("test {0}", *myInt));
    }

private:
    void Update() {

    }
}

guys my script doesnt work help /s

rich adder
#

UnrealUnity

grand badger
grand snow
#

ding ding you win

rich adder
#

hey at least its not python

grand snow
#

it would sigsegv due to the nullptr deref

grand badger
#

I recommend studying a bit more about Unity code and C# in general before jumping straight in game dev high

grand snow
#

yes i will go read up on python for unity

naive pawn
grand badger
#

that's the spirit!

grand snow
naive pawn
#
import "UnityEngine";

class MyScript extends MonoBehaviour {
  public Start(): void {
    Debug.Log(`Start from ${this.constructor.name}`);
  }
}
grand badger
#

what's this damn language

naive pawn
#

ts

grand badger
#

why this.constructor.name is allowed lmao

naive pawn
#

because that's how js works

grand snow
#

this is cursed in js

#

() => {} will capture this but function() {} will not

grand badger
#

oh lol wow

naive pawn
grand snow
#

i mean that the lambda will capture this from the scope it was created in, vs the calling this later.

naive pawn
grand snow
naive pawn
#

the behaviour is that function() {} creates a new this context, while () => {} does not

#

() => console.log(this) will give different results depending on where it's called from

grand badger
#

ended up solving it by caching a local variable but still not realizing why that'd fix it

naive pawn
grand snow
#

all py examples i see always shorten the longest import you have ever seen into a

#

import supercoolclibwrapper as s

grand badger
#
import unityengine as MyCustomEngine_I_MadeThis_btw
rich adder
naive pawn
rich adder
naive pawn
#

we kinda exhausted our options, huh

rich adder
#

ran the train right into a brick wall

naive pawn
mental prawn
#

I did everything and it still doesn't autocomplete it in this visualstudio

naive pawn
# naive pawn

bruh i edited the "number or text" to "message" and it didn't save

naive pawn
rich adder
rich adder
#

button in Preferences

mental prawn
rich adder
#

right click it, Reload with Dependencies

mental prawn
rich adder
mental prawn
rich adder
#

well you need glasses then

mental prawn
#

maybe

rich adder
naive pawn
#

do you see the tab labelled solution explorer

mental prawn
naive pawn
#

consider not doing that

rich adder
#

civilization is doomed

mental prawn
#

now I got this

#

T_T

naive pawn
#

it disliked your usage of gpt

#

as it should

#

(microsoft wants you to use copilot instead)

rich adder
#

I dont understand how its easier to ask a chatbot than look with your eyes

#

will you need chatgpt to tell you how to piss

mental prawn
#

I WON, FINALLY

hexed terrace
#

!vs

eternal falconBOT
#
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

rich adder
#

did your discord not update ?

fallen jacinth
#

Do someone have good youtube toturials for C# or something other than youtube?

fallen jacinth
#

thanks

rich adder
fallen jacinth
#

thank you so much

#

now my computer is exploding after i render my animation in blender

lyric pulsar
#

hey im working on a 20 sided dice but the debug log is showing the wrong number. is there a way to fix that?

rich adder
hexed terrace
#

debug log is showing the correct number for the time it spits it out

lyric pulsar
#

is there a way to assign a number per roll?

rich adder
#

yeah why not

rocky canyon
rotund bolt
#

I have two classes, Player (which doesn't have the title in the screenshot, sry, but its just the smaller picture one) and TestingEvents. I'm learning about events and I think the way they're supposed to work is if I invoke an event in class A, a different class B can "hear" that the event was invoked and then perform a desired function that was defined in class B. <--- assuming that's correct, I'm trying to do some stuff using that logic (I might be wrong about those assumptions and maybe that's my issue though.)

So I have some code that tests whether space was pressed, one time with a function defined inside TestingEvents class, and another time with a function defined in the Player class. The Testing_OnSpacePressed() function works (defined inside TestingEvents) and spits out "Space!" in the console, but the EventTester_OnSpacePressed() does not seem to work (defined in Player). I assumed since OnSpacePressed?.Invoke(this, EventArgs.Empty); is getting invoked inside the Update() method in TestingEvents that the EventTester_OnSpacePressed() would be triggered since I attached it with eventTester.OnSpacePressed += EventTester_OnSpacePressed; in the Player class. Any thoughts on this? do I have a fundamentally flawed assumption about how events work? I was hoping to join a voicechat to get some verbal help with this but i dont think unity discord has voicechat, if somebody has a mutual server we can join a voicechat there

TestingEvents Class: https://paste.ofcode.org/rASCtxvdZwQXV5giv2hht
Player Class code: https://paste.ofcode.org/iHfmnEBdMnQtBw6HdLevJb

short hazel
#

Also you're subscribing with += in Update, which is executed every frame. Given a framerate of 60 FPS, if you raise the event after 1 second, your OnSpacePressed() method will be executed 60 times!

rotund bolt
#

no worries if not

cerulean oyster
#

yo i am using a RayCastHit2D to check if im hitting a wall and for some reason only on build it hits triggers even though I contact filtered them out and turned off queries hit triggers in settings im so confused ive been messing with it for hours and I cant figure this out. IT's so weird that it only happens on build( and it happens for both webgl and windows) I even tested it on my laptop and it still happens. It's important because im resetting the score on wall hit, and it works fine on my item but it breaks on the collider that has SceneManager.LoadScene(). Any ideas??

tawny grove
#

how would i go about getting the angle between the red square and the blue square as if it was on a circle? like in this case it would be around 145. i tried vector3.angle but it doesent seem to work the way i want it

wintry quarry
tawny grove
#

yes

wintry quarry
#

You would use Vector3.SignedAngle

#

or Vector2.SignedAngle

tawny grove
#

let me try that

#

what do i put as the axis?

wintry quarry
#

The direction pointing out of the screen

#

in this diagram

#

or use the 2D version

#

if you have 2d vectors

tawny grove
#

hm it still appears to be in the wrong position but i think it might be from something else

wintry quarry
#

Vector3.Angle would also work perfectly here btw (and will work as long as the angle you are looking for is less than 180 degrees)

#

so my guess is you are passing in the wrong parameters

#

Maybe show your code?

tawny grove
#

alr 1 sec

wintry quarry
#

that's wrong from the get go

tawny grove
#

oh

wintry quarry
#

it works with directions

tawny grove
#

to get directions i just normalize them right?

wintry quarry
#

those are the directions

wintry quarry
#

To get a direction vector from point A to point B it's B - A.

#

(you can normalize that result)

tawny grove
#

yeah thats what i meant woops

wintry quarry
#

you need a point C here

#

which would be the rightmost part of the circle in your diagram

tawny grove
#

C would just be vector2.right * radius right?

wintry quarry
#
  • the center
#

of the circle

#

Unless the blue position happens to be Vector2.zero

#

otherwise it'd be blue + Vector2.right * radius

#

though the radius isn't going to matter for these angle calculations

tawny grove
wintry quarry
#

the direction itself might just be Vector2.right if you always want it to be that

tawny grove
#

oh actually that makes sense lol

wintry quarry
#

yeah for the second one if you always want it going straight right you can just put Vector2/3.right

tawny grove
#

i got a - 67 from what should have been 150~, weird

steel smelt
#

ur normalizing the position itself before ur computing the delta

#

ur supposed to normalize the difference between the positions

tawny grove
#

oh i forgot to remove that ,b

#

mb

wintry quarry
#

Also which one is the red and which is the blue between player.transform and this.transform

wintry quarry
#

if you want the direction from the player to this object

#

dir from A to B is B - A

tawny grove
#

alright, btw is there a reason for using this.tranform instead of just transform?

wintry quarry
#

I'm just being explicit

#

they will be the same

tawny grove
#

oh okay

rancid tinsel
#

Could someone explain to me why setting variables in inspector vs programmatically is considered bad practice? The obvious is that you can lose those references (when errors happen, moving scripts etc) but are there other reasons?

tawny grove
#

would this (player and ghost) not be like 150*? im getting -170 which would be in the third sector( below left of player)

wintry quarry
#

the blue shirt guy?

tawny grove
#

yeah

wintry quarry