#💻┃code-beginner

1 messages · Page 346 of 1

short hazel
#

Don't worry about Steve they have their power trips from time to time

sick jay
#

oh yeah putting in the max distance causes an error

#

it doesnt like that i put in 4 arguments

languid spire
#

come on, you ask a silly question, you get a silly answer

sick jay
#

hey it was real hard for me to find where to learn programming at first too

#

those learn pages are decently hidden

short hazel
sick jay
#

oh whoops

inland aurora
#

i dont really understand why do i have to take a quiz if they taught me nothing

#

i watched the video but then i when i went to my first mission it gave me a quiz to start off

sick jay
#

okay i think i understand how steve smith feels now

inland aurora
#

nvm

#

i downloaded the rong thing

#

im sorry im kinda stupid

sick jay
#

@short hazel it gives another error, this time saying that argument 4 may not be passed with the out keyword, i tried to fix it myself since ive already asked so much but i just cant figure it out

#

i think it wants a quaternion in between the out and the maxdistance

short hazel
#

Your arguments seem to be out of order, they must conform to one of the available overloads mentioned in the docs I've linked

#

When one of the parameters have an equals sign (eg. Quaternion orientation = Quaternion.identity) it can be omitted, it is optional

sick jay
#

everything seems to be in order

#

the error goes away if i put an orientation in

#

its the wrong rotation but i was just using it to check

short hazel
#

I guess it can't determine which overload to use when you don't supply the optional parameters in order

#

You technically don't need the out variable so you can use the overload that doesn't have it

hollow dawn
#

how can i fix this? when walking my leg does that

short hazel
#

Yeah but put the orientation too, pass Quaternion.identity

sick jay
#

alright

#

i just need to figure out what that orientation actually needs to be

short hazel
#

It's how the box is rotated, not to be mixed up with where it goes. Best to leave it not rotated by default

sick jay
short hazel
sick jay
#

i thought so

#

would boxCenter.rotation work

#

or something

#

that isnt right

#

hold on ill figure it out

short hazel
#

No you just pass Quaternion.identity directly!!!

#

BoxCast(..., Quaternion.identity, ...)

sick jay
#

Ahh

#

it uses the "identity rotation"

#

what is that the rotation of specifically? the Vector3?

rich adder
sick jay
#

yes i realized that after

short hazel
#

Identity represents 0 degrees on all 3 axes

sick jay
#

got it

short hazel
#

Quaternions store rotations on 4 values internally to mitigate some issues, each value ranging from -1 to 1

#

You don't mess with them directly

sick jay
#

thanks for all the help, this is the final bit of code. the players height is at 3, and i wanted a bit of wiggle room to jump in case you hit the spacebar too early

#

oops let me get rid of that useless vector

#

and the raycasthit

#

and i can just make the return true; instead of all that

inland aurora
#

bro unity crashed

#

i was downloading it

short hazel
#

If you have issues when installing, ask in #💻┃unity-talk as it's not a code issue. It doesn't come from your own programming, at least

sick jay
#

is there an easy way to get the side of a hitbox? to test for collision with walls

#

or should i just tag every wall with a wall tag

short hazel
#

You usually make other physics casts for that. I did that for a wall run mechanic once

#

Raycasts left and right of the player

wintry quarry
sick jay
#

alright i think i can do that without any help

#

its kinda silly though right now if i run into a wall hard enough its like walking through jelly

short hazel
#

That means you're moving in a way that doesn't respect the physics engine, if you can go into it slightly

sick jay
#

heres the movement right now, im gonna move it into its own voids soon to get it out of update

wintry quarry
sick jay
#

yeah i know its not a great thing

short hazel
#

Yep you should be using the Rigidbody

sick jay
#

i should be using rigidbody movement

plain dagger
#

transform.translate sucks

sick jay
#

ive used the rigidbody already for a different test i was doing it looked like this

plain dagger
#

This looks like an old input system problem

sick jay
#

yeah i was following a fairly old tutorial then

ionic plank
#

Hello guys I have a quick question about musics in my game. I have a playlist of two musics right now and when the second starts my game lag for 2 seconds. Can someone help me with this ?

sick jay
#

it wanted to make its own input system instead of using unitys built in one

nocturne parcel
#

Yikes

plain dagger
sick jay
#

dont worry its from a test game that ive already finished

plain dagger
ionic plank
#

I don't see it

plain dagger
#

Click it in the assets

ionic plank
#

this ?

plain dagger
#

yes

ionic plank
#

thank you ❤️

#

should I change the load type for a android game ?

#

an *

plain dagger
# sick jay dont worry its from a test game that ive already finished

I'd recommend taking some time to learn the new input system. Realistically all you need to do is get the direction of the control stick and then translate that information to a Vector3. Then just move the player with that Vector3.

What you have now looks like trying to use an old broken car because it's familiar.

short hazel
#

Even with the legacy input system, you can construct a vector from the horizontal and vertical axes

plain dagger
#

but only if it's only going on android

inland aurora
#

i cant seem to open my project

#

anyone know why?

plain dagger
short hazel
sick jay
#

this code is improved but it doesnt seem to be doing what i want(speed is set to 0.1f)

#

i think the main issues are the max speed isnt working, and i also slide really far before stopping instead of stopping over 0.1f

plain dagger
#

what's the problem at hand

sick jay
#

wait i think i see the problem for one of those

#

something like this should stop the player instantly when no WASD keys are being pressed, since it does the opposite velocity force

#

i just need to multiply it by something to make it slow down over a short period of time

nocturne parcel
# sick jay

That lerp is returning a number very close to currentSpeed. Is that what you want?

#

The currentSpeed is slowing down by almost nothing

plain dagger
#

Try changing ForceMode to acceleration

#

no

#

don't actually

sick jay
plain dagger
#

I thought of why you'd need impulse force to move

sick jay
#

also uhh what i did did not work

#

it sent me flying downward at what im assuming was infinite speed

nocturne parcel
#

Do you want the player to slowdown when stopping or to stop completely?

#

Like, still slide a little bit when stopping?

sick jay
#

slowdown, but not at the speed it is without any code

plain dagger
sick jay
#

yeah

#

but slowdown over a period of 0.1f seconds

#

i just thought it would start adding 0,0,0 force since the rb.velocity should go to 0 when you stop moving

#

but it must have not gone exactly to 0 since i was adding it backward

#

and then it went back and force

#

forth

#

from positive to negative

nocturne parcel
#

You could try tuning the friction factor down for 0.1f seconds

#

But I believe you could try and use something similar to knockback

sick jay
#

is that in project settings

crude sphinx
#

Yo guys, how do I replace the last line to use my rigidbody instead of the transform.Translate?

  void FixedUpdate()
    {
        Vector3 forwardDirection = transform.forward;
        Vector3 movement = new Vector3(move.x, 0.0f, move.y) * moveSpeed * Time.deltaTime;

        // Rotate the movement vector based on the player's forward direction
        movement = Quaternion.LookRotation(forwardDirection) * movement;

        transform.Translate(movement, Space.World);
    }
sick jay
#

or should i add a physic material to the player

plain dagger
#

physic material

nocturne parcel
#

There is also something called drag

plain dagger
#

that's slightly pseudocode btw

crude sphinx
plain dagger
#

Oh, that's a vector3, not a var

crude sphinx
#

Ye

sick jay
#

more specifically when i landed

nocturne parcel
#

I dunno with drag will help actually

plain dagger
nocturne parcel
#

You could try and set the friction back to normal when landing

#

Or even when pressing the jump button

plain dagger
sick jay
#

draga works

nocturne parcel
#

Oh it did?

sick jay
#

yeah

nocturne parcel
#

Oh cool

plain dagger
#

alright

#

remove your multiplications from your movement vector and put them in the rb.velocity line

sick jay
#

i have two gameobject floors here at the same height touching each other. sometimes when i run across it, it gets stuck for a second and makes me lose speed

crude sphinx
plain dagger
#

yes

eternal needle
crude sphinx
#

I still cannot move though

crude sphinx
#

I do glide every so slightly for some reason (but that is not speed related)

plain dagger
#

Sounds like an inspector issue

sick jay
#

ignore the useless if statement i havent removed it yet it was for something else

crude sphinx
eternal needle
# sick jay this is from above

!code
Ideally just put everything in 1 complete message so it's easy for anyone to help.
For movement I also really suggest adding debug drawray a lot to see where you are even trying to move

eternal falconBOT
plain dagger
wooden shoal
#

Where I find good tutorial which explain how to change UI toolkit uxml layouts to another?

eternal needle
sick jay
#

but only sometimes, which is odd

crude sphinx
eternal needle
swift crag
#

This looks like a bogus collision with the floor. This can happen where two colliders meet.

plain dagger
sick jay
#

which means if there was a gap id be able to see it

molten dock
#

what is the technical name for something like this

#

i just say

#

set the Moveinputs value to the move input

nocturne parcel
#

Set the drag to what it was before, it was the only thing you changed.

sick jay
#

ill try it

#

but i feel like it might have happened in the past i just didnt notice it till now

plain dagger
ivory bobcat
sick jay
#

tested, changing drag back to 0 and it still happens

swift crag
#

Can you show me the inspector for the rigidbody?

eternal needle
sick jay
eternal needle
#

Oh box collider for the player is probably making it worse

sick jay
swift crag
# sick jay

Try changing Collision Detection to Sweep-based

crude sphinx
#

@plain dagger

swift crag
#

i am curious

ivory bobcat
sick jay
swift crag
#

and yeah, capsule colliders can help smooth out that kind of behavior

sick jay
#

thats what people thought i had originally so im assuming thats what i should use

eternal needle
#

I feel like capsule collider should be more smooth considering its way less area hitting the bump

swift crag
#

although they can also allow things to climb on top of each other, which gets annoying

strong token
swift crag
#

I'd just asy "read move input" if I had to write a comment

#

I might note that I'm reading X and Y into X and Z

plain dagger
# crude sphinx <@270688467879460866>

if its not an inspector issue then somewhere you've got code stopping your object's velocity, or that code isn't running in the first place (just test that with a debug.log)

sick jay
#

changing to a capsule collider worked great

hoary halo
#

Yo since the unity 6 change idk how to check the velocity of a object to see if its moving. Anyone able to help? They changed how rigidbody.velocity works

sick jay
#

but i do want to see about combining nearby floors like that to a single collider

#

if its not too hard to do

plain dagger
crude sphinx
plain dagger
#

no skull_real

crude sphinx
#

hahahaha

short hazel
eternal needle
sick jay
hoary halo
short hazel
#

Then your Rigidbody moves

#

Log both rigidbody.position and transform.position

crude sphinx
ivory bobcat
hushed hinge
#

is there like a way for the ui image to know that it's still the player that are rescuing muons even if the player dies and new player gameobject appears? because the gameobject script that holds the ui image disappears from the muon UI Controller gameobject in the new player object https://gdl.space/pimefadoma.cs (this is the script in the ui image for the muon images)

hoary halo
ivory bobcat
hushed hinge
ivory bobcat
hushed hinge
hushed hinge
hushed hinge
ivory bobcat
hushed hinge
ivory bobcat
#

Maybe show where you're instantiating the new player (likely on the player's death - assuming the next player isn't already in the scene)

hushed hinge
ivory bobcat
#

Are there multiple muon ui controllers in the scene or only one? @hushed hinge

hushed spire
#

I've got a joystick script and I'm using unity remote to simulate it on my phone, which is working just fine. However, when using the joystick and having a finger touch anywhere else on the screen, the joystick freezes until this bonus finger input is taken off the screen. To stop this, is there a way to stop unity from even recognizing this extra input if it's not inside a certain area?

hushed hinge
#

while this is the ui image (the screenshots are being slow to take)

ivory bobcat
#

If there's only one, when you instantiate the player in the manager, you'd just setup the muon ui controller (assuming the manager really has access to it)cs public PlayerComponents SpawnPlayer(int playerNumber, Vector3 position, Transform parent = null) { if (playerNumber == 1) { playerOne = Instantiate(playerOnePrefab, position, Quaternion.identity, parent); playerOne.muonUIController = muonUIController; return playerOne; } else { playerTwo = Instantiate(playerTwoPrefab, position, Quaternion.identity, parent); playerTwo.muonUIController = muonUIController; return playerTwo; } }

ivory bobcat
hushed hinge
ivory bobcat
ionic zephyr
#

How can I make a shop system but whenever I buy an item it immediately does its effect?

hushed hinge
ionic zephyr
ivory bobcat
hushed spire
polar acorn
# hushed hinge

Does PlayerComponents contain a definition for muonUIController

strong token
# hushed hinge

In the video you have sent, the component "Muon Interaction" is missing the reference to the controller. So you should get that component, and set it there.

ivory bobcat
# hushed hinge

I recall the purpose of your player components script to be a mediator for all other components on the player object. If the above post is correct and that your necessary reference is from the interaction component (that's hopefully on the player), update your player components script to account for the new component on the player and assign the muon ui controller appropriately through references. cs playerOne.muonInteraction.muonUIController = muonUIController;

hushed hinge
eternal needle
polar acorn
ionic zephyr
#

Okay, thanks a lot

ivory bobcat
ember tangle
#
List<FormationPositions> targetPosition;
targetPosition.Add(new FormationPositions());

Why is this not valid?

#

FormationPositions is a MonoBehaviour.

slender nymph
#

you should not be manually calling a MonoBehaviour's constructor. which you should be receiving a warning about in the editor console at runtime

#

unless this is like your exact code, in which case you don't initialize the list and therefore get a NRE

wintry quarry
ember tangle
#

Do you have a link describing that in more detail or showing the proper way to do it?

#

I still dont really understand

wintry quarry
hushed hinge
deft grail
#

which is why you get that error probably

hushed hinge
deft grail
#

in the inspector

#

i can see 3

hushed hinge
#

like that in player component and Muon interaction?

deft grail
#

yeah

hushed hinge
#

even if i can assign them in the player gameobject, i can't assign them in the player prefab

ember tangle
# wintry quarry MonoBehaviors can only be created by: - Attaching them manually in the editor - ...
public class FormationPositions: MonoBehaviour
{

    GameObject markerPrefab;

    public GameObject formationTargetPosition; // for the formation overall
    public List<GameObject> unitTargetPosition; // for individuals units

    public void Start()
    {
        
    }
    public void SetFormation(int unitCount, int width, int spacing, Transform position)
    {
        formationTargetPosition = Instantiate(new GameObject(), position);

        markerPrefab = Resources.Load<GameObject>("Prefabs/DestinationMarker"); // temporary, loads destination marker type

        int _depth = unitCount / width; // calculate formation depth

        // offset to be centered
        int xOffset = (spacing * width) / 2;
        int yOffset = (spacing * _depth) / 2;

        Debug.Log($"x offset = {xOffset} y offset ={yOffset}");

        //fill list with position gameobjects
        for (int index = 0; index < unitCount; index++)
        {
            //add unit position to list as prefab and as a child
            unitTargetPosition.Add(Instantiate(markerPrefab, formationTargetPosition.transform));
        }

        //set position values for game objects
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < _depth; y++)
            {
                //set each position
                int index = width * y + x; // get grid position off one dimensional vector.
                unitTargetPosition[index].transform.localPosition = new Vector3(0 + spacing * x - xOffset, 0, 0 - spacing * y);

                //Debug.Log($"{gameObject} index {index}: value ({unitTargetPosition[index].transform.position.x} , {unitTargetPosition[index].transform.position.y})");

            }
        }
    }

}

I'm stuck using Monobehaviour due to needing to Instantiate() GameObjects within the class but I feel that the FormationPositions class is inappropriate as a Game Object. Maybe im missing the plot

deft grail
#

so you cant assign that to a prefab

slender nymph
hushed hinge
deft grail
teal viper
hushed hinge
frozen steeple
#

I dont know if anyone ever used the third person template of Unity, but how exactly does this code works? there's no reference to the PlayerInput. So does the OnMove look for a "Move" action in the active map?

deft grail
hushed hinge
frozen steeple
#

so if I create an action named Fly I need to create a function named OnFly?

deft grail
ember tangle
slender nymph
hushed hinge
slender nymph
deft grail
frozen steeple
teal viper
hushed hinge
deft grail
eager wolf
#

how can I create an ID list of scriptable objects, kinda like Minecraft has an ID list for items?

hushed hinge
deft grail
deft grail
eager wolf
#

but then when I want to spawn a scriptable object of ID 5 (example), how do I find the scriptable object matching this ID?

#

@deft grail

hushed hinge
#

yet I don't know how to assign that if i can't assign it in the prefabs

deft grail
deft grail
hushed hinge
deft grail
#

basic C# really

deft grail
hushed hinge
deft grail
eager wolf
deft grail
#

or this can also just be a scriptable object i think

eager wolf
#

is there a better way than ddol, though?

deft grail
eager wolf
#

a scriptable object with an array?

deft grail
#

yeah the same way you made what you made now

eager wolf
#

and then i instanciate it in every scene to use it?

deft grail
#

no? you just reference it

hushed hinge
ember tangle
#

I think I understand what everyone is saying... so instead of formationTargetPosition = Instantiate(new GameObject(), this.transform); I should use formationTargetPosition.transform.parent = this.transform; correct?

deft grail
# hushed hinge

need to do this the long way...
create a variable which will reference your main player thats already in the scene.
create more variables which will hold the variables you want to keep.
then set them from the player

eager wolf
#

I didn't know I could reference scriptable objects lol, thanks bro, you the man

slender nymph
ivory bobcat
ember tangle
# slender nymph why would you think that is what you want? didn't you want to create a new empty...

I'm trying to create an object and set it to a transform parent in the script. Formation (Parent), Formation Target Position (Child).

It needs to be a child because setting movement orders in this game (think total war) requires a transform that is relative to the Formation's position overall.

The code I had worked, its just making too many object and was wrong apparently. I thought that replacing it and setting a child using the transform of the parent instead was the proper way?

hushed hinge
#

nope, it isn't, aghhh, what is wrong with me not thinking straight?

ivory bobcat
hushed hinge
ivory bobcat
#

If they're not unique per scene (maybe they're a part of the manager) it should work. Else you'll need to tell the manager in some start function which muon ui controller the scene is using.

teal viper
north oar
#

im learning unity for the first time and im already lost on this tutorial my code of "gameObject.name = "brah"; wont work and im not sure whats causing it

wintry quarry
#

be more specific about what happens

north oar
#

it doesnt change the name

wintry quarry
#

where did you write the code?

#

Can you show the full script?

#

!code

eternal falconBOT
north oar
#

i put it inside of the void start

wintry quarry
#

Show your code

#

All kinds of things could be wrong

#

we won't know without seeing it

north oar
#
    {
        gameObject.name = "brr";
    }```
wintry quarry
#

Also you need to make sure your script is actually attached to an active GameObject in the scene

ember tangle
wintry quarry
north oar
#

yeah its attached

#
using System.Collections.Generic;
using UnityEngine;

public class BirdScript : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        gameObject.name = "brr";
    }

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

its just the default code it gives me with the name script

wintry quarry
north oar
teal viper
ivory bobcat
#

You'd do the second if each scene has their own muon ui controllers - I'm assuming you've got to rescue different muons per scene/stage.

ember tangle
hushed hinge
wintry quarry
teal viper
ivory bobcat
ember tangle
#

ok this may be a dumb question but doesn't formationTargetPosition act as a pointer to that new GameObject? Doesn't the garbage collection in C# take care of that duplicate?

#

or am I really not understanding? (probably 😭 )

wintry quarry
#

they halfway live in the Unity Engine itself

#

as native objects

#

and thus will not be garbage collected

#

Also the engine itself maintains a reference to the C# half.

wintry quarry
ivory bobcat
deft grail
#

what do you think it means?

ivory bobcat
# hushed hinge

this implies that the statement should be called from the muon ui controller script

#

Meaning this should be placed in the muon ui controller script

ember tangle
#

Alright I think I understand now. I have a lot of cleanup in this code now haha. Last question on the Instantiate thing:

List<GameObject> units;
units.Add(Instantiate(unitPrefab, this.transform));

is the correct use of of Instantiate because its a List, right?

ivory bobcat
#

I've got to run again. Have a good day.

wintry quarry
#

also if that's the actual code, it's not going to compile

ember tangle
#

Yeah the list is a public attribute of a class, I'm just smushing it together for brevity.

hushed hinge
# hushed hinge ok

oh no i deleted a lot from scene one without me thinking that because i thought it was the second stage, how can i brings things back to there how things were and i can skip back?

deft grail
hushed hinge
#

..................😢

north oar
#

in this unity tutorial im wathcing whenever he writes code he gets this dropdown menu with a list of things but it doesnt show dropdown menus for me, why?

eternal falconBOT
ember tangle
teal viper
hushed hinge
wintry quarry
teal viper
deft grail
hushed hinge
ember tangle
summer stump
summer stump
#

It would be up to date if you committed all your changes recently

ember tangle
#

Duplicating the prefab yeah, but not unintentionally

wintry quarry
summer stump
#

It looks like you may have NOT been up to date if you deleted more than two things

wintry quarry
#

and the thing it's adding to the list is just a reference

#

You could do this and it's the same:

var clone = Instantiate(unitPrefab, this.transform);
units.Add(clone);```
hushed hinge
teal mason
#

I have a Cinemachine brain, virtual camera, and a player game object. All are prefabs. I assign the player prefab to the 'Follow' transform in the virtual camera's inspector. The player prefab loads on start via a script. The camera is in the scene. It wont follow the player.

If I drag the player prefab into the scene manually, then drag it onto the camera's follow, it now works.

NOW...Both player and camera objects are set to don't destroy on load. I load a second scene. The camera is following the player. When I load the first scene back. The camera won't follow the player. The transform isn't missing BUT when I change the camera's Culling Mask to nothing and back to default while still in play mode, IT STARTS WORKING.

So frustrating.

ember tangle
#

okay you guys rock thanks for the patience 🙏

wintry quarry
summer stump
#

You sent a picture of selecting NOT a deleted thing

sullen galleon
#

ok now i have a qustion: why the hell is the counter not going up? it's not being reset anywhere

summer stump
eternal falconBOT
sullen galleon
hushed hinge
teal mason
summer stump
hushed hinge
dusty shell
#

!code

eternal falconBOT
summer stump
hushed hinge
summer stump
dusty shell
summer stump
wintry quarry
#

they're not comparable

dusty shell
#

I mean I was told to try an enum but when for a dictionary in the end

hushed hinge
wintry quarry
#

You could and should use enums as the key to the dictionary instead of strings though

eternal needle
#

That is an absurd use for a dictionary though

hasty sleet
summer stump
wintry quarry
#

I mean a Dictioanry<string, bool> is pretty useless though yeah

hushed hinge
dusty shell
wintry quarry
eternal needle
hasty sleet
#

I agree. The implementation seems largely redundant and difficult to read.

#

Why do moveType["running"] instead of MoveType.Running which will work just fine as an Enum?

hushed hinge
# hushed hinge 😢

I never used github desktop before... so I don't how it can be up to date if i commited all my chanes recently while this changing so much in stage 1-1 was recently...

dusty shell
wintry quarry
#

Your script with bool vars instead

#

it's the same

#

just simpler

summer stump
hasty sleet
#

I would recommend against bool variables

hasty sleet
#

Bool variables imply a possible state where two bools can be true at the same time, but it's logically not possible

eternal needle
summer stump
hasty sleet
#

Instead of

bool isWalking;
bool isRunning;
bool isIdle;

An enum would be better because it is a direct switch between one of three states, leaving no ambiguity.

MoveState _moveState;
public enum MoveState
{
    Walking,
    Running,
    Idle
}
wintry quarry
#

indeed

dusty shell
#

I tried but I really don't understand enums

wintry quarry
hushed hinge
dusty shell
wintry quarry
# dusty shell I'm just slow cl

Imagine we made up a fun language between you and I where instead of "zero" we say "Walking", instead of "one" we say "Running" and instead of "two" we say "Idle".

#

that's all an enum is

hasty sleet
#

Enums are a mapping of strings to numbers.

public Enum ExampleEnum
{
  HandyString = 0,
  OtherString = 1,
  NotReallyString = 2 // The "= intLiteral" is optional
}
eternal needle
hasty sleet
#

It's almost exactly what you're trying to do with movetype["walking"]

hushed hinge
summer stump
eternal needle
#

Google will tell you more than I can, temp scene files are made when you enter play mode

hasty sleet
#

Behind the scenes, Enums map strings written as if they were variables (e.g. not as "var_name" but as var_name) so you have a consistent way to associate a variable with a number

#

And if you have a single variable that is of type Enum, then that variable can only switch between one of the enum options

#
// Define the enum
public Enum Movestate
{
  Walking,
  Running,
  Idle, // Trailing comma optional
}

// Semantically equivalent to:
public Enum Movestate
{
  Walking = 0,
  Running = 1,
  Idle = 2, // Trailing comma optional
}
hushed hinge
summer stump
dusty shell
hasty sleet
#
// Store MoveState enum in our class
public class SomeClass
{
  private MoveState _moveState;

  // Now, MoveState can either be Walking, Running, or Idle.

  private void Awake()
  {
    // Initialize _moveState as being Idle
    _moveState = MoveState.Idle
  }
}
hasty sleet
dusty shell
hasty sleet
#

The class variable in your movement controller can store a data of type Enum so it logically must be one of your defined enum values

#

No problem!

dusty shell
#

also is there a way to move the moveInput getter out of the walk

#

I wanna get it outside the onWalk just for preference

hasty sleet
#

Yeah, when you reference the class variable, there is no get required

#

That whole if/else is redundant

#

The variable itself is a "get"

hushed hinge
hushed hinge
dusty shell
hasty sleet
#
if (Input.GetKeyDown(KeyCode.Up) || /* walking movement */ )
{
  _moveState = MoveState.Walking
}
summer stump
hasty sleet
#

If this is a player controller, I would just read their input keys

summer stump
dusty shell
hushed hinge
hushed hinge
hasty sleet
#
if (Input.GetKey(KeyCode.Up) || Input.GetKey(KeyCode.Left) || Input.GetKey(KeyCode.Right) || Input.GetKey(KeyCode.Down))
{

  if (Input.GetKey(KeyCode.Shift)
  {
    _moveState = MoveState.Running
  }
  else
  {
    _moveState = MoveState.Walking
  }
}
hasty sleet
dusty shell
summer stump
hasty sleet
#

Yes, it is.

hushed hinge
eager wolf
#

so i have a game UI (canvas) and multiple scenes. What would be the best way for me to keep the same UI across all scenes? Don't destroy on load? or?

hasty sleet
#

I'm not familiar with the new input system since the old one suits my needs and I've used it

summer stump
#

Get that file, move it in..

summer stump
hushed hinge
eager wolf
summer stump
hushed hinge
wicked stratus
#

quaternion.identity is not turning the rotation x y z to zero, it's setting it to different values. i want to change the rotation to 0,0,0

#

it's changing it to -90, -90, -90

#

more specifically -89.526, -90, -90

summer stump
hushed hinge
summer stump
#

If you are instantiating a prefab, then the prefab must be rotated already

wicked stratus
#

when i try quaternion.euler(0,0,0) it also doesn't work

#

i believe the same value

wintry quarry
wicked stratus
#

yes the same values

summer stump
wintry quarry
#

Are you mixing up rotation and localRotation on a Transform?

#

the thing in the inspector is localRotation

wicked stratus
wicked stratus
#

ok yes i was mixing up rotation and localrotation

#

it works now

#

thank you, that makes sense

vestal ether
#

Where does everyone learn C# from. Is there a good place to just take free lessons or watch videos and learn C#.

hushed hinge
#

and I don't have much time left

vestal ether
hushed hinge
rich adder
#

didnt you setup Version Control last time ?

eternal needle
hushed hinge
rich adder
#

huh? bet I can look back in time and see it was suggested to you multiple times

rich adder
#

this is the main reason vc even exist

hushed hinge
#

and i don't have it

eternal needle
#

you do have version control setup. that is github

teal viper
#

That's a great opportunity to pause you project and go learn the basics finally.

eternal needle
#

you simply didnt use it

summer stump
# hushed hinge no?

Yes you did. You showed a screenshot of it too. Version control is git
You just didn't USE the version control like you should have.
We even told you that you need to commit multiple times in the past. You apparantly chose not to

vestal ether
teal viper
summer stump
teal viper
#

Oh, nvm. I though it was unity learn.

hushed hinge
summer stump
hushed hinge
summer stump
wintry quarry
teal viper
eternal needle
# hushed hinge I know, but i don't know which one like in stage 1-1 is that holds a lot of thin...

At this point, you can probably just assume the scene is gone forever. Even if you look into restore points if your OS makes them, you'd lose everything else done on your pc between now and then.

Do yourself a favor and experiment with github. Maybe first commit everything you have via github desktop. And then after you push them, do yourself a favor and make changes on a simple text file and see what the actual difference is. Change the file, look at the file on github, commit and push the file, then look at the file again. Notice the change

#

You really dont wanna be learning how to not blow up your project, with your actual project that you spent months on.

hushed hinge
umbral bough
#

Hi, I've been struggling with this one for a while.
When an x rotation is < -90 or > 90, y rotation is inverted.
If I try to fix that with a ternary I sent here, it works for the most part, but then quaternions being quaternions somehow transform rotation from say x -180 to z 180 or something like that and the script fails.
This is the only code I have and as you can see, I am not setting the z position anywhere.
Am I missing something obvious here or what?

public class CameraScript : MonoBehaviour
{
    [SerializeField] private float _rotSpeed;
    private Vector2 _prevPointerPos = Vector2.zero;
    private Vector3 _rot = Vector3.zero;
    private void Update()
    {
        var pos = Misc.GetPointerPos();
        var delta = (pos - _prevPointerPos) * _rotSpeed;
        _rot.x -= delta.y;
        _rot.y += transform.localRotation.eulerAngles.x is > 90 or < -90 ? -delta.x : delta.x;
        transform.localRotation = Misc.VectorToQuaternion(_rot);
        _prevPointerPos = pos;
    }
}
wintry quarry
#

btw this is not a quaternion problem this is an euler angles problem

umbral bough
wintry quarry
#

In simple english can you explain what you're trying to check with this ternary?

umbral bough
umbral bough
wintry quarry
#

you mean you want to know if you're upside down?

umbral bough
#

yes

wintry quarry
#

Simple:

Vector3 up = transform.up;
bool upsideDown = up.y < 0;```
vestal ether
umbral bough
#

let me test that out, thanks, never went outside my original idea enough to think of transform.up 🤦‍♂️

wintry quarry
wintry quarry
#

you can also use the dot product which is slightly more efficient but this is more understandable imo

vestal ether
wintry quarry
vestal ether
#

no unless safari has one by default

umbral bough
wintry quarry
#

this happens to work because we're comparing with the world y axis
but you could generalize this to check if we're facing opposite any direction using the other approach

vestal ether
wintry quarry
wintry quarry
umbral bough
#

thanks again!

wintry quarry
vestal ether
#

also mind i ask how u ogt dark mode?

#

is that just ur browser's color

wintry quarry
#

idk

wintry quarry
vestal ether
#

I do not have that 💀

wintry quarry
#

no idea

rich adder
#

I usually use Dark Reader browser extension though

wintry quarry
hushed hinge
vestal ether
rich adder
#

or its bound to happen again

hushed hinge
iron tulip
#

does anyone know how to make it so whenever you add a velocity to a rigidbody and it collides with a wall theres less velocity applied ? i cant really explain it well i hope this stupid drawing helps this make sense 😭

wintry quarry
#

what do the red and blue arrows mean

iron tulip
#

dammit 💔

cosmic dagger
iron tulip
#

im trying to make it so my rigidbody doesnt slide up things ,,

cosmic dagger
#

what do you mean by there is less velocity? when you hit a solid object, do you want to keep going but slower because of the mass of the obstruction?

wintry quarry
iron tulip
#

whenever you apply a force to a rigidbody itll go up walls so im assuming if you dont apply a force in that direction it wont slide

#

up

wintry quarry
#

If you want to slide less, give the wall a material with a lot of friction, or kill the velocity that is orthogonal to the wall in OnCollisionStay or something

frigid sequoia
#

Is there a way to tell a Nav Mesh Agent that I want it to REMAIN at stopping distance instead of letting the target move within it's range or do I have to code that manually?

wintry quarry
#

Definitely need to code manually

iron tulip
frigid sequoia
#

Cause I could calculate a position from the target and the agent's posstion but I have to be sure it is an avalible position on the NavMesh

wintry quarry
teal viper
frigid sequoia
teal viper
#

The other day you were struggling with basics iirc. Why are you doing networking??

frigid sequoia
teal viper
frigid sequoia
#

Cause it is very likely to get a point outside the NavMesh and just get really sticked to the walls

teal viper
#

That would be ruining the whole point of that API.

frigid sequoia
teal viper
frigid sequoia
#

Like basically the whole area that is outside the NavMesh is positions where it might get stucked on walls

teal viper
#

Then don't pass in a position that is outside the navmesh

frigid sequoia
frigid sequoia
teal viper
#

You can define some bounds that you would only sample points in for example.

teal viper
#

As for how you deal with it, is up to your game logic.

frigid sequoia
#

I guess the right way of doing it would be: Get vector from target to agent, then multiply it by the range, then get closest point in the NavMesh to that point; if that point is within range of the target (meaning it had to move closer due to boundaries of the mesh), get a new one (probably the same vector with opposite direction should work?)

#

Dunno

#

Seems really messy to work smoothly

teal viper
#

Well, what do you want to happen? What is this logic for?

frigid sequoia
#

Is supposed to be for the typical "treasure enemy" that flees at the sight of the player and after a while it dissapears

#

So basically I just want this to be as far away of the player as possible

teal viper
frigid sequoia
teal viper
runic peak
#

Hi, I'm trying to make a barebones rhythm game and I ran into some input issues - when there's a sequence requiring to press 2 keys at once on the keyboard, sometimes the keys just won't register when I press both keys simultaneously. I tried to do some research and apparently it's an old bug that hasn't been fixed? Or maybe it's because my code is bad so here's the code for the input.
https://github.com/Unity-Technologies/InputSystem/issues/663

GitHub

While testing my game I found that sometimes when pressing/releasing multiple buttons quickly many times in a row, sometimes one of the keys get stuck in a pressed state until any other key is pres...

slender nymph
#

your code is unrelated to the github issue you posted, you are using the old input manager, not the input system

#

the code you've shown can also only ever detect a single key press at a time

runic peak
#

I'll try to look into the input system, thanks

queen adder
#

I could use some help, I'm using UnityEngine.UI, created a Slider variable, and all I want to do is change my color to match the Slider Variable. For some reason my Colors red value keeps going to 191, unless the slider is at 0, then the Colors red value goes to 0. There's no in between.

#

I'm just messing around with UI and trying to get comfortable with it

#

but this is a strange problem I'm encountering, note there's no other code

languid spire
#

Color takes values between 0 and 1. So your slider needs that too. If you want 0 to 255 use Color32

queen adder
#

ohh, okay cool ty Steve

#

So just to feed my curiosity, if I wanted to use a value between 0 and 1, how would I do that? I realized floats are not accepted, however, bytes are. So this doesn't give any errors, but it also does not work.

languid spire
#

floats are accepted. Color is 4 float values

queen adder
slender nymph
#

that's not a Color

queen adder
#

ohhh

languid spire
#

that is Color32

queen adder
#

4 float values

languid spire
#

Color - 4 float values. Color32 - 4 byte values

queen adder
#

understood

languid spire
#

no, you are still using Color32

queen adder
languid spire
#

ok, there is automatic conversion between Color32 and Color

queen adder
#

it was an oversight cuz I was so focused on new Color, but this is pretty much what you meant correct?

languid spire
#

yes. you can also do

Color color = new Color32(126,255,255,255);
green ether
#

Is there any actual difference between Color and Color32 then?

#

Id assume color would use more memory?

#

But its not so much more that it matters right

languid spire
#

yes, 4 times the memory. Also Color32 is what eventually ends up on your monitor

green ether
#

yeah

queen adder
languid spire
#

manupilating floar values is much slower than manipulating byte values

green ether
#

but this is is extremely negligable for most usecases right?

#

Just preference for how you want to write them?

#

I remember using both at some point

languid spire
#

well, not if you are scanning the pixels of a large texture for example. It can make a huge difference

green ether
#

ohhh

#

Good point

#

I do do that in my current project but only for small 20x20 pixel images

#

But i need to check wether i use color or color32

languid spire
#

really the only thing that should use Color is shaders because that is what the GPU works with

#

CPU based stuff should always use Color32

green ether
#

alright I will go through my stuff and replace it where I can. Thanks!

green ether
runic peak
#

I tried to use the input system + separating simultaneous inputs for debugging, now I'm puzzled on why only 1 of the 2 supposed methods are run only when there's simultaneous inputs in the same frame

keen dew
#

The same reason as before. Because you use an else if chain so only one of those blocks can ever run

queen adder
queen adder
#

I figured, i'm just slow

runic peak
ivory bobcat
slender nymph
#

which, of course was also part of the issue with your previous code so i have no idea why you decided to swap to the input system for this issue

green ether
languid spire
#

yes, the chances of 2 keys being pressed on EXACTLY the same frame are virtually zero

runic peak
#

I don't think the issue was "I didn't press 2 keys"? It's that the bracket for F+J only executed one of the 2 methods inside (despite the video showing that I pressed 2 keys multiple times to cancel out the falling objects)

slender nymph
#

no, the issue is that you didn't press the two keys in the exact same frame which is the only time that first if statement will ever be true

#

you need literally frame perfect timing for that which is almost physically impossible, especially if you are running more than 60 fps which is a strong possibility

queen adder
#

alright so I'm experimenting, I found this, colors are expected color except, the variable color32. Why is this?
also, dw, I do not use numbers when naming variables, this is just me testing.

languid spire
#

in fact I believe that for mobile that is not even possible at all because of the way input is registered

runic peak
#

if I didn't press F+J on the same frame it wouldn't have wrote "F + J pressed" on the console though?

queen adder
queen adder
#

yea

slender nymph
green ether
#

not new Color32

#

so its basically 1, 1, 1, 1

#

which is white

queen adder
#

yea, it was an oversight again, I keep overlooking the details

#

ty guys

runic peak
#

so there's something preventing 2 Add methods from executing at the same time fsr

topaz mortar
#

Is there a difference between FindGameObjectWithTag and FindWithTag?
FindWithTag says it looks for an active element, while FindGameObjectWithTag doesn't specify any info

languid spire
green ether
#

FindWithTag returns only one?

queen adder
#

yea, very true, I need to increase my attention span xD

green ether
topaz mortar
green ether
#

yeah i just realized

#

oopsie

runic peak
#

my apologies, tap is a list so the add() was adding the value to the list

#

wasn't a method

topaz mortar
#

any way to look for an inactive GameObject?

slender nymph
# runic peak wasn't a method

Add absolutely is a method. it's just not the source of the issue here. however you are processing the data in the list is the issue

green ether
runic peak
#

ah my bad terminology

slender nymph
topaz mortar
#

but I'll just reference it instead

fair veldt
topaz mortar
#

Transform equipmentSlot = CharacterLogic.Inventory.Equipment.transform.Find(equipmentType);
is this too much?

eternal needle
hasty sleet
#

In general, I would advise against using Find() unless there is no suitable alternative, and even then, still consider ways to not use Find()

eternal needle
#

the equipment part itself should probably handle that whole finding an object thing, rather than needing to access the transform and .Find on it

topaz mortar
#

I'm actually just asking about this part: CharacterLogic.Inventory.Equipment still re-building the rest

hasty sleet
#

For my equipment system, I have a dictionary that maps equipment types to equipment slots (Helmet to HeadSlot, for example).

If I'm looking for the first equipment item in the inventory, then I have a function FindFirstItemInContainerOfType(ItemType itemType) { ... }

topaz mortar
#

guess I could reference each equipment slot too

hasty sleet
#

Accessing properties is very fast and is effectively zero-cost as far as you should be concerned

topaz mortar
#

I could put Equipment in CharacterLogic too, but I need it more in Inventory

hasty sleet
#

Searching for items in large collections is very unperformant

burnt vapor
topaz mortar
#

it's just like 15 item slots, but yeah I'll add references for them instead

burnt vapor
#

Then you can just use Equipment/this.Equipment

hasty sleet
topaz mortar
hasty sleet
#

PlayerInventory // PlayerController // etc. is good practice if you plan on scaling more

burnt vapor
#

As with a lot of things it really depends

topaz mortar
#

it just looks weird, that's why I'm asking

burnt vapor
#

You're probably better off by making a singleton if that helps it

#

Accessing static data can be hard to scale and test

topaz mortar
#

I really don't want any of this stuff to be singletons in case I ever want to expand the game

burnt vapor
#

Assuming this is static. The way this code was capitalized makes me think it's all static

topaz mortar
#

none of it is static though?

eternal needle
#

i was just assuming they are properties

hasty sleet
#
Player
  |
  --- PlayerController
  --- PlayerMovement
  --- PlayerInventory
  --- PlayerStatusEffects
 ...
burnt vapor
#

Then idk 🤷‍♂️
Can't really give advice on a single line of code like this

hasty sleet
#

It's only weird if you start tunneling through public variables in convoluted ways like PlayerController.PlayerInventory.PlayerStateManager.WhateverElse

burnt vapor
#

If you want proper help then you should actually share the context around the code

#

Otherwise I'm just throwing out possible suggestions that likely won't apply

topaz mortar
#
{
    [SerializeField] public Inventory Inventory;```
```public class Inventory : MonoBehaviour
{
    [SerializeField] public GameObject Equipment;```
burnt vapor
#

Trying real hard not to comment on code style here

eternal needle
#

i will, these should be lowercase

burnt vapor
#

Not only that

topaz mortar
#

feel free to comment

hasty sleet
#

public variables are usually upper-case though?

eternal needle
#

true i didnt even see the public part

#

brain skipped it when i saw SerializeField

hasty sleet
#

private class variables are usually _likeThis

burnt vapor
#

And if you do the attribute is completely useless

#

Please make it private

hasty sleet
#

What's wrong with public fields?

burnt vapor
#

I think that is explained very well online

hasty sleet
#

It won't have a realistic impact on anything

eternal needle
hasty sleet
#

What if another component wants to access it? You can use properties instead of fields but the result is ultimately the same

topaz mortar
topaz mortar
hasty sleet
#

public/private matters more when you're trying to shield proprietary information from less-authorized users in enterprise networks. Not super applicable to Unity unless you're on a massive prod team and trying to hyper-modularize, no?

burnt vapor
#

A public field breaks encapsulation

#

I don't really feel like explaining every single reason when this can just be found online

hasty sleet
#

So what?

#

Haha it doesn't really matter

burnt vapor
#

If another component wants to access data, you can have a property with a public getter

hasty sleet
#

It doesn't need to be perfectly encapsulated to serve its purpose

#

And then the getter will do the exact same thing as the field

topaz mortar
#

I know the diffence between public & private
I've been using private for 6 months and it's just been annoying me and slowing me down, I haven't found a single good reason to use it in my project

hasty sleet
#

Thus with no difference except added complexity

eternal needle
#

well yea it doesnt matter in terms of gameplay, but god seeing public fields everywhere is such a nightmare

#

theres literally 0 added complexity

topaz mortar
hasty sleet
#

The complexity of having to care about public/private is complexity itself to manage

#

Just do what works and meets requirements. Using public fields won't break your game

languid spire
#

Also for value types there is a great deal of added complexity

eternal needle
burnt vapor
#

By all means keep using public fields, but in a few weeks it becomes very hard to udnerstand what uses it 😉

#

And suddenly it's a lot more complex than when it woul dhave been if you just sticked to the property

#

I think arguing is pointless, you just seem to lack the experience to understand when to use something

hasty sleet
#

I'm a software engineer at Microsoft

#

I think I know how it works

#

Because there's a ton of bickering at the lower levels about what is right and what ought to be

#

And it's pointless because all that matters is meeting requirements

burnt vapor
#

Oof, then I'm very surprised you don't see the point of encapsulation

hasty sleet
#

I know what the point of encapsulation is

#

I'm telling you that you're overestimating the importance. You're not designing Facebook, you're designing an indie game

#

You don't need dependency injection to make your sprite go up or down

eternal needle
#

I mean if your only point is gonna be that it doesnt affect gameplay, then you could argue literally anything if the end gameplay is the exact same.

#

there is absolutely no way you are comparing a property which exposes a private field to DI

burnt vapor
#

Sorry, I stopped caring about convincing you when you mentioned properties are "too hard" to use over fields

hasty sleet
#

You don't need to protected internal your variables to hide them from other components that you are the sole controller of. C# was made for enterprise to hide proprietary information and improve upon Java. Just meet business requirements

burnt vapor
#

But please stop trying to give bad examples to beginners here

hasty sleet
#

I never said they were too hard to use, I said it's pointless to bicker about public fields = bad and public properties = good

#

You're boasting on the ivory tower. It just doesn't matter at all

languid spire
hasty sleet
#

I agree it's generally good practice to keep fields private and use getters and setters but it's just such a headache to police it all. Just get the job done. Meet requirements and refactor when needed

eternal needle
#

This is literally 2 lines of code. The amount of headache is solves from someone just modifying it later when they shouldnt and causing issues is justified

hasty sleet
#

It's telling a beginner something that doesn't really matter

#
  1. Make it work
  2. Make it right
  3. Make it fast.

In that order.

#

You're trying to make it right before it's working

eternal needle
#

🤷‍♂️ if you consider a property too much to manage then theres really nothing i can say about it. And im usually pretty against the whole enterprise solutions that people show in their projects

hasty sleet
#

I agree that what you're saying is best practice, but I just don't think it matters enough to tell a beginner how it ought to be as if their choice was bad. It just doesn't really matter for their use case.

#

Never said it was too much to manage. I'm saying it's not worth trying to police a beginner into using the "correct" way to code. It just doesn't matter.

#

Use a property when you want extra control over getting and setting operations, like when you want to invoke an event when a property is set so you can decouple components. I really like this use of properties personally. But if I just store data, why doesn't a field work just fine? I just don't think it's important.

topaz mortar
#
{
    [SerializeField] public Inventory Inventory;```
Alright, so the reason I'm doing this is because I use CharacterLogic.Inventory in nearly every other script I have that only has the reference to CharacterLogic, so I don't also have to reference Inventory there
How does making it a public property over a public field change anything?
I understand the difference between public & private, I've just NEVER had a usecase where it actually mattered to me, so I don't understand why you would use private, I understand the theory behind it, but it just doesn't apply to anything I'm doing
burnt vapor
topaz mortar
#

You want me to do this right?

{
    [SerializeField] private Inventory inventory;
    public Inventory Inventory { get => inventory; set => inventory = value; }```
Which is exactly the same result?
hasty sleet
#

Thus, the adage:

  1. Make it work
  2. Make it right
  3. Make it fast

There's no point in policing style when their requirement does not work.

topaz mortar
#

or am I still missing something?

burnt vapor
void thicket
slender nymph
topaz mortar
void thicket
#

Access modifier is all about constraints

#

Constraining yourself from doing something wrong, specifically

hasty sleet
#

private Inventory inventory does fine without needing extra logic for getting and setting operations

topaz mortar
#

so the whole idea is that I should be doing
public Inventory Inventory { get => inventory; }

void thicket
#

or just public Inventory Inventory => inventory

topaz mortar
#

so I can't modify my inventory outside of it?

eternal needle
#

yes nothing can just do CharacterLogic.Inventory = null

#

because now its just a getter

void thicket
#

Yes and if you want to modify something then you probably want it through proper method

hasty sleet
#

Or you can do
public Inventory Inventory { get; private set; } to restrict setting to in-class and getting to any class

burnt vapor
#

No point in exposing it yet

#

Once you actually want to replace it you can read it. Maybe even make a method and apply validation or different logic to prevent issues

hasty sleet
#

Why not focus on getting the inventory to work first before focusing on optimizing the accessibility

burnt vapor
#

The question was about code style specifically on the small snippet that was given

#

If that wasnt the case I would not have given the advice

topaz mortar
# burnt vapor Then remove the setter

the thing is, I never program things where they're not supposed to be, so I never thought about this lol
and I'm a one dev team so don't have to worry about others
but now I at least understand why everyone says it's so important to set fields to private lol

topaz mortar
hasty sleet
#

So what problem are you trying to solve?

topaz mortar
#

I'm asking for information and trying to learn to optimize my code and prevent bad practices

hasty sleet
#

If you're looking to optimize your code, studying algorithmic time complexity and big-O time of data structures and algorithms is a great starting point. Hash set > binary search through sorted array > search through unsorted array > combination check. *But typically, it's best to avoid optimizing before you have a performance bottleneck.

What constitutes bad practice is nebulous and generally comes down to well-named variables and cleanly-defined interfaces between components. It's largely up to preference and what works for you.

burnt vapor
#

A public field just gives too much accessibility, so hence why you would never see this and instead use properties

#

Even if they are completely empty they would allow for future-proofing any possible changes

languid spire
hasty sleet
#

Dev teams do things the way that works for them. It varies a ton between individuals and teams. The fundamentals are the same: working code that meets requirements and that can be maintained. What that constitutes is contentious.

eternal needle
#

🤷‍♂️ they were literally asking on the style because it was clear they felt something off by having to do A.B.C.D.E.F
telling them do what works is nice and all but its a bit silly to force it through the entire conversation. Properties were also brought up as a way to skip doing A.B.C because A could have a property to access C

hasty sleet
#

Yes, that makes sense by itself. It's when it was mentioned that using a public field would make your game unmaintainable after 2 weeks that I expressed disagreement

#

Undertale's dialogue has control flow of a giant, massive, immense if-then block. Hundreds of lines. Ugly code, beautiful game.

languid spire
#

OMG

hasty sleet
#

Oh yeah, it's a beauty 😎

languid spire
#

never heard of databases, huh

slender nymph
#

assert dominance by writing unmaintainable code

hasty sleet
#

It was apparently maintainable by him, and since he developed it by himself, that's all that really mattered

#

I would not call Undertale a failure despite the horrendous switchcase

languid spire
#

Ok, but what was he thinking when he wrote that?

rough fossil
#

As long as he understood it I don’t see a problem

topaz mortar
languid spire
eternal needle
topaz mortar
topaz mortar
hasty sleet
#

He could have refactored whenever he wanted to, but he never felt a need to, and clearly he delivered results. You're not measured by the cleanliness of your code but by your ability to deliver results.

#

It's still an anti-pattern that should be avoided, anyways.

languid spire
eternal needle
topaz mortar
eternal needle
#

like an example i have, a lot of my abilities check what faction a character is before deciding to damage them (so you cant hurt allies). I have a property like this on my character

    public FactionSO FactionInfo { get; }
    public Faction CharacterFaction => FactionInfo.faction;
hasty sleet
#

It's not luck at all. It's just an untidy chunk of code that fits the purpose.

hasty sleet
#

Clamoring over what code is most clean or most optimal is a programmer's way of procrastinating

topaz mortar
#

never used that before 🙂 what's it called?

burnt vapor
#

That's usually what I do when I need a single instance from somewhere and I don't have some sort of DI system

eternal needle
#

if the current script is using it a lot, then yea id say its justified. Its still just a property

burnt vapor
#

Works fine assuming the instance always exists

eternal needle
languid spire
burnt vapor
#

So something like public MyProperty { get; set; } just gets compiled into a method with a hidden field called a backing field.

#

Hence why Bawsi for example uses a separate field

eternal needle
languid spire
hasty sleet
#

You can set a default value to a property

languid spire
#

because you are turning a simple one cycle instruction into a mess all for what?

hasty sleet
#

Without using a field. It can technically store data

burnt vapor
#

Then you just set the default value of the backing field

hasty sleet
#

You can do
public int MyProperty { get; set; } = 5

#

No field required

burnt vapor
#

Yes, so it sets the backing field

slender nymph
rough fossil
#

Have any of you guys worked on any game projects?

eternal needle
topaz mortar
eternal needle
#

honestly i wouldnt go back and rewrite everything even. its just sometihng to keep in mind

hasty sleet
languid spire
rough fossil
burnt vapor
#

You can select "IL" as the result and if you look in the code you can see it lowers into separate methods called get_MyProperty and set_MyProperty

#

Hence the "fancy methods" I mentioned

topaz mortar
#

meh 😛

languid spire
hasty sleet
#

💀

#

you're an actual wizard

languid spire
#

I am very, very old school, ASM is the only language that counts

hasty sleet
#

I cannot even fathom. That's incredible

languid spire
#

I've been doing this for a very long time

hasty sleet
#

How close do you get when mentally converting from C# to IL?

languid spire
#

100%

hasty sleet
#

Hahaha jesus there's no way

languid spire
#

IL is pretty simple

#

if you think of the IL between

public int A;

and

private int a;
public int A ( get { return a; }  set { a= value; })

you will only use properties when you actually have to

hasty sleet
#

How did you first begin to understand the mapping between C# and IL?

languid spire
#

well, I've been using C# since before it was released, I was one of the beta testers

hasty sleet
#

holy hell you're actually a wizard

languid spire
#

maybe, just very old and experienced

#

and, btw, generally MS devs are not my favourite people

hasty sleet
#

Why not?

languid spire
#

because they write crap code

hasty sleet
#

Which products specifically? The teams vary widely

languid spire
#

Windows basically

#

it's the reason I now need a i7 13 series to do the same I used to do on a i386

winter prairie
#

!blender

eternal falconBOT
hasty sleet
#

Windows being too bulky, in general?

languid spire
#

yes, and very badly designed. I mean, explicitly whoever came up with the implementation of the registry?

hasty sleet
#

Hm, I don't know. It's not a feature I use too often explicitly except when I'm debugging something and I'm usually deep into the rabbit hole.

hushed hinge
hasty sleet
languid spire
burnt vapor
hasty sleet
#

Is there a strong use case for upgrading it besides it looking/feeling outdated?

#

Or do you mean it's bloated, or both?

languid spire
#

both, it is inefficient, unwieldy and very prone to break

#

and NOBODY, not even MS ever cleans it up

hushed hinge
hasty sleet
#

That works. Not a super descriptive name, but it works.

hasty sleet
hushed hinge
#

should i commit ALL of them?

languid spire
# hasty sleet That's fair

My main bug bear is that MS seem to have forgotten that I own my computer not them, so I should have the choice of what it runs and when

hasty sleet