#šŸ’»ā”ƒcode-beginner

1 messages Ā· Page 701 of 1

silver fern
#

ah cool

grand snow
#

hehe

#

If you want to save some inventory state it should be something like:

{
  "items": [
    {
      "id": "gun",
      "amount": 1
    }
  ]
}

then when loading the save data you use the id to retrieve the "gun data" for example
you cant just try to serialize the unity scriptable object as json... its gonna produce junk

#

you can load scriptable objects at runtime for items and then use the id to find it for example

dull grail
#

Thank you

silver fern
#

hm serialized enum doesnt show up in the editor

naive pawn
#

...what?

#

enums aren't supposed to show up

#

fields of enum type are though

#

you sure you're looking at the right thing? perhaps show the declaration and stuff

ember tangle
#

Does it make sense to have all the data in my gameobject as a struct so I can save it easier?

grand snow
#

makes no difference when its saved

dull grail
#

You may search for plugin which add serializable dictionary and do something like this

silver fern
grand snow
#

ha yes you are

#

thats the enum declaration

#

use it as a type when declaring a var

silver fern
#

ahh got it thx

#

Is there any best practice or whatever on where to put the enum declaration or can I just put it in front of the variable declaration?

naive pawn
#

put it where it's relevant

#

you won't be using it just one place

grand snow
#

better to not have it inside a class as it makes using it elsewhere require Class.Enum

naive pawn
#

you'll be using it when you want to use the field of that type too

fresh rampart
#

Can you tell me what this is about? there is nothing on the stage and there are still such errors, the unity version is 6.1 (6000.1.10f1)

silver fern
#

I don't think I need to use this particular enum anywhere else tbh

slender nymph
dull grail
naive pawn
naive pawn
#

i mean what i said

silver fern
#

well I don't understand what you said

dull grail
#

Just move enum to a different cs file

naive pawn
#

how were you checking the damage type before?

silver fern
#

so its just string comparison

naive pawn
#

you don't have strings anymore though

#

so you can't do string comparison

#

you would do comparison against enum members instead

silver fern
#

maybe enum is the wrong solution

grand snow
#

it is the right solution

#

enums are actually an int so that means faster comparison later
e.g. if(damageType == DamageType.Physical)

silver fern
#

ok, well this is in the variable declarations part at the start of the weapons controller, so where should I move it then?

#

make a new script and import it in the controller?

naive pawn
#

if it's relevant to all weapons, i would just put it in that file or that class

naive pawn
silver fern
dull grail
# silver fern maybe enum is the wrong solution

Try something like this

foreach (var entry in damageList) // damageList is dict with key presented as DamageTypes enum
        {
            // True damage bypass any calculations
            if (entry.Key == DamageTypes.True)
            {
                health -= entry.Value;
                continue;
            }
            
            if (dmgResists.ContainsKey(entry.Key))
            {
                reducedDamage += entry.Value * (1.0f - dmgResists[entry.Key]); // or whatever logic you need
            }
naive pawn
#

also don't spoonfeed

silver fern
#

can I have this enum declaration in every weapon controller script or will that cause an issue

naive pawn
#

that will mean you have several enums that happen to have the same name

#

you probably just want 1 enum

#

do you have any centralized weapon-related script? if you do, i'd probably put it there

#

if not, its own file would be fine

dull grail
silver fern
naive pawn
naive pawn
silver fern
naive pawn
#

the weapon controllers

silver fern
#

yeah I mean for what purpose would I have that?

#

or what would be in it?

naive pawn
#

being able to have core logic that's shared between classes

#

even simple things like having an owner

#

or making sure some functionality is included, specifying common method names

#

or being a common interface that you can assign to stuff without having to use MonoBehaviour

fresh rampart
silver fern
#

the only thing they might have in common is reading the mouse position in Update() I suppose

naive pawn
#

imagine you add controller support, now you have to rewrite that logic in however many weapons you have instead of just one central base weapon

silver fern
#

I'm not sure the game would even be playable with anything but keyboard and mouse

naive pawn
#

it's a theoretical, i barely know anything about your game

silver fern
#

How would that work then? Should the weapon controller only have the mouse position update and then import the rest from another script?

dull grail
#

The point is you can make 1 base script which will be inherited by other scripts and you can just change base logic in 1 place instead on redoing it in every script separately

naive pawn
#

no, the other custom weapons would be extending the base weapon controller

silver fern
#

I can't find consistent information on how to do this

#

every site is saying something different

polar acorn
#

That tends to happen when there's multiple ways to do something

silver fern
#

then how do I do it

grand snow
#

its a general object oriented programming concept using inheritance

polar acorn
#

I was just pointing out that there are often many ways to achieve the same goal and which one is correct is highly dependent on the situation you're using it in

silver fern
#

maybe I should use a dictionary instead of an enum

#

or something

naive pawn
#

probably not, given that you wanted limited options

silver fern
#

well I don't see how to do what you said

#

so enum isn't gonna work like this

naive pawn
#

huh?

#

that's unrelated

silver fern
#

you said I had to do it this way to use the enum in multiple controllers

naive pawn
#

no i didn't

#

i said you can't put the enum in multiple places

#

the above like, 30 messages, were just trying to find that central place

silver fern
#

and I told you there is none

naive pawn
silver fern
#

ah I didn't see that

#

so I make another script containing just the enum, attach it to the gameobject in addition to the controllers, and then import the enum from there?

polar acorn
#

Honestly you should be defining enums in their own file pretty much always

polar acorn
naive pawn
#

why are you so set on importing stuff lol

silver fern
naive pawn
#

script != component

polar acorn
silver fern
#

then where do I put the script

polar acorn
#

Wherever

naive pawn
#

a script is a file that contains code

#

a component is a class that extends UnityEngine.Component
classes live inside scripts
thus, components live inside scripts

polar acorn
#

Making a class that inherits from MonoBehaviour makes that class a component (because MonoBehaviour also inherits from Component)

#

A script is just a file containing code

silver fern
polar acorn
#

If your code isn't a MonoBehaviour it isn't a component

silver fern
#

as you can see there are script components and other components

polar acorn
#

Enums are not components

#

Enums are types

#

like int and string and Vector3 and whatnot

naive pawn
silver fern
#

then why does it say script on only the ones at the bottom

#

this is confusing

naive pawn
#

because those are from your scripts

polar acorn
naive pawn
#

the others are from packages or built-in, where it isn't really touchable as a file

polar acorn
#

Scripts can contain components, but they are not the same thing

#
public class Thing
{
  public int Num;
}

Slap this in a .cs file and you have yourself a bonafide script-that-doesn't-contain-a-component

silver fern
polar acorn
#

it's a Unity component

#

that is not a script

silver fern
#

chris just said they are all scripts

#

anyway, so I make a new script in the script folder with all the other scripts, and define only the enum in it yes?

polar acorn
#

No actually they literally just said the opposite

polar acorn
naive pawn
polar acorn
#

"Components live inside scripts" != "Components can only come from scripts"

#

This is programming. Statements mean exactly what they say and nothing more

naive pawn
polar acorn
#

The following are axiomatically true and do not conflict:

  • Components can be attached to GameObjects
  • Components can be defined in scripts
  • Components can be provided by Unity
  • Scripts can contain components
  • Scripts do not need to contain components
polar acorn
naive pawn
polar acorn
#

I don't know if I'd count a file containing basically pure externs as "A C# script" but at this point we're just being pedantic and probably confusing the matter even more

naive pawn
#

true

silver fern
#

true

#

so about that enum script

polar acorn
#

Just a file with the enum in it

#

Not inside a class in the file

#

just file containing enum

silver fern
#

ok. normally, to reference another script, I'd use GetComponent(), but since this is not a component, how do I best use the enum in the controller script?

rich adder
#
enum CoolEnum {One, Two, Three}```

// any script
private CoolEnum myCoolenum;
void Foo(){
myCoolEnum = CoolEnum.One``` etc.

naive pawn
#

"referencing" is just.. using its name

silver fern
polar acorn
#

You don't reference an enum

#

it's just a type

#

You use it like you'd use int

rich adder
#

^ enum is not a reference type, a numerical type (its literally in the name)

naive pawn
#

have you been importing the files for your other components?

silver fern
#

well there was no need to since they're all self contained

#

but they have stuff like using UnityEngine;

naive pawn
#

0% interop 100% modularity is insane

silver fern
#

😟

naive pawn
#

but anyways yeah to finish out that thought - in c#/java, there is a concept of namespaces (packages for java), where everything in a given namespace can use everything else in the same namespace directly

rich adder
# silver fern but they have stuff like `using UnityEngine;`

enum can also be in a namespace if designed as such you'd need also its containing namespace

namespace AwesomeSpace {
enum CoolEnum { etc .}
}
//script 
private CoolEnum coolEnum; // not found unless you do using AwesomeSpace
or
private AwesomeSpace.CoolEnum coolEnum```
naive pawn
#

and "no namespace" is also its own namespace, the anonymous namespace

#

(unlike js/ts/py where it's just files)

silver fern
#

ok, I see

#

I thought it would ignore files if I don't explicitly tell it to use them

rich adder
#

there is no concepts of "files" in codespace

#

thats just for human organizing

naive pawn
#

(in c#/java)

rich adder
#

lets do most* ig lol

silver fern
#

I didn't think it would add the contents of that file to the codespace if I didn't explicitly tell it to

naive pawn
rich adder
#

I'm just assuming tbh. I only knew a handful and mostly are C family anyway

#

except I guess for Header Files if you chose so in c++ ?

silver fern
#

most of the ones I know need explicit imports

rich adder
#

imports and namespaces are pretty similar

#

or maybe more of assemblies thing ig

naive pawn
#

implicit sharing, no mention of files, import gets all
c# & friends - namespaces
java & friends - packages
file names, import gets all
ruby, c/c++
file paths, import gets all
sh
file paths, import gets specified
js/ts, py

apparently it's not something very generalizable, the more i think about it

silver fern
#

alright, thanks a lot everyone

#

Is there a way to find a specific subcomponent of a game object from another component on a different branch of the game object tree?

naive pawn
#

a component of a child?

#

subcomponent would mean it's part a component, that's not a thing

silver fern
#

I'm in PlayerControllers and I want to get the position of ProjectileSpawner

rich adder
polar acorn
silver fern
#

oh yeah that would work

#

cool ty

polar acorn
#

If you have the option to drag something in you should do that

fair nymph
#

I don't see any bricks even though I moved the camera

polar acorn
silver fern
#

I'd probably add a bunch of print()s to make sure all the values are what they're supposed to be

graceful abyss
#

Could someone please tell me what help file to read to make a timer to count from 0-60 over 1 minute?

rich adder
#

there is no "help file" for a timer, there's plenty of ways you can google how to do it

polar acorn
rich adder
#

float  currentTime ;
void Start() { currentTime = 60 }

void Update(){
currentTime -=  Time.deltaTime;
if(currentTime <= 0 ) //timer done```
graceful abyss
rich adder
rough granite
scarlet aspen
#

Hello sorry for the dumb question, I recently started doing c# scripting on unity but honestly I was following a series that explained but was quite confusing of Kodeco... Can anyone recommend me a good youtuber to follow some videos or anything else to start learning?

slender nymph
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

scarlet aspen
#

I think the learn beginner scripting is a little bit confusing too, am I wrong?

naive pawn
#

i mean.. if you don't have any prior experience, then it is, just, a whole new thing to learn

scarlet aspen
#

You're also right...

fierce shuttle
naive pawn
#

there are resources pinned in this channel as well

scarlet aspen
polar acorn
#

Just do both

scarlet aspen
#

Yeah why not

fierce shuttle
chilly wolf
#

Hello again, i'm trying to set up mouse input to switch between 3rd person perspective camera and orthographic (isometric).

scroll up for third-person
scroll down for isometric

I’m using cinemachine and i made three scripts: CameraManager, CameraRegister, and PlayerCamera. The input works, and the transition between cameras plays nicely. Weird part is that when i scroll down to switch to the isometric camera, the projection stays in perspective instead of switching to orthographic. Any idea why that might be happening?

rich adder
chilly wolf
#

I will show you, just a second

hexed terrace
#

!code - use a paste site

eternal falconBOT
chilly wolf
#

Don’t know how this site works properly, but i think it’s possible to see the three scripts: https://paste.mod.gg/xbsmhpzmncbn

The camera setup in the spectator is pretty simple, tho. I have assigned the main camera with the CameraManager script and the two other cameras: "Cinemachine3rdPerson" and "CinemachineIsometric", each with the CameraRegister script. The 3rdPerson camera is in perspective, and the Isometric is in orthographic.

Edit: While looking to write this to explain to you, i found the problem (bruh). There’s an option for Mode Override in the Lens config. Anyway, I’ll show it to you anyway so you can see if it’s properly done.

errant umbra
#

@autumn compass

#

here

autumn compass
#

Ok, thanks

rich adder
#

<@&502884371011731486>

north kiln
#

!mute 1117165952241516564 3d not sure what this spam is about but do it again and you're gone.

eternal falconBOT
#

dynoError I couldn't find that user

north kiln
#

Bizarre

polar acorn
#

Is he gone? Or was he never here to begin with? [X-Files theme plays]

lofty mirage
#

I'm too lol if that's the case

rugged beacon
#

is there a way to change a graphic alpha like graphic.color.a = alpha
rather than create a new color

rich adder
rugged beacon
#

yea, just an example, want to know if there a way to do it

polar acorn
#

color = new Color(color.r, color,g, color.b, alpha)

wintry quarry
rugged beacon
#

nvm goit it

wintry quarry
#

But no there's no way to assign it without assigning the whole color

#

other than making a helper method

rich adder
wintry quarry
rugged beacon
#

perhaps but this will do for now fr

acoustic belfry
#

how i can check if a 2dobject's rigidbody is still?

grand snow
#

Velocity?

#

I forget if it's active/sleep state can be checked or if it's reliable

acoustic belfry
#

idk, i was thinking on
rb2d.linearvelocity == vector2.zero

but i dont know if that's not very optimized

visual fable
#

zoned out and wrote an hour of spaghetti code

#

idk how it works so well but it sucks

polar acorn
#

If you're worried about performance, profile it and check

acoustic belfry
#

ok

#

but in theory rb2d.linearvelocity == vector2.zero should do it, right?

polar acorn
# visual fable

Immediately I see that you should just use one overlapAll with a mask containing all of those layers and then check the layers of each thing you detect

rich adder
visual fable
eager elm
visual fable
#

update one this, changed one thing, dont know what it was, and now every single item is cheese

timber tide
# visual fable

Few ideas on minimizing, your overlap check can be singled into a single check with a filter that has all of those layers. You can then iterate over the return values to compare to what they might be.

rich adder
#

Debug.Log the velocity and see what values you're getting when you think its stopped then create a variable for that as min or its a max.. however you want to think of it ig

timber tide
eager elm
#

Is there a way to add interfaces to Unity classes? Like IHasColor to SpriteRenderer and Image.

rich adder
#

nah

teal viper
timber tide
#

MYBetterSpriteRender: SpriteRender, IHasColor

#

No wait, wrong engine

eager spindle
#
public class SpriteRendererHasColor : SpriteRenderer, IHasColor {
  public bool HasColor(Color _color) => color == _color;
}
brave shadow
#

What exactly does "Layer" do differently from "Sorting Layer"?

rich adder
brave shadow
#

so if Sorting Layer affects wich elements are layered on top, does that mean that Sorting Layer doesn't affect, like, collision detection and non-Sorting Layer DOES affect which objects can collide and interact?

rich adder
brave shadow
#

thanks, that's useful information.

ripe galleon
#

does someon eknow how i could fix this error?

ivory bobcat
#

What's a pause menu?

ripe galleon
#

when you press pause

ivory bobcat
#

What is the object in the scene

ripe galleon
wintry quarry
#

Yeeep lol

#

There's no reason your pause menu should have a PlayerInput component

ripe galleon
#

it“s to switsch the input, so when i press pause the player can“t do any inputs anymore

wintry quarry
#

There should be exactly one PlayerInput component in the scene per human player of the game

ripe galleon
#

it“s UI
i also have a player input

wintry quarry
wintry quarry
#

PlayerInput doesn't belong on it

#

Remove it

ripe galleon
#

sorry for writing like that, i am a beginenr so i donĀ“t know yet how to express myself well šŸ™

#

i will see how i can do that 🫔

wintry quarry
#

It's assuming you're doing local multiplayer

#

Because that's the only situation in which you would have more than one PlayerInput component

nova kite
#

heyy! i'm learning state machines and im confused about something, why do we need this(1st picture) to define the functions that the state uses if we are defining them every time again in each of the actual states(2nd picture), seems redundant to me idk like why not just define them in the states only

teal viper
nova kite
#

but i need to treat all of them different at the base class anyway no? override them

#

so why declare them in the first place outside XD

north kiln
#

I'm not sure why this isn't an interface

#

but it's so you can pass around many objects of type State without having to know what specific sub-type they are

teal viper
nova kite
#

but i am because i override them so technically it is specific to that state no?

nova kite
#

because then again it's the specific Enter for that script

teal viper
nova kite
#

ohhh i see! so only the base Method would be called but youd have to pass the correct state to override it?

#

like Enter(PlayerIdleState)

north kiln
#

the state machine holds onto instances of State, and it doesn't know what type of state that is because that's implementation-specific

#

void PerformLogic(State currentState) { ... use currentState ... }

#

When currentState.Enter() is called then whatever type the instance of currentState actually is will have its override called

nova kite
#

i see so you pass the state for it to execute it

#

ouuuu i see!

#

thank you both! much clearer nowšŸ˜„

frigid sequoia
#

This is a silly thing, but is there like any difference from calling something from inside the class than from outside of it?

#

Like is this a thing I should do if I am to call this over and over?

#

Or doesn't matter at all?

wintry quarry
#

There's no performance difference in terms of "outside vs inside" but if you are repeatedly accessing a property or method or series of variables or a struct, you're potentially wasting cpu cycles calling a function or copying structs.

frigid sequoia
#

So you mean like stuff that would need to be calculated on each call or what?

#

What do you mean with accessing a property repeatedly can waste cpu cycles?

timber tide
#

Depends if the property returns a value or a reference

#

Usually more of a problem if you've some giant structs of data

#

which is why classes are superior ;)

frigid sequoia
#

So, if the property points like to another instance of a class, that is a reference and can be an issue?

north kiln
#
  1. a property is a method, calling methods incurs a cost if they haven't been inlined
  2. if the property has any logic in it, then you're incurring that cost every time it's invoked
#

But more generally code is easier to read when you're not calling Blah.Instance multiple times in one method?

frigid sequoia
north kiln
#

That just sounds like something you should get better naming conventions for if it's a problem for you

frigid sequoia
#

But, what properties would incur a logic to get access to? Like does it have to do with the type of the property?

north kiln
#

Sometimes singletons, especially those in Unity have all sorts of logic in their getters; surely I don't need to go through it

frigid sequoia
north kiln
#

If you feel like that will make a difference in your scenario, then yes

frigid sequoia
#

Mmm, not sure how I can tell when that would make a difference....

humble bay
#

Hi, Im having a problem on the unity mouse lock state which is being ignored and runs further script execution

grand snow
#

then lockState must equal locked?
have you used a debugger to verify?

humble bay
#

It doesnt correctly check the lock state in editor

grand snow
#

in editor you can unlock any time with esc so perhaps it acts weirdly.
Ideally you track this state yourself (e.g. is a menu open?)

naive pawn
latent mortar
#

is this many notes necessary or overkill?

#

(note for every line)

frosty hound
humble bay
#

I mean when the mouse is not locked in the game and I hover it rotates my camera

frosty hound
#

And no, adding a comment to every line is unnecessary.

humble bay
#

Rotation

naive pawn
#

gotta hit save first

latent mortar
#

oops

rough granite
latent mortar
#

that doesnt look right

naive pawn
#

no, not that save

#

the button on the website that says save

#

and then use the url

latent mortar
#

šŸ¤¦ā€ā™‚ļø

#

right

naive pawn
#

yeah ok that's way too many comments

#

you have more comments than code

rough granite
#

yeah at this rate it takes double the time to write the comments than to code

#

writing more comments than the ai does

naive pawn
#

like this, this is just completely unnecessary

//sets the boolean thingy to false when function is called
i can get some of them explaining stuff, but this is pushing it

latent mortar
#

the thing with coding is that i understand alot of the functions and variables and loops etc but idk how to put them all together and make it work

latent mortar
naive pawn
#

(also you're using both .transform and .gameObject on powerUpIndicator.
right now you have it as GameObject, so .gameObject is unnecessary.
)

naive pawn
latent mortar
naive pawn
#

in general, comments are not what is being done, but why it's being done - the code should speak for itself in terms of what it's doing

naive pawn
latent mortar
#

also uhh some of the comments are a lil weird jsut sayin

latent mortar
#

like sometimes idk if i use vector3 or transform.position etc

naive pawn
#

why would you even have this comment

//no explanation needed :////

#

those 2 things are.. not comparable

latent mortar
latent mortar
rough granite
naive pawn
#

this is also just noise

//makes a variable that will be used in the function

naive pawn
rough granite
#

oh :/

#

til that class = variable (im sorry not trying to be rude just found it funny)

naive pawn
#

btw

collision.gameObject.GetComponent<Rigidbody>()
this can just be collision.rigidbody

latent mortar
foggy marten
#

Weird question, but how would you return an index of the object from a multidimensional array?

rough granite
#

could you give an example of what you're asking

sinful pollen
#

yo

#

anyone know how to make a simple 2 d fighting game or smt?

slender nymph
#

nobody here is going to tell you anything different than what you were told in #šŸ’»ā”ƒunity-talk
use the courses on the unity !learn site like you've been instructed

eternal falconBOT
#

:teacher: Unity Learn ↗

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

lofty mirage
naive pawn
#

also they're asking about the index, not the access

lofty mirage
#

Well multidimensional is n >= 2 no?

#

Here I explained for n=2

#

because it's the most common case

naive pawn
#

c# has different concepts for multidimensional arrays and nested arrays

#

multidimensional arrays would be like array[i, j]
nested arrays would be like array[i][j]

but that's still not what they asked about - they're asking about how to represent the indices

lofty mirage
lofty mirage
naive pawn
#

bro they're asking about indices...

rough granite
naive pawn
#

doubt it tbh.. what else would it be other than a tuple or maybe a struct if the indices had meanings

foggy marten
rough granite
#

cause if the size is small like a 2d array and it was a string so srting[,] and each value was different you could just loop through it till you have a match but if you have a huge array of ints you couldn't really cause the chances of 2 indices equaling the same number are there

naive pawn
#

i don't see how that factors in to the question at all

#

the part that would make a difference is this

each value was different
not the types

#

and honestly i don't think that part really makes a difference either

eternal needle
#

it doesnt make a difference what the type is. if they relied on these values being unique, their values would be unique.

naive pawn
rough granite
#

sorry what's tuple mean?

foggy marten
naive pawn
foggy marten
naive pawn
#

please don't be out

rough granite
naive pawn
#

how do you represent the key, in that case

rough granite
#

vector2 and the value be gameobject but yeah fair

naive pawn
#

not Vector2 in this situation where they're all ints

eternal needle
naive pawn
eternal needle
#

I would start with looping through and returning a Vector2Int, i assume you're using this for some grid like structure

wintry quarry
naive pawn
naive pawn
rough granite
naive pawn
#

which is not the same as gameobject

foggy marten
rough granite
#

could you provide a code snippet?

naive pawn
#

that was satisfying as hell

eternal needle
naive pawn
foggy marten
rough granite
#

!code

eternal falconBOT
naive pawn
#

where's that Equals coming from

foggy marten
rough granite
#

though i know i shouldn't

eternal needle
#

Object.Equals...

#

but ive never seen anyone use it like this lol

rough granite
foggy marten
naive pawn
slender nymph
rough granite
#

ahh i see :/

#

my bad

naive pawn
naive pawn
#

it will make our jobs easier

foggy marten
naive pawn
#

why? it's the same thing

foggy marten
#

dunno

naive pawn
#

if it's just stylistic preference just say that

foggy marten
#

prefrence ig? it looks neater

naive pawn
#

aight

#

you're doing float comparison, that might not be consistent

#

but also it seems like you want to do a reverse mapping, via the transform position, which is at a different scale

#

that's where your issue seems to be?

foggy marten
#

Kinda

naive pawn
#

instead of having to manage/translate the transform.position using the width and height into indices, just have MazeBlock remember what index it's from, so you have a proper reverse mapping

#

with that i don't think you'd need FindMazeBlock at all, you could just index into the array

eternal needle
#

one thing i notice is that you're doing is this
var cellX = (int)currentCell.transform.position.x;
which removes the decimal. then sending it to be compared by the original float value
mazeGrid[x, z].transform.position.x

naive pawn
#

by the way, [SerializeField] private int mazeWidth, mazeHeight = 3; only sets the default for mazeHeight.

foggy marten
naive pawn
#

you aren't dumb, you're just inexperienced

#

and that's way easier to fix

eternal needle
#

The value is serialized so if you see 3 in inspector, its still 3. Your default value is just 0 for maze width

#

Default as in when you create a new component

foggy marten
#

Huh

#

Though it actually set both

naive pawn
#

nah, you'd need int a = 3, b = 3; for that

#

it's not actually a logical issue, just pointing out that it doesn't say what you probably think it says

foggy marten
naive pawn
#

no, because Vector2 uses floats

#

it could be a Vector2Int, or a tuple, or a struct, as mentioned before

#

there's not really a best practice, this is kind of a specific situation

foggy marten
naive pawn
#

oh also since this is just storing the index rather than having to return them as a single value, there is a 4th option of storing each dimension separately

#

just preference things though

craggy depot
#

Hey yall, which Ai is best for unity instructions?

#

I’m going insane with ChatGPT trying to make a UI

silver fern
#

Is there a way to have my bullet be able to call a method in the CharacterController script of the target that was hit without specifying the namespace?

polar acorn
eternal falconBOT
#

:teacher: Unity Learn ↗

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

polar acorn
craggy depot
edgy pier
craggy depot
polar acorn
silver fern
# polar acorn I'm not sure what you mean by "without specifying the namespace"

I was planning on having a CharacterController script on each character that handles taking damage from the bullet, but if I have two different scripts with the same name on two different operators, it complains that the global namespace already has a definition for that script. But if I add a namespace for each one, then GetComponent() wants me to specify the namespace

craggy depot
#

Is there really no way?

polar acorn
#

If the scripts do different things, call them different things

silver fern
polar acorn
rare stag
#

yo

silver fern
#

in the bullet

craggy depot
#

Ok let me ask it here if it’s possible or will be difficult, so I want to make a side panel, with three different tabs, once I press on one, I want that panel to show in the same sidebar (basically switching tabs) that and when I click on something (there are tons of pieces) I want a small pop up to show what part that is

silver fern
#

hit being the hit object

polar acorn
polar acorn
silver fern
polar acorn
silver fern
#

and it does have that methond

silver fern
silver fern
polar acorn
craggy depot
silver fern
#

that is the code I just forgot to type the 2D here

polar acorn
polar acorn
polar acorn
polar acorn
silver fern
polar acorn
silver fern
polar acorn
#

You have to tell it which component you want

#

If you have multiple things with the same name you just have to specify which of those two things you want

silver fern
polar acorn
silver fern
#

but they have separate hitpoints

#

so how would that work

polar acorn
#

By making that a variable?

#

They're still separate instances of the component

#

It's just the same script

silver fern
#

but they cant have the same name so how do I find that component then

polar acorn
#

They're the same script

silver fern
#

wait no

polar acorn
#
public CharacterController2D : MonoBehaviour
{
  public int hp;

  ...
}
#

and then put that on two objects

#

it's the same script

#

on two objects

#

The variable belongs to the instance

#

They each have their own hp

#

You can put the same script on multiple objects. You don't need a new copy of the code for everything that uses it

silver fern
#

well theyre not the same script so I'm trying to figure out how to solve that but thanks I think I understand the issue

polar acorn
#

If they don't do the same thing, they shouldn't be named the same

#

If they have some shared functionality they should have a shared parent class containing that shared functionality

rough granite
silver fern
#

I'm trying to add a new script named TargetCharacterController and it's telling me this but class and file names all match, what gives?

polar acorn
rough granite
rough granite
silver fern
#

ah there was one in a different script, thanks

polar acorn
rough granite
polar acorn
#

In older versions it would work until you restarted the editor, at which point it would break

silver fern
#

ok I have a DamageController script with the dealDamage method that is the same across all characters, while the rest is separated out into each characters separately named controller script. But let's say each character has different death animation, so I will still need some kind of way to access character specific scripts from common shared scripts, right?

slender nymph
#

use an event

polar acorn
#

Or:

  • The controllers can check their DamageController to know when they run out of health
  • DamageController could invoke an event that the other scripts subscribe to
  • DamageController could be a parent class of the controller scripts that override the death function
silver fern
#

is listening for an event faster than checking the controller in Update() or does it do that anyway?

polar acorn
silver fern
#

yeah but I mean it still has to keep checking right

polar acorn
#

No

#

It doesn't query the event

#

when the event is invoked, all listeners of it will run

silver fern
#

I see, ok thanks

rough granite
# craggy depot YESS EXACTLY

now i know im not meant to give out the answer but well easy fix instead of using GameObject.SetActive in the button make a script like this and put it on the button and add inplace of the other stuff in OnClick and fill the GameObject with the object you are trying to change the active state of

#

miss spelt object 😭

#

@slender nymph shh, wasnt me

covert hornet
#

Hey, people.
Got some weird bug or something
When I'm logged in unity learn I can't see list of tutorials on the left in this specific tutorial.
Didn't work in incognito. Tried Chrome and Opera. Google didn't give anything useful either.
Maybe somebody encountered this problem?

https://learn.unity.com/course/programming-interactions-with-c-scripting-in-unity

Unity Learn

Take your Unity development skills to the next level by learning how to create program interactions using C# scripting. This hands-on course delves into interactive gameplay mechanics, from setting up player controls and projectiles to integrating animations, ragdoll physics, and sound effects. Using Unity’s Input System, Cinemachine, and Meca...

slender nymph
#

this is a code channel

rough granite
naive pawn
#

this is a code channel

rich ice
naive pawn
#

everything in unity is code under the hood. this reasoning doesn't hold

kindred iron
#

yeah right i didnt think that much

#

mb

paper needle
#

guys how should i start learning unity c# should i read the unity official documentation for each command or just watch an insane amount of tutorials

eternal falconBOT
#

:teacher: Unity Learn ↗

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

paper needle
#

thanks ā¤ļø

naive pawn
#

there are also resources pinned here

rich adder
#

this is a code channel..
also depends how many things are on screen..genrally there is nothing worry about it to much

craggy depot
#

but when i run the game it doesnt show, can you tell me where am i going wrong

polar acorn
craggy depot
#

ohh...😭 man unity is hella difficult (i feel so dumb)

rich adder
#

even veterans still ain't fully using an entirely new system like UITK

craggy depot
#

OMG IT FINALLY WORKED, IVE BEEN AT IT THIS FOR HOURS IT FINALLY WORKS UnityChanCelebrate UnityChanCelebrate

rich adder
#

is there a reason to use UIToolkit instead in the first place?

craggy depot
#

and honestly it DID not look good either

rough granite
craggy depot
#

i got the idea of the state list because of what you said

supple idol
#

Guys I'm wondering what will be the difference between
rb.AddRelativeTorque(Vector3.forward * rotateStrength * Time.fixedDeltaTime);
and
transform.rotate(Vector3.forward * rotateStrength * Time.fixedDeltaTime);
Like I get the thing with local and global axes but codewise is there any additional difference

naive pawn
#

one goes through the rb and the other goes through the transform

rich adder
naive pawn
#

if you use an rb, you shouldn't modify the transform, because the rb is expecting to control the transform itself

#

it may not sync properly

slender nymph
#

also adding torque is not the same thing as just rotating by a specific number of degrees

rough granite
rich adder
#

^ adding Torque is like addForce but for rotation, if you want specific rotation use MoveRotation

candid pilot
#

hi

rich adder
supple idol
#

Like I'm following a tutorial and I've had previously for forward movement (a rocket and flappy bird mix) where for the thrust they've used AddrelativeForce and for the rotation they've used transform.rotate and I'm wondering why and is this the same etc.

rich adder
rough granite
rich adder
#

Transform is forcing it to be a specific rotation regardless of physics

naive pawn
#

well it's thinking there aren't physics

rough granite
naive pawn
#

the "correct" approach would be to tell the rb to rotate as well

lusty bramble
#

I need help with programming animations, and getting the model out of Tpose

I have the animation files in fbx. and I added transitions. followed tutorials to try attempt to make it work but I got no luck.

using System.Collections;
using System.Collections.Generic;

public class Walking : MonoBehaviour
{
    private Animator mAnimator;
    private bool isCurrentlyWalking = false;

    void Start()
    {
        mAnimator = GetComponent<Animator>();
    }

    void Update()
    {
        {
            if (mAnimator != null)
            {
                bool moving = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D);

                if (moving)
                {
                    mAnimator.SetInteger("sn_walk_loop", 1);  // Set to walk
                }
                else
                {
                    mAnimator.SetInteger("sn_walk_loop", 0);  // Set to idle
                }
            }
        }
    }
}```
rich adder
#

if you want a similar effect to Transform.Rotate us Rb.MoveRotation at least it respects physics and interpolation but should at least not deal with outside forces like friction

supple idol
#

okay I think I get it cheers šŸ’Ŗ

naive pawn
lusty bramble
#

still a noob

naive pawn
#

which part

lusty bramble
#

the whole thing-

naive pawn
#

you don't know what "make sure the component exists" means?

lusty bramble
#

If it helps to understand better, the animations are separate the are not apart of the character,

rough granite
lusty bramble
naive pawn
rough granite
naive pawn
lusty bramble
#

I heard a lot of people say "exist" isn't needed

lusty bramble
#

I got all of the animations here, I'm not sure if that means anything in this context

naive pawn
lusty bramble
#

typo

naive pawn
#

if you didn't know what those were you should probably go do the unity essentials course on !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

lusty bramble
#

All these files were originally havok fiels. .anim.hkx.anim

#

idrk how to explain

nova kite
#

i have a basic understanding of state machines now but im having trouble deciding what should be a state and what should be combined into one state, player movement for example. he can be idle walk run jump crouch fall attack. so should each of these have a state? should each call all other states?

#

this seems more messy and complicated than just putting everything in one script

lusty bramble
#

nvm

#

Idk how to explain so it doesn't matter

naive pawn
nova kite
#

but like should really each of these have their own state?

craggy depot
#

hey so ive setup my camera to orbit around my object, and i have put mesh colliders onto the body of my object and even added code, yet its not working, i dont even think the click is being registered. what do i do?

naive pawn
naive pawn
nova kite
naive pawn
#

"running" and "jump" can coexist, thus they aren't separate states, that kind of thing
of course i don't know if they actually can in your game, just using that as an example

nova kite
#

i see so the states is not the actual movement but the logic behind it

#

but what if it's jumping and falling for example, because you always fall when you jump but you dont have to jump to fall

#

so is that coexistence or

eternal needle
nova kite
#

well falling should calculate if the player recives fall damage

#

but you dont have to jump for it

#

you can walk off an edge

naive pawn
#

those just.. exist separately

nova kite
#

so these are two different states

naive pawn
#

no, not necessarily

eternal needle
naive pawn
#

it just means your jumping and falling are not coupled

nova kite
naive pawn
#

they may be part of the same state, or they may be part of different states, maybe jump is bunched in with the rest of movement and fall is a separate state

eternal needle
#

if your calculation is flawed, sure

nova kite
#

how should you decide then😭

naive pawn
#

my point is - just because they have separate logic doesn't mean they're separate states

naive pawn
nova kite
#

yes

naive pawn
#

then it's not a separate state

nova kite
#

then the script gets clutered and messy anyway i thought the whole point of a state machine is so it looks pretty and easy to manage

eternal needle
#

tbh i dont find theres good reasoning to separate your entire movement into states unless you need different actions to happen. Like swimming compared to walking is valid for a state
Walking, running, moving while in air are all the same thing

naive pawn
#

code management isn't magically solved by putting a state machine in there

#

you still have to put in work to make the logic of each state work and make it maintainable

nova kite
eternal needle
#

whats wrong with 200 lines of code, you say "but" as if thats a bad thing

naive pawn
#

for example my player has, not really states, but more of actions

enum PlayerState {
    None,
    Dash,
    Attack,
    Turn,
    Stun,
    Defeat,
}
nova kite
#

if there is a bug you gotta go through 200 lines then xd

#

but if it was a jump state and there is a bug with jumping maybe youd have to go only through the jump state script

rich adder
#

200 lines aint shit

eternal needle
naive pawn
nova kite
#

OHH!!

#

so another state should exist if you can't do it while performing any of the other states

valid violet
#

If your code base is good your won't reduce the count of lines

naive pawn
#

yes, that's what i'm trying to get at with the "overlap" thing, i mightve not explained it well

nova kite
#

you did i get it now it just didnt click haha

#

i see so as long as it can be performed simultaneouslyit should be in the same state

#

i have a rule to go by now😌

vocal olive
nova kite
naive pawn
#

only with one of the characters

nova kite
#

oh i see so it's intended

eternal needle
# nova kite i see so as long as it can be performed simultaneouslyit should be in the same s...

for basic movement, you really can get away with this all being defined in one "state". If you want to code a limitation where you cant attack while in the air, you simply check if the player is grounded, or check if its a certain enum value. You don't need to go full enterprise mode and separate this into individual classes where one state doesn't handle attacking
going back to the swimming vs running example, it would make more sense for a swimming state to exist because the logic would be entirely different

nova kite
#

but if you can attack while moving then that should be in the same script too?

naive pawn
#
case PlayerState.Attack:
    if (character == Character.Gawr) {
        goto case PlayerState.None;
    } else {
        rigidbody.velocity = Vector2.zero;
    }
    break;
naive pawn
#

my PlayerController is 400 lines long

#

this isn't really a state machine, i'm just using states to handle how stuff works

nova kite
#

i guess i understood it all wrong then

#

i thought state machines should perform an action and then call a different action so you dont have to check if the player is doing everything he can do every frame

naive pawn
#

state machine is kind of a broad thing

#

hell you could probably shoehorn what i have into the definition of statemachine

ruby python
#

Really stupid knucklehead question, but could someone tell me if I'm using this correctly please? It makes sense to me but my rockets ain't moving. lol.

Rigidbody is setup correctly etc. Just can't figure out what's going on. šŸ˜•

rocketRigidBody.MovePosition(transform.position + transform.forward * rocketSpeed * Time.deltaTime);
naive pawn
eternal needle
dry pewter
#

When using Application.targetFrameRate if I set the target frame rate once in a game's first scene do I not have to consistently set it to that value in scenes after that or do I?

naive pawn
naive pawn
dry pewter
#

Okay just wanted to make sure šŸ‘

naive pawn
#

as indicated by it being a static prop on Application

rich adder
nova kite
ruby python
naive pawn
naive pawn
#

there's a speed that's presumably per-second, this is presumably being executed per frame/tick

ruby python
#

FixedUpdate.

rich adder
#

thought like AddForce / Torque it was already tick moved

naive pawn
#

nah, this takes a target position

rich adder
#

oh wait thats MovePosition

eternal needle
# nova kite well for example Input Horizontal or Input spacebar for moving and jumping, itd ...

you would be moving every frame in most cases, so its fine. even in air, most games allow you to move slightly. because of this you might end up having very few states that actually limit movement, like attacking could be one. This could really just be a bool like "canMove" which you check first before applying movement
it's simple enough still you dont need to separate into states

rich adder
#

I thought it was MoveRotation

naive pawn
#

wouldn't that be the same thing?

nova kite
rich adder
#

hmm yeah I think, I suppose with Torque/Force you don't . nvm then lol

nova kite
#

beause you are gonna check for it anyway with an if statement

ruby python
#

I've always used Translate before, but I know that it causes issues with collision physics.

rich adder
#

but just fyi MovePosition also ignores colliders

ruby python
timber tide
#

yeah movePosition* collision ignores walls

ruby python
#

Sorry, replied to the wrong message. lol.

timber tide
#

docs makes it sound like just a smooth alternative but tosses out the whole collision detection

ruby python
#

So, what should I be using instead to respect collisions? šŸ˜•

rich adder
#

so yea yeah typically you need to pair with Rb.SweepTest for example to consider walls

rich adder
timber tide
#

if you want to use non-kinematic (ye) then add force 99% of the time

#

Velocity I usually use for stuff like quick dash that removes forces

rich adder
#

opposite, kinematic is meant to be moved with MovePosition not addForce (kinematic dont have velocity in 3D phyx at least)

eternal needle
# nova kite then why use a state machine at all and not check if the player is swimming for ...

because your swimming logic would entirely be different. gravity wouldnt apply, you might be able to move up and down, you play different animations/sounds. Maybe you cant attack at all, maybe you can attack while treading the water.
Your state here would be swimming vs regular movement. Basically swapping between two classes that processes your inputs
adding these in if statements to your regular logic would make it miles more complex. its no longer just one check of a bool

ruby python
#

Yeah I was just gonna say I thought kinematic removes all movement physics.

#

Right okay, will give addforce a go. I think I read somewhere that you shouldn't set the velocity directly.

rich adder
timber tide
#

Velocity overrides all variables you'd get from forces otherwise if you constantly set it so it's not something you should primarily use

nova kite
#

but i guess walking to running the only changes are speed and animation

#

so a whole new script is redundant

rich adder
#

ya setting velocity directly gives a more "snappy" feel because you're essentially overriding all other forces like Friction / Damping etc.

#

although unity docs always discourages from doing so

ruby python
#

hmm, okay, well velocity might be the way to go then (this is for an ffar rocket, so needs to be kinda immediate)

rich adder
#

Force.Impulse exists for a similiar effect

#

but yeah usually just setting vel should be plenty

ruby python
#

Just as a clarification thing, forcemode.Impulse would be the one to use if I don't want continuously adding force right?

rich adder
warm palm
#

Is this a help channel?

rich adder
#

but yeah typically its used as 1 time thing like explosions and all that

ruby python
#

Right I get you. Thanks.

timber tide
#

Usually you're constantly adding forces, but impulse is a one time jump kind of situation

rich adder
ruby python
#

Hmm......okay, now I'm really baffled, tried setting the velocity directly, but the rockets still don't move. lol.

eternal needle
# nova kite ohhh! so you have to evaluate the amount of checks you have to perform and the a...

it really is a case by case thing where yea you should evaluate how complex the logic is. the number of values isn't as much the concern but I guess it does correlate with how complex your logic might be.
Think of a door, it can be opened or closed. When it is opened, you can only close it. When it is closed, you can only open it. Ask yourself if it would be simpler to use a statemachine (+2 states, open and close) or one class with a bool isOpen? In this case its quite obvious because at the end, all you're doing is calling a function based on isOpen.

ruby python
#
rocketRigidBody.linearVelocity = new Vector3(0, 0, rocketSpeed);
warm palm
#

Perfect, I just installed Unity and used it for the first time and saw the roll a ball tutorial straight away when I opened the Unity hub, I got stuck in straight away and followed along with the web tutorial with videos but I'm getting some kind of error with the first script I've ever made "playercontroller.cs". The video says now press play and move the ball "It works!" Mine won't let me press the play button and says "Top-level statements must precede namespace and type declarations" and I have no idea what to do lol

#

Also I have never made a game or used any game engine in my life, or written any code for anything I'm simply a beginner level animator on Blender

nova kite
#

i understand it much better now thank you both!

short hazel
#

Post your code

warm palm
#

ok

polar acorn
warm palm
timber tide
short hazel
polar acorn
#

Can't do that

warm palm
#

I'm so embarrassed but what does that mean?

#

I'm a complete noob sorry

short hazel
#

Basically the } on line 22 ends the class PlayerContoller { of line 3

polar acorn
#

Your code is outside of those

warm palm
#

So just put {} around the text

polar acorn
#

The { is on line 4.
The } is on line 22.
Your fixed update function starts on line 24

polar acorn
short hazel
#

Move the whole FixedUpdate function so it's inside the class's { } instead

#

Also you'll have to set up Visual Studio because there are a few more errors in this code, and they're not highlighted right now

#

!ide

eternal falconBOT
warm palm
#

okay erm how do I move it

#

click and drag?

short hazel
#

Copy/paste it

naive pawn
#

select and drag should work

warm palm
#

okay

short hazel
#

Or select the whole function, then hold Alt and tap Up Arrow to move it up

ruby python
#

If you're following a tutorial, go back and look at his code very very carefully. You'll be able to see where you're going wrong.

warm palm
#

Is that right

polar acorn
#

If you configured your !ide you'd get errors underlined in red so you'd be able to see right away

eternal falconBOT
warm palm
#

How do I try it

#

What's !ide

eternal falconBOT
polar acorn
warm palm
#

The Unity Dyno thing

#

What's my IDE

polar acorn
#

the thing you write code in

warm palm
#

still not working

warm palm
short hazel
#

Make sure you have saved, the orange indicator to the left of the code shows that your changes are not

polar acorn
#

and do that

warm palm
#

what link?

short hazel
#

But yeah do the configuration, it'll show errors in the code directly, give suggestions as you type code, and auto-format your code

#

Read all the options and select the most appropriate one

polar acorn
#

one time, even by yourself

warm palm
#

Well there's no need for the attitude

#

I'm new and I'm struggling here

#

If you get annoyed by helping people why are you responding

polar acorn
#

Most people are capable of reading instructions

warm palm
#

most people I've interacted with on help channels aren't cunts to people who are struggling to understand

rough granite
# warm palm

I happen to think the problem is on line 24 of whatever script this is referring to

short hazel
#

Format is (line, column), so line 24, 2nd character

rough granite
#

And what is what i thought it was before but the fact he has a using whatever; on the 24th line seemed silly to me so i thought it could've been saying you we found an error here and here

polar acorn
#

There's no point trying to guess where the problem is when a configured IDE will literally highlight it

short hazel
#

Exactly

rough granite
#

I think you scared him away :/

short hazel
rough granite
polar acorn
#

Multiple times

#

That's the point

rough granite
#

I saw you talking about the lack of a configured ide which would give him the answer in half a second, which with the simple mistake he has i can agree with doing over just saying oh you are missing a space at that point

short hazel
#

Looking at it quickly there's at least 5 more errors in that file!

warm palm
#

I can't find "Windows > Package Manager" menu in the Unity Editor

#

If it's not too annoying for you, could you help me locate it

short hazel
#

In the menu bar, at the top of the window

#

File, Edit, Assets, ...., Window, Help

sinful pollen
#

is this where i ask my questions

warm palm
#

Found it, was confused because it says "Windows" on the website but just "Window" in the editor

warm palm
sinful pollen
#

need helping dealing damage to charectors when performing an input?can anyone tell me how to?

warm palm
#

RIght so, I already have everything installed that you told me to install

rough granite
warm palm
#

The IDE is already configured

rough granite
polar acorn
rough granite
sinful pollen
warm palm
sinful pollen
warm palm
#

If you'd have just looked at my screenshot in the first place you would have known that

polar acorn
rough granite
warm palm
#

@polar acorn Wrong screenshot

warm palm
short hazel
polar acorn
sinful pollen
#

coz i think ur pretty smart and u can help me i think

fickle plume
#

@warm palm Keep off-topic remarks off the channel. Please. If you were asked to clirify the question provide the information. No one needs to hear your bickering.

polar acorn
#

I've looked at all of them

rough granite
sinful pollen
polar acorn
warm palm
#

I think you need to stop writing in italics bruh, it's cringe af

#

You are not the main character

fickle plume
polar acorn
warm palm
#

This guy

naive pawn
fickle plume
#

!mute 314014424438538240 15m Don't spam the channel with off-topic. Don't make me repeat myself.

eternal falconBOT
#

dynoSuccess mrmaxta was muted.

raw talon
#

Hi ! I try to make my first game, But I'm currently stuck. I'm practicing on a 2D top-down shooter, but the problem is that I can't get the character to move with the new Unity 6 inputs. When I follow a tutorial, it never works

#

How can i do with the new system ?

fickle plume
nova kite
#

when calling a parent do you have to write : base ?

is there a way where you could just write the parent's class's name or is that a c# thing

#

like:

class Parent
{
    public Parent(string something)
}

class Child : Parent
{
    public Child(string something) : base(something)
    {
    
    }
}

but instead do this:

 public Child(string something) : Parent(something)
raw talon
fickle plume
eternal needle
rich adder
#

You could use composition or factory pattern depending what you need to do

nova kite
#

i see, no it was only for coninience to instantly know who the parent is by name when reading through the code

#

but i will get used to : base haha

#

thank you!

rich adder
#

cause what you showed was constructor

#

or you mean the base class itself

nova kite
#

i meant like being able to write

: ParentName instead of : base

#

but it's just a small thing i gotta get used to

half wave
#

Heyo! tiny question, what would be the best way to unzip a .zip file in unity?

nova kite
#

because this is how you do it in C++

#

but in c# i guess it'd be Dog : base

polar acorn
#

...no?

#

You need to tell it which class it's a child of

#

It's basically the same syntax, just without an access modifier in the parent declaration

nova kite
#
public class PlayerMoveState : State
{
    public PlayerMoveState(StateMachine stateMachine) : base(stateMachine) { }
#

well yea at the beginning

#

but then you write the : base

#

instead of : State again

polar acorn
rich adder
#

for the constructor

nova kite
#

i dont think it's like that for C++ is it?

#

now im confused lol

polar acorn
#

What you showed in C++ doesn't have a constructor so I'm not sure how it handles it

rich adder
#

C# isn't C++

nova kite
#

thats what im saying

rich adder
#

yeah so don't apply C++ syntax especially to c#

#

they are different

nova kite
#

thats why i asked if it's possible lol

#

and then said it's something ill get used to

rich adder
#

except for access modifier in declared class inherited, it looks exactly the same

#

you mentioning a constructor which is something else

polar acorn
#

Well, looks like the reason the syntax is different from C++'s is because apparently you literally cannot call a parent constructor from the derived class

#

At least according to some random forum post I found

nova kite
#

ohhh that'd explain it too

#

because the whole thing got me confused haha i guess i havnt done it before at all

#

when we studied inheritence

rich adder
#

a bit of time you'll get used to its quirks lol

timber tide
#

Only large difference between c++ constructor and c# constructor is you have to also specify the parent class parameters

grand snow
#

seems in cpp the base constructor is invoked without needing to explicitly do it like in c#

nova kite
#

OHH RIGHT!!

grand snow
nova kite
#

right!😭 omg i can sleep at night now hahaha

#

it instantly calls it with the correct values passed

#

and you can have multiple constructors and it will call the one that matches the amount of values passed or a default one

grand snow
#

ah I see. I don't do cpp enough to remember how it works tbh

nova kite
#

i only learned it cuz it's what they teach in the college computer science program haha

#

i hate it

grand snow
#

try rust and you may love or hate it

#

Its cool but sometimes soo obtuse it makes you feel like a baby learning to talk

nova kite
#

i saw the sytax at one point and i did not like that haha

grand snow
#

functional langauges can be funny but I do like the security it offers and the fact it has a real package manager and build system

#

before i found vcpkg i hated adding a lib to a cpp project

nova kite
#

is NavMeshAgent hard to learn? my brain is fried from all the state machine stuff i learned and the next step is making the enemy and it says enemies in games mostly use that thing

ivory bobcat
#

This is the beginner coding channel

lusty bramble
#

oh-

#

well

#

I'm also a beginner following off of the main Unity tut

rich adder
ivory bobcat
lusty bramble
#

okay

timber tide
#

Unfortunately Unity's avoidance is pretty bad

#

Otherwise dumb swarm logic it works fine

rich adder
#

some tricks you can use to mitigate some of the problems

timber tide
rich adder
#

never seen 2D isn't that third party?

timber tide
#

2.5D

#

I cheat

rich adder
#

that twitchy movement is strange never seen that b4 lol

#

for a group of enemies I usually don't assign the same target, i try to give unique ones that are aprox near it

timber tide
#

their agent zone is rather large, but shows what happens when there's no gaps to really pass through they just spaz out

#

it works fine for a small number of units but it'll eventually start vibrating with enough agents crammed together

rich adder
#

yeah sometimes if they are on the same narrow path they do weird behavior but you also need to play around with the avoidancePriority number

timber tide
#

it's also quite expensive, rather exponential the more units that are close. A* project has a few better ways it handles it which is why I consider a must buy ;)

teal viper
quiet hazel
#

Hey guys, quick question here, how do you do a save and load, continue progress thing? I don't know nothing about anything, any Youtube videos I watch don't really help me.

timber tide
#

JSON serialization and deserialization

quiet hazel
rich adder