#💻┃code-beginner

1 messages · Page 831 of 1

sour fulcrum
#

it can be fine if you know what your doing and what is happening

limpid wren
#

What are you trying to do with them? They're not intended to be changed at runtime but that doesn't mean you can't if you have a good enough reason

grand snow
#

No because in editor the assets will keep changes made in play mode

#

also may fool you into thinking "wow easy data saving"

limpid wren
#

I guess the answer to your question is "no" it's not good practice, so unless you have a good reason to break good practice then you should avoid it

limpid wren
sour fulcrum
#

I don't think it's bad practice, it's just practice. If your uninformed on what it's doing then you could be doing bad practice with it though

grand snow
sour fulcrum
sage mirage
#

I know what SO's do

sick laurel
#

Hi umm I need help with a code for my uni assignment ^^"

fickle plume
radiant voidBOT
# fickle plume !ask the full question if you need help.

:thinking: Asking Questions

:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.

-# For more posting guidelines, go to #🌱┃start-here

sage mirage
sick laurel
#

aaa oki so
im tryna make an enemy like up the speed when the player is in the "range" the tutorial ive found only shows me ones for shooting games, and the enemies in that are stopping in place and then "shooting". i dont want my enemy to "shoot" i want him to speed up and then for the players position to be reset to the world spawn point when the enemy comes in contact with the player
im using unity 6.3 LTS
the 3d one

#

this is my code

fickle plume
#

!code

radiant voidBOT
sick laurel
#

ahh sorry

sage mirage
#

Hello, world!

#

Just use this 🙂

sage mirage
#

if you know how to use it

sick laurel
#

does that work

sage mirage
#

I see you have a method called AttackPlayer() which is empty

naive pawn
#
    //States
    public float sightRange, attackRange;

these wouldn't be states, btw

#

(the 2 bools are though, as well as walkPoint, walkPointSet, and alreadyAttacked)

sick laurel
#

ummm oki so, i basically have a chicken (the "enemy/agent") and i have the player controlling a fox, when the fox gets too close to a chicken, i want the chicken to first "chase" the player and once its close enough, i want the chicken to like dash toward the fox

naive pawn
#

how does the code you have differ from the goal

sick laurel
#

coz im unsure how to like write it out

#

in the attackplayer() section

naive pawn
#

you'll have to design a system to allow that kind of attacking then

sick laurel
#

Would u be able to explain how i could

naive pawn
#

wait, this seems to conflict with what you said earlier

#

is it 3 separate states here?

#

player in sight range -> walk towards player
player in attack range -> dash towards player
player contact -> destroy player

is this what you're trying to say?

sick laurel
#

Theres the patroling state, the chasing state, and the attacking state

#

patroling is when the chickens just roaming

naive pawn
#

what is the attacking state exactly

sick laurel
#

or do they needa be separate

naive pawn
#

they wouldn't be separate states, i guess, since destroying the player is just a singular action

#

so right now are you asking about the dash, or destroying the player?

sick laurel
#

both ^^"

naive pawn
#

alright, one at a time

sick laurel
#

sorry im still learning

sage mirage
#

Do you know about Design Patterns and specifically State Pattern? Instead of using booleans first of all I would recommend implementing State Pattern like for such cases.

sage mirage
#

I see you dont have any state pattern

sick laurel
#

what makes it a state pattern

sage mirage
naive pawn
sly shard
#

Hello fellow humans

naive pawn
#

cool, just set the navmeshagent's speed higher when the player is in that smaller range then

sick laurel
#

oooh oki

#

wat about the destroy thing

naive pawn
#

you'd need some way to detect that they're "touching", im not sure if the navmeshagent has something for that built-in

sick laurel
#

Mmm no idea

naive pawn
#

also not sure if rbs would interfere with the agent, i'm really not familiar with navmesh

#

you could just check distance though tbh

sick laurel
#

how would u usually check for collision

naive pawn
#

the physics system

#

but i don't know if that would interfere with the navmeshagent

sick laurel
#

would i not be able to

#

ahh oki

#

the tutorial i was following was using physics for the shooting thing they were doing

#

So maybe id be able to? i can give it a try i guess

#

the vid is from 5 years ago, i dont know if the function wouldve changed alot since then

sage mirage
#

Can you send a video by the way of your game to see what's going on?

sick laurel
#

i dont have alot right now

sage mirage
#

Are you a beginner?

#

I assume right?

sick laurel
#

Yes i am

fickle plume
#

@sage mirage Don't start with the off-topic here

sick laurel
sage mirage
# sick laurel

So where is the kitchen and where is the fox you were saying?

sick laurel
sage mirage
sick laurel
#

i needa figure out how to do the scoring as well

naive pawn
#

this is all kinda unnecessary...

sick laurel
#

Wdym

naive pawn
#

this thread of conversation is irrelevant

sick laurel
#

Ohh right

fickle plume
#

Pretty sure agents have a callback when they reach destination. Otherwise you need to handle collision events yourself

sick laurel
#

Ah

naive pawn
#

hm that'd only work if the agent was right on top of the target though, wouldn't it? or can you configure the threshold

sick laurel
#

That is useful then, ill just needa figure out the collision

#

on top as in literally on top?

sage mirage
#

if you want to handle collisions there are ways if you want to know...

fickle plume
#

!learn You should check tutorials about trigger colliders and events on

radiant voidBOT
naive pawn
#

unless there's a configurable threshold

naive pawn
fickle plume
#

I don't remember how agent handles physics, pretty sure I used with it for one of the game jams.

sick laurel
#

Would it have changed from 5 years ago

naive pawn
#

probably not

#

(though like i mentioned earlier you could probably just use a distance check for a quick & dirty solution)

sick laurel
#

xD okay

fickle plume
#

That is the wrong chat :)

naive pawn
fickle plume
#

It was an agricultural discussion for all concerned.

sage mirage
#

@sick laurel AI & Pathfinding and these concepts are advanced enough and you have to get a deeper understanding of Design Patterns like State Pattern along with Finite State Machine, as well as Pathfinding algorithms and more. I dont think you have to mess right now with these stuff like A*, Dijktra and more. Yes just do what chris said.

naive pawn
#

they're using a navmesh

#

they aren't doing manual pathfinding

sick laurel
#

yea i dont think i can do manual pathfinding

sage mirage
#

In Unity there is a built in way to do all these stuff?

naive pawn
#

what do you think a navmesh is

sage mirage
#

and it actually does everything?

#

Like what about pathfinding or whatever you want to do with AI?

#

NPC's lets say

naive pawn
#

just go google it man

sick laurel
#

does this look right

teal viper
sick laurel
#

to be sure? i dont wanna break anything

teal viper
sick laurel
#

just wanna know if i did the increase speed thing correctly

teal viper
#

Does it not work?

sick laurel
#

it gives me an error message when i try to attach the script to the object

teal viper
#

Okay. Then perhaps that was what you should have started with. As well as share the error message.

#

Asking if "it looks right" is a very lazy way to annoy people. Be more concise in your questions.

sick laurel
#

Ah sorry

#

it says "Can't add script component 'chickenScript' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match."

#

the script is called chickenScript

teal viper
#

What unity version are you using?
Older versions required you to name the class and the file name the same way.

#

And your class is called "ChickenScript".

sick laurel
#

its unity 6.3

teal viper
#

Hmm... Okay. Are there any other errors?

sick laurel
teal viper
#

Take a screenshot of your console.

sick laurel
#

oki one sec

teal viper
#

Okay. Take a screenshot of the warning that you mentioned.

sick laurel
#

huh it let me do it this time

#

^^"

#

sorryy thank u

#

giving me this now tho

polar acorn
sage mirage
elfin pike
#

I should make settings menu IDisposable?

delicate zinc
#

https://pastebin.com/GfJu0BRz
im so confused to why the vector2.reflect line when the border is hit wont work, every other velocity related line works, but its specifically if i try to apply velocity after hitting the wall it doesnt wanna work
the first image is the walls and the second one is the fighters

delicate zinc
slender nymph
#

by the time OnCollisionEnter2D runs your velocity may have already changed from the collision, store the velocity in FixedUpdate or Update and use that stored velocity instead

delicate zinc
slender nymph
#

AddForce isn't going to change anything if the issue is related to the Vector2.Reflect, you'd still get the same incorrect result from Reflect

delicate zinc
#

ouh oka ill just try the thing you said then

#

ok so i tried that and it didnt change anything, but i think i found the issue
whenever they hit the wall the velocity in the info section just does this??? instead of reflecting, i think its trying to go positive but it just wont for some reason

slender nymph
#

show what you tried

delicate zinc
slender nymph
#

so not in the Reflect call then?

delicate zinc
#

wait wrong part of the code whoops

slender nymph
#

that's still wrong

delicate zinc
#

WAAIT if orgot to change the rb.velocity in the second bit

slender nymph
#

you still need to be assigning to rb.velocity, the only place you would replace rb.velocity with Velocity is inside that Reflect call

delicate zinc
#

ohhh ok

#

oh my god that worked tysm

cunning bramble
dark hatch
#

i was using this to have enemies follow the player. "target" = player.transform.position. but the enemies movement is very jittery. it seems that when i remove the 2nd line (so they dont rotate at all and keep moving in 1 continous dir), there is no jitter. any way to fix this jitter? i have already tried stopping any rotating if the angle is <2 deg, and setting rigidbody interpolation

naive pawn
#

are you getting the rb every frame lol

dark hatch
#

yes

#

does it create problems

naive pawn
#

you should not, you should cache that retreival

dark hatch
#

let me try that real quick if that changes anything

naive pawn
#

it won't

dark hatch
naive pawn
#

it's just good practice

dark hatch
#

should i move it to fixedupdate

naive pawn
# dark hatch yeah

i'd guess the this is running before the player so it's getting values from the previous frame, try putting this in LateUpdate instead

dark hatch
#

ok

naive pawn
#

ah wait it's with an rb too isn't it

#

you should probably be rotating with the rb, not via the transform
also check the interpolation settings

dark hatch
#

and how can i rotate with rb ?

#

theres this moverotation function does that work?

naive pawn
#

you could use MoveRotation with the angle calculated from target - transform.position

#

you could use eg Mathf.Atan2 to get the angle from that direction

#

wait actually there's probably a better way, one sec

naive pawn
dark hatch
#

and use that on moverotation

naive pawn
#

you don't need quaternions

dark hatch
#

it seems the moverotation function takes a quaternion as input

naive pawn
#

you don't need the current rotation either

#

are you looking at the wrong docs

dark hatch
#

hold on

naive pawn
#

it takes either a float or a quaternion, and a float would be simpler to work with here

dark hatch
#

oh yeah i was

#

i was seeing the rigidbody3d moverotation

#

that one uses a quaternion

#

yeah okay that does seem to fix it, thanks

#

i really need to look into these methods that rigidbody has

elfin pike
#

I have this game object. [Pause] has script, it received with inspector [Pause_Canvas] reference. After scene reload, console throw error, that reference doesn't exist, but looking in inspector reference is set.

polar acorn
#

If you see one that has the reference set, but you have an error saying that one of them doesn't have their reference set, then the one you are looking at is not the one that threw the error

elfin pike
#

There shouldnt be anything preventing gameobject instance deletion.

Script on [Pause] gets deleted. Canvas doesnt have any of my scripts

slender nymph
#

show the full error and the relevant code, otherwise we're just going to be guessing at what the issue is

#

but if i had to guess, i'd say it's probably a DDOL object that had a reference and when the scene was reloaded the object it was referencing was destroyed and a new, unrelated, one was created

slender nymph
#

!code

radiant voidBOT
slender nymph
#

also you're subscribing and unsubscribing two separate delegates to the performed event, if you want to use an anonymous function for that then you need to store it in a variable and use the variable to subscribe and unsubscribe, otherwise just use a regular method

naive pawn
elfin pike
naive pawn
#

....ok

potent portal
#

can someone help me. im making a multiplayer game with a friend and now im getting "You are not signed in to the Authentication Service. Please sign in."

#

im super confused because it was working earlier

#

nevermind

#

i fixed it by restarting the project

balmy vortex
#

hey so like just to sanity check myself rq is this actually a good way of telling if the player's standing on something?

#

or is it secretly like horrible

slender nymph
#

physics queries are a good way to handle that, though i'd personally use something with some volume to it, like a CheckBox or BoxCast so that you aren't considered ungrounded when 51% of the player is hanging over an edge or if there's a tiny gap in the ground right where the center of the player is

sage mirage
#

Hey, guys! By the way, I had a question earlier today about scriptable objects and that I don't have to change them at runtime. So, I figured out something, basically what I have to change is the copy of the scriptable object not the scriptsble object itself. What I mean is I have to do something like let's say

int currentLives = playerData.MaxLives that is possible and the best practice when you want to change a value of a scriptsble at runtime that was my question basically. What do you think?

eternal needle
naive pawn
#

or have you actually just.. not configured your ide in all this time

sour fulcrum
eternal needle
limpid wren
#

Let's say I have a singleton object that spawns damage numbers on hit
Currently the implementation is that the damaged object references the singleton and asks for a damage number to spawn upon dealing damage.

I don't like that implementation and would like it to go the other direction. I want the damage number manager to be able to tell that damage has been dealt and then decide if it wants to spawn damage numbers.

But I'm not sure about the implementation. Do I just use events for this?

#

For me, I don't want every object to have to know about the damage number manager

verbal dome
limpid wren
#

But then the question is, how do I get the damagenumbermanager to subscribe to all the required events without creating an equivalent god object

#

The reason I don't like my implementation is I just created a new scene to test something and got a null reference because I forgot to add the damagenumbermanager.

If I add a damagenumbermanager but get an error because I forgot to add an enemymanager or whatever then that feels like the same thing

slender nymph
#

I would go with a specific component for handling receiving damage that invokes a static event upon receiving any damage, it can also pass itself or its transform or whatever so that whatever subscribes to the event has the info it needs

verbal dome
#

What events do you need apart from something like Action<HitInfo> HitHappened?

sour fulcrum
#

scriptableobject singleton time

limpid wren
slender nymph
#

yes

limpid wren
#

That unlocks a lot in my brain at once

slender nymph
#

and if you have a single component that handles the damage that each damageable object has, then you only ever need the one static event so your worry about needing to reference a bunch of different things is unnecessary

verbal dome
#

(Latter better ofc)

limpid wren
slender nymph
limpid wren
slender nymph
#

yup, that way other components on the same object can subscribe to the localized non-static one. and anything else that does stuff on any damage can subscribe to the static one

#

I would go with a UnityEvent for the non-static one so you can subscribe in the inspector then just a regular C# event for the static one since you'd only be subscribing in code

limpid wren
#

And because it's a static event I don't need any instance of an HP/Damage component to subscribe to it

slender nymph
#

correct

limpid wren
#

That makes sense

#

I'll try that, thanks!

#

Also about to rewrite every god object to use that pattern instead

grand snow
limpid wren
#

The alternative here was a singleton so I am just trading out one "static" for another

But if you have other suggestions for a damagenumbermanager to be able to know about every health component on every enemy/object I'm open to suggestions!

grand snow
#

what does it do?

limpid wren
#

In this case it just displays a damage number in the location when damage is received. I used to have the HP-component call to the singleton damage number manager when this happened.

#

My general issue has been that I've been having small, placeable objects that want to to generic things. Enemy spawners that want to spawn enemies, things that want to play sound effects or spawn pooled particle effects, etc.

I've been using singleton "manager" objects to deal with that, but that means every scene needs like 10 of these god objects to work

grand snow
#

Right. To me an ideal hierachy could be UI <- Player <- Level Manager -> On Enemy Spawned/Created -> Enemy -> Base -> OnTakeDamage

#

The part i think that matters the most would be "how can the UI know when something takes damage"? Whatever makes and handles enemies should propogate some event up the chain or provide easy access to the objects with said events.

limpid wren
#

What I had was that HP-component talks to the DamageNumberSpawner upon damage taken.

What I now have is that the DamageNumberSpawner is listening to a static "takedamage" event.

That means I can have either object in the scene without the other without a null reference exception

grand snow
#

What i propose is more flexable. If said UI is present or enabled then it can initialize itself. Otherwise nothing happens and happy days

#

A static "took damage" event isnt too bad but is very general

#

I get that what I propose requires good existing design to allow for handling initialisation this easily

limpid wren
#

I'm not sure if I want events on objects that don't seem to fit that object. Like would the player have a "enemy took damage" event? Or the level manager?

grand snow
#

thats just me trying to communicate "flow" not events

limpid wren
#

Sure, but it still seems like these objects expect the existence of other objects, which is what annoyed me to begin with and why I started this rewrite

grand snow
#

level manager inits level, spawns player and player UI. Player UI init is given references to player + level manager ect...

#

Some things cant be avoided but if designed well its more logical

#

e.g. player ui requires a player to exist but thats fine because its directly related to a player

limpid wren
#

Sure. I just got frustrated from adding manager after manager and lots of objects just to get a scene to work here

#

I'd love to have the player UI disconnected from the existence of the player too, if I could

grand snow
#
//Damage Number UI
public void Init(Player player, LevelManager levelManager)
{
    levelManager.OnEnemySpawned += OnEnemySpawned;
}

private void OnEnemySpawned(Enemy enemy)
{
    enemy.OnTakeDamage += ShowDamage;
    enemy.OnKilled += OnEnemyKilled;
}

private void ShowDamage(EntityBase entityBase, float damage)
{
    //Stuff
}

private void OnEnemyKilled(EntityBase entityBase)
{
    entityBase.OnTakeDamage -= ShowDamage;
    entityBase.OnKilled -= OnEnemyKilled;
}
#

example i just created out of thin air blah blah

limpid wren
#

Yeah but the issue is the same here. What calls "OnEnemySpawned"

#

This now requires a reference to the levelmanager, right?

#

And a player

wicked stratus
#

Not sure where to ask this, but
say you have 3 active items and an attack stat of 100
item 1 = 20% increase to attack stat
item 2 = 10% increase to attack stat
item 3 = 40% increase to attack stat
is it more typical/better game design to calculate percentage bonuses like this:

(20+10+40) = 70% attack boost->
attack is now 170

or like this:

100 + 20= 120
120 + 12 = 132
132 + ~53 = 185
attack is now 185

limpid wren
#

That's kind of a design question, but both are equally common.

verbal dome
#

The second one is trickier because order matters

#

But yeah totally a design question

wicked stratus
#

ah okay, I could see the second one get out of control if there's a ton of stuff going on

#

is there a design help/question channel here?

eternal needle
#

the order only matters if theres addition done between

verbal dome
#

True

eternal needle
#

the first way is usually gonna be easier to follow and balance. Though its really up to what you want in your game.
The only real thing to keep in mind is to do all additive bonuses first then multiplication

limpid wren
#

The question here is if the buffs are multiplicative or additive.

I just played raccoin and had a buff that was + 50% every time something happened and I was getting several thousand trillion points because it was multiplicative.

wicked stratus
#

Gotcha. I think in this case the first is probably what I want to do, though I feel it may be a tad bit trickier to implement for some reason

limpid wren
#

If it's easy to lose control over the amount of buffs the player has, go additive. If it's just one or two buffs, go multiplicative

wicked stratus
#

I think there'll be quite a lot

limpid wren
#

So you have List<Buffs>, and just add all the buff.amount's together before applying it to damage

eternal needle
#

additive for example would mean you have a +1. Multiplicative means *1.4

wicked stratus
#

In the second example, I don't think 1.848 would be the correct multiplier for what I laid out (Edit wait it might I'm not thinking properly )but also I don't think the second way is the way to do it for me anymore to begin with-> I'm going to switch to the first yeah.

grand snow
eternal needle
wicked stratus
#

but yes thank you everyone

limpid wren
grand snow
limpid wren
#

I was trying to set up a basic test scene and every object was asking for more objects to be added. What I wanted was the ability to just have the level manager exist with nothing else in the game

#

Or, one enemy, for example

grand snow
#

What i describe allows for this too but i guess that isnt getting through

#

anyway mull over it or not

limpid wren
#

In your example the damagenumbermanager seems to reference the levelmanager, so it would at least need that, no?

eternal needle
# wicked stratus yeah I realized right after send 😭 dunno what I was thinking

regardless i think you should also reread what i wrote because i think theres some wrong terminology being used. A multiplicative buff is something being applied like "I want 50% more". If you have 2 50% buffs, you can add them to make it 100% but doesn't make it additive. That's still being multiplied to your stats (or whatever its used for). if you multiplied 1.5*1.5 instead, that's exponential

limpid wren
#

The enemies immediately barking about wanting to contact the damagenumbermanager and all kinds of other stuff was really annoying to work with

grand snow
#

instead of "jump over everything with static event"

#

as too many of those means spaghetti oh fuck what does anything do

#

Ill leave it there

limpid wren
eternal needle
limpid wren
#

No, that is called "additive"

eternal needle
#

increasing something by 70% is multiplication

limpid wren
#

Yes, but adding two multipliers together means they are additive buffs

#

My "Sword of +50% damage" is additively added to my "+20% damage" orc racial buff to turn into 70%

#

If they were multiplicative buffs, they would combine to +80% because 1.5 * 1.2 = 1.8

eternal needle
#

Yes numbers are being added, the final value of 70% is multiplied to the stats.
The difference in what im saying is values like +1 (added to your stats) need to be done first in the calculations to remain consistent so order of operations do not affect the final result

wicked stratus
# eternal needle regardless i think you should also reread what i wrote because i think theres so...

If I implement it as follows (pseudocode, ik it would be different like with the list format)

List<float> multiplierList = new List<float>(0.2, 0.1, 0.4);

int attackBaseStat = 100;
float ourMultiplier = 1f;

foreach(AttackMultiplier am in multiplierList){
ourMultiplier += am;
}
int ourAttackStat = RoundToInt(attackBaseStat + attackBaseStat*ourMultiplier);

would this get me the correct additive outcome? Just want to make sure I understand your point.

limpid wren
eternal needle
limpid wren
#

foreach(AttackMultiplier am in multiplierList){
ourMultiplier += am;
}

If you switch this to a *= it's multiplicative

eternal needle
#

you can display everything cleanly as ints in the UI but you're losing out on accuracy if keeping everything as ints

wicked stratus
#

ah ok that makes sense

eternal needle
#

a 49% increase to 1 damage is still 1 damage if you use ints

wicked stratus
#

gotcha, thank you

eternal needle
limpid wren
eternal needle
limpid wren
#

err, you're right

#

if the buff numbers were 1.2, 1.4, etc then it would be multiplicative

#

with the numbers given then they would be debuffs

tight sapphire
#

i tried making a 2d game but its blue i added a capsule but it is only a blue screen when i press play how fix?

tight sapphire
rich adder
tight sapphire
#

its 2d

rich adder
#

right which is why there is no skybox and its a plain color

#

a capsule would still show if it were infront of the cam

tight sapphire
rich adder
# tight sapphire this is the scene

without camera selected you cant even see the frustum.. and you have to check z position to be front (camera should be at -10 ish, object on 0)

tight sapphire
#

okay

rich adder
#

you should keep the GameView and SceneView tabs side by side its easier to see

tight sapphire
#

i just started all i know how to do is add a object and add gravity thats it

#

okay

rich adder
tight sapphire
#

it works now somehow

rich adder
#

btw unless code related correct channel for this type of question goes in #💻┃unity-talk

rich adder
tight sapphire
#

so unity talk is for visuals?

tight sapphire
#

thank you

rich adder
#

this is more like scene navigation / usage than visuals

#

btw check out 👇

radiant voidBOT
#

:teacher: Unity Learn ↗

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

tight sapphire
#

is there a turtorial for top down kinda 2d like the binding of issac?

rich adder
#

probably, but you should really be careful following an entire course on something specific without learning the editor basics first

#

most 2d movements are the same if you learn the fundamentals

tight sapphire
#

okay

rich adder
#

check pins there are also c# courses, I'd start there if you don't have any c# exp

valid heath
#

this is probably a dumb question because i think i already have the answer, but if I want an object to follow the cursor, is it best practice to just stick something like "transform.position = mousePosition" inside of Update()? or is there a better way than that

#

i just dont like the idea of something updating every frame but if thats really just the way you're supposed to do it then ig its fine lol

rich adder
#

thats what its there for

#

btw new input system has events so you don't have to use update

valid heath
#

wdym?

rich adder
valid heath
rich adder
#

mouse movement, already has that event and you can assign the position there or whatever but its fine doing it in update not a big deal

valid heath
#

oh i know what events are, i just didnt know there was one for mouse movement

#

ill look into that, thanks

waxen adder
#

How expensive is GetComponent?

naive pawn
#

compared to if, very
compared to a recursive file lookup, not at all

everything is relative

#

you shouldn't worry about the specifics really

waxen adder
#

Yeah, I might be going down a really dumb rabbit hole lol.

rich adder
#

just don't use it in update like every frame and you're fine..

sick laurel
naive pawn
#

gotta be more specific than "not working" though

sick laurel
naive pawn
#

do some debugging, see if Update is being called

#

if it is, see if it's receiving input

#

if it is, see if currentSpeed is correct

#

etc

sick laurel
#

ahh wait i forgot to add the ground check

#

it works now

pliant bridge
#

Can someone help me about this , when i use brush tool in tile palatte to paint the map
but i have world generator , so when it generates

#

it becomes like 2nd pic

naive pawn
pliant bridge
#

kind of, but uhh i fixed it, the issues is sprite Pixel Per Unit, i put it in wrong input so when i do the brush , it costs 4 pixel per item
but when i fixed it, it become 1 pixel 1 item , so when it generated ,it won't conflict each other. 🤓 👆

#

not pixel, i meant grid tile

jovial heron
#

how am it supposed to slice this asset

jovial heron
toxic cloak
#

Hello how do i rename scriptable objects with on validate?

#

is it possible without any errors

#
    {

#if UNITY_EDITOR
        string path = AssetDatabase.GetAssetPath(this);
        AssetDatabase.RenameAsset(path, "Example");

#endif
    }```
#

currently i tried this and works but i get some red editor errors

sour fulcrum
#

if you have errors just post them

#

otherwise people need to ask for them

toxic cloak
#

UnityException: Calls to "AssetDatabase.RenameAsset" are restricted during asset importing. Please make sure this function is not called from ScriptedImporters or PostProcessors, as it is a source of non-determinism.

sour fulcrum
#

sounds like no

#

what are you trying to do

toxic cloak
#

like rename my assets based on the data i assign to that SO

sour fulcrum
#

have you tried just changing .name? might not work it's been a second since i've messed with it

toxic cloak
rancid tinsel
#

any idea why the min isn't working? I can set to 0 and negative

#

setting to 0.1f also doesn't change the default value of 0

somber solstice
#

hey all!
can anyone tell me if it will actually help with performance to call System.GC.Collect() during loading screens?

rancid tinsel
sour fulcrum
wintry quarry
#

I don't think Min has ever done anything in the inspector

rancid tinsel
wintry quarry
#

make a really large max

sour fulcrum
wintry quarry
#

e.g. float.MaxValue

sour fulcrum
rancid tinsel
rancid tinsel
sour fulcrum
#

!code

radiant voidBOT
rancid tinsel
#

I know how to paste code, just showing why my set up is weird

sour fulcrum
rancid tinsel
somber solstice
#

atwhatcost back to looking for more ways to optimize gc

swift crag
#

notably, garbage gets collected pretty frequently, even if you aren't allocating tons of garbage

#

(and there will absolutely be a GC collect when you unload a scene)

#

i've noticed that the collect is the main source of lag when switching scenes

teal viper
cosmic dagger
#

You never need to call it manually . . .

somber solstice
# teal viper Is it actually creating an issue for you to optimize it?

Well, I do have quite a lot of garbage piling up...
I removed most string creation from my code, and swapped to using material property blocks instead of material instances to save up on memory, etc...
But I have memory leaks when unloading reloading scenes repeatedly and I see some garbage accumulating over reloads

somber solstice
#

profiler?

teal viper
#

What exactly do you see?

#

Collection spikes?

cosmic dagger
#

The profiler should be able to tell you what scripts and methods its coming from, no?

sour fulcrum
teal viper
#

Because you might be optimizing in the wrong direction?

somber solstice
somber solstice
# teal viper What exactly do you see?

memory usage slowly climbing over time and sharply climbing when unloading/reloading areas (that's what i do to make enemies respawn, reset level etc), a few collection spikes here and there. I know I do very little pooling which is probably very bad but ALSO kind of too far gone to begin fixing now

naive pawn
#

kind of too far gone to begin fixing now
yet here you are trying to fix it indirectly

teal viper
#

Use the memory profiler. Make a few captures throughout the game and diff them to see what increased memory consumption.

somber solstice
somber solstice
cosmic dagger
somber solstice
#

Any idea how I could determine how much of a problem it actually is? Stuff I should look at in profiling?

swift crag
#

You are going to allocate garbage

#

that's expected

rich adder
#

managed language for ya

potent portal
#

i setup IK and i want to disable it for the time being and have the normal animations that i have. how could i do that?

rich adder
#

assuming by "Setup IK" you mean the animationn rigging package

potent portal
#

that didnt help

rich adder
#

try lowering the weight on the IK component itself

#

they should all link to Rig builder though

potent portal
#

wtf it still didnt work

#

this is so weird

#

i even have Foot IK disabled on the animator

rich adder
#

which IK components are you using exactly ?

potent portal
#

im just going to try and restart the process

#

i most likley set it up wrong

#

i had to rig builders

#

okay i set it up once again

#

and i cant disable it

potent portal
rich adder
#

which version are you using ? I wonder if it could be a bug

potent portal
#

6000.0.67f1

rich adder
#

have you tried disabling the TwoBone IK entirely ? does it restore the animation

potent portal
#

let me try that

#

the only things that move are the arms

#

its really strange

#

well the arms are stuck in a pose

#

they just rotate

rich adder
#

was it working before you added RIG/IK to it

potent portal
#

yes

#

disabling the Rig Builder Component fixed it

fast coral
#

Hey I need to constantly call this function instead of it just doing it once when its performed and not really sure how (playerControls.Movement.Move.performed)

#

I hope this is the right channel🥲

naive pawn
fast coral
#

copy 🫡

naive pawn
fast coral
slender nymph
#

or just assign the ReadValue result to a variable that you then pass to the Move call each frame in Update

naive pawn
#

oh that's playerMovement, i read it as playerControls

#

but yeah there's several ways to go about this

fast coral
#

I did the caraible method thanks my gs ❤️

ripe oyster
#

weird question:
i use a script which needs to activate a function in a different script. the problem is that it needs to activate the same function in 3 different scripts, as in 3 seperatly named script with the same named function. is there a way to do this?
(context: i am making a puzzle game in which i have each rule only checking if it's correct when you press a button, but because the rules are different they each have a different way of checking if it's correct or not)

keen dew
#

That's what interfaces are for

ripe oyster
#

right, i forgot about those even though i'm using one of them. thanks

swift crag
#

one important note there – you cannot assign references to interface-typed fields in the inspector

#

so you can't add a public IClickable target; field and assign it in the inspector

#

you can, however, use interface types in TryGetComponent

#

very useful for interactions

wintry quarry
grand snow
#

You can cheat and serialise a MonoBehaviour or Component reference and cast at runtime. Best used with a validation however

ripe oyster
#

forgot to send an update. for the prototype i noticed that i used a button, so for now i assigned all the functions to that button too (which meant that the button now has 10 things it does, but hey, it's a prototype. once i get proper programmers to help me we'll make it betteR)

slim night
#

موجود ؟

#

في عربي هنا ولا

rich adder
slim night
rich adder
slim night
#

حمار

#

الزبده يا اخوان في عربي ولا

rich adder
slim night
frosty hound
#

Didn't care so much they ran away.

open crater
#

Guys a question, if i have 5 scenes and a random player play the game, does every scene load once the player open the game or just the starter one? How this affect the performance of the game?

#

I mean every scene will be loaded or just the selected one

rich adder
slender nymph
#

by default unity will load whatever the first scene in your load order is, then you are in control of what is loaded beyond that

open crater
teal viper
#

Performance is based on whatever scene is currently loaded.

rich adder
#

you open a scene, it loads whats in it.. simple as that

open crater
#

Ok, so is it worth if I plan to make a 2d unity platformer game with levels?

#

Or just everything in a scene? Im talking about NO MENU

teal viper
#

I'm not sure how to parse these questions... 😅

rich adder
#

thats more a design thing, not performance.
make it easier on yourself and make each one a scene

open crater
#

Okok ty guys, sorry if questions seems dumb but im on early-developement 🙂

rich adder
#

its fine to ask, no need to overthink performance stuff . just make things

teal viper
#

You can have all levels in one scene and still have a menu. You can have a menu with levels split into their own scenes. You can have no menu and levels in one scene. And you can have no menu and levels in their own scenes.
These are not self contradicting options.

#

And really, performance is probably not the biggest concern here anyway. At least not in 2d.

rich adder
#

I've seen lots of creativity flows get interrupted by over fixating on the minor details, micro optimizations w not much benefit

open crater
#

Ok ty again

cinder fog
#

Hey guys can you help me? I'm trying to script an auto detect feature for some hovercars and there's just this one part I need help with. What do you call the z axis in rotation part in unity? Like I mean the rotation in the transform tool. Cuz I had something going where if I can figure out what the thing is called then I can set a param for it that I can make an if statement for it to rotate itself back upright. Im using Unity 2021.3.5f1 (school reasons) and im SUPER new into coding so my prof will dock points for using lerp quanterion or raycast.

slender nymph
#

i'm not 100% sure what you're asking here. are you asking how you access the Z axis of the rotation in code?

cinder fog
#

yeah kinda? cuz like you can code Input.GetAxis("Horizontal") for like position and forward movement in controls right? I want to know how to call the z in rotation so I can code a script that flips it in a natural looking way, not just snap it to +1

slender nymph
#

look at the Transform class which is where an object's position and rotation are both stored

#

unless you are asking how to get rotational input (like mouse movement) because it is still not entirely clear since your example uses something pretty much unrelated

cinder fog
#

Ah its hard to describe in text I guess. But like uh, will a picture work?

slender nymph
#

unlikely, but you can try 🤷‍♂️
the disconnect here seems to be your utter lack of understanding of how components and your code work

cinder fog
#

Yeah 😅 go easy on me, its my first rodeo like I said

slender nymph
#

i'll point out that Input.GetAxis("Horizontal") actually has nothing at all to do with "position and forward movement", it's just a method that returns the value of your Horizontal input axis, how that returned value is used is typically related to those things you mentioned, but the method itself is entirely unrelated

#

so are you trying to rotate the object, get some sort of input that you will then use to rotate it, etc, this part is not clear

tight sapphire
#

anyone know whats wrong with the code?

slender nymph
#

!ide 👇 use a real IDE to code, not notepad++

radiant voidBOT
teal viper
tight sapphire
#

thats what it opens automaticaly

teal viper
cinder fog
tight sapphire
teal viper
tight sapphire
slender nymph
# cinder fog

again, those Input.GetAxis calls are not related to the properties shown in the inspector. you're modifying those properties by using the transform.Translate call below. but it seems like you want to get input that you can then use for the transform.Rotate call, yes?

tight sapphire
#

bc if i pick one im not swapping

slender nymph
#

start with visual studio which should have been installed along with unity by default

tight sapphire
#

okay so how do i even get it to open with that

solar hill
#

look at the bot message

cinder fog
teal viper
slender nymph
solar hill
slender nymph
tight sapphire
#

downloading it

cinder fog
#

yeah, so the car can rotate itself back upright if it detects that its close to flipped over

tight sapphire
#

so my entire proplem was... bc of terrira

#

i think

solar hill
#

follow the ide set up guide linked above and you should be good to go

slender nymph
solar hill
#

i still dont see how input is related 🧐

cinder fog
#

I really didn't know what I was looking for

slender nymph
#

anyway, detecting if the car is flipped isn't going to be something that's really all that simple with your current level of knowledge. you might think that just checking the current rotation might be enough, but the rotation in degrees is interpreted from a quaternion at the time you access it so the angles may be signed or unsigned depending on what the engine decides to give you, multiple different values can also end up as the same rotation.
so the easiest thing to do would be to simply either lock the rotation around whatever axis it is that you want to prevent from flipping, or just don't rotate it around that axis.
since you have a rigidbody but you aren't actually moving with it, you'd want to do both

#

but also you'd want to consider moving via the rigidbody rather than the transform since you are fighting against physics doing this

cinder fog
solar hill
#

well yeah if you say "rotate if x <= 0.2" then its not going to bother rotating any more at 0.25 because its fulfilling this conditional

cinder fog
#

yeah I figured that out last night 😅 but i any higher was too strict of a requirement...

solar hill
#

youre missing the point

cinder fog
#

oh, sorry...

solar hill
#

think of it this way... if you tell me "the glass cant be empty" and i pour 1 droplet of water into an empty glass* the glass is no longer empty

#

there is no expectation of me to fill the glass all the way

#

you have to define that rule

#

'if car is flipped: rotate back to upright rotation'

cinder fog
#

yeah, I was going to add more that would have it rotate itself back to +1 but I couldn't figure that part out because I don't even know what im calling for

#

the closest I got to last night just had it spin like a spit roast infinitely

solar hill
#

imo boxfriend is right... i wouldnt bother with it for now.. its a bit too complex for you to handle it as is, use a simpler approach

cinder fog
#

I just looked into the input manager and it didn't seem to help much, I have two inputs for horizontal and vertical, the dropdown for each doesnt seem to help either

#

oh, ok.

#

My bad to waste everyone's time then, I'll uh, go work on the sounds effects for this project...

solar hill
#

youre not really wasting anyones time

#

thats the point of this channel and server

#

knowledge is never a waste of time

cinder fog
#

I feel like I pissed off boxfriend kinda, I guess I did kinda sound like a know it all earlier 😅

tight sapphire
#

are you still a game developer if all your codes copy pasted

tight sapphire
#

mow whats wring with it

slender nymph
#

what does the error message say

tight sapphire
#

idk my screens not propperly croped

#

cant see it

#

and i acidently didnt save it so cantsee now

#

just tried opening it and what do i do bout this when openign the project

slender nymph
#

ignore it, that will pop up when you have compile errors and try opening the project

#

the only time you need to enter safe mode is if you have errors in assets/packages that could break the editor in some way

tight sapphire
#

could someone copy paste the code for movement maybe?

slender nymph
#

there are hundreds of tutorials for movement, pick one and follow it. we don't do code handouts here

tight sapphire
#

okay

#

how do i find one for the top down veiw type of movement

#

nvm

#

found a 3 minute one

slender nymph
#

rather than finding random tutorials that barely teach you anything, you should consider going through some structured courses so you can learn what you are actually doing instead of just stumbling along blindly. the pathways on the unity learn site are a good place to start with that

woven thistle
#

what does this error message mean

slender nymph
#

!input 👇

radiant voidBOT
# slender nymph !input 👇
How to Set Input

To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling

• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.

woven thistle
#

this happened when I did that. The character has disappeared.

woven thistle
verbal dome
#

Why do you have so many missing scripts

#

Did you remove URP or something

woven thistle
verbal dome
#

It's a package, a render pipeline for unity.

#

What's the history of that project

#

Did you recently create it or did you create it with an older unity version or what

woven thistle
#

I just created it today

verbal dome
#

So what used to be here instead of (Script)?

woven thistle
#

I wasn't able to get the character to move on screen through input, and then did what the person above recomended, changing the input type

#

nothing

woven thistle
verbal dome
#

Changing the input handling does not (should not) affect the rendering in any way

woven thistle
#

should I change it back then?

eternal vale
#

Hello 🙂

#

Im new

verbal dome
woven thistle
#

that is what I titled the script

verbal dome
#

But you just said there was nothing

eternal vale
#

Learning Unity after Godot is intense brutal training

#

😭

woven thistle
#

I thought you said what was there before I added the scipt, that is the name of the script, that is the script

verbal dome
#

Ah. Well it's broken, unity can't find it for some reason

#

Anway, close unity, delete the Library folder in your project folder, and restart unity. See if that helps

woven thistle
#

I am not 100% sure my VS code studio is even compatible with unity. I did follow setup instructions cause i had problems with that before, is there any test I can run to make sure they work together

verbal dome
#

Send a screenshot of a unity script open in VS code first (don't crop it)

verbal dome
#

Yeah this part instantly tells us it's not configured

#

!vscode

radiant voidBOT
verbal dome
#

Follow those steps^

woven thistle
woven thistle
verbal dome
#

Open your project and find the package manager in the unity editor

woven thistle
#

thanks. Makes sense

median hatch
#

ayo does anyone know when the next unity asset sale is? and if hot reload is worth it?

remote sequoia
#

Documentation says FindObjectsByType<>() return Objects[] but when I try to assign it to the GameObject this happens

#

Why?

sour fulcrum
#

Enemy is not GameObject

median hatch
#

you're trying to find a script

remote sequoia
#

But doesn't this code block find and list objects with the Enemy script? Are there only Enemy scripts on the list or are they stored in objects with that script?

sour fulcrum
#

Objects aren't always neccasarily GameObjects

remote sequoia
#

I need to access the transform of objects with the enemy script

sour fulcrum
#

you can access .transform on any MonoBehaviour

median hatch
#

a gameObject is something defined by unity

#

every gameObject must have a transform

#

an object is defined by yourself or any other libraries you may use

sour fulcrum
#

kinda not right

#

a GameObject is a Object too

median hatch
#

a gameobject is defined by unity

#

thats my point

#

doesnt matter how they did it

eternal needle
#

This seems like a major sidetracke from the fact they just are using the wrong type in that loop

median hatch
#

xD

sour fulcrum
#

that's already been pointed out

remote sequoia
#

Understood, thanks!

median hatch
remote sequoia
#

foreach (var enemy in FindObjectsByType<Enemy>(FindObjectsSortMode.None))
This means find all the objects in the scene with the enemy script and count them all as enemy and do something for each
Am I understood right?

naive pawn
pliant bridge
#

Can Shader Graph can replace a Fake Shadow from prefab?

remote sequoia
median hatch
remote sequoia
median hatch
#

its not well optimized tho

#

i'd create a list in Start() and assign all enemies there

#

then loop through them whenever

#

FindObjectsByType is an expensive way of finding objects

remote sequoia
#

But the enemies die and when they all die, they respawn, how else can I update the list constantly?

median hatch
#

C# events

remote sequoia
#

Ohh I have to deep dive to the events got it

stuck parrot
#

how do I got ALL my coin objects into the serializefield? ```cs using UnityEngine;

public class CoinCollector : MonoBehaviour
{
public int score = 0;
[SerializeField] GameObject coinObject;

void OnTriggerEnter(Collider other)
{
    if (other.CompareTag("Coin"))
    {
        score++;
        Destroy(coinObject);
    }
}

}```

stuck parrot
unique thistle
#

make an array or a list

median hatch
#

you want all coins to go into score?

#

or you want an array of coinObjects?

unique thistle
#

[SerializeField] GameObject[] coinObject; for an array

median hatch
#

i think i see what you mean

stuck parrot
median hatch
#

you can directly destroy the coinObject without needing a class reference

stuck parrot
#

but I can only put one object in the serialize field

median hatch
#

Destroy(other.gameObject)

#

no need for lists

stuck parrot
median hatch
#

for the future you can also access scripts and components inside that other.

#

other.GetComponent<Transform>(); for example

median hatch
#

you're checking if other (the object you're colliding with) has a tag of "Coin"

stuck parrot
#

I already tried Destroy(other); but that didnt work. Most of the time I try stuff out until it works but this time I lost 😅 as soon as there are "." seperations involved I loose track of what is what

median hatch
#

yea it takes a while to get used to it

#

other in this case is a Collider

#

for example BoxCollider, SphereCollider and so on

#

when you do other. you get all its values + able to get other components that are on the same gameObject

#

basically you can do crazy stuff with colliders

median hatch
#

when you do Destroy(other.gameObject) you're destroying the object itself, not the component

stuck parrot
sage mirage
#

Hey, guys! Is it fine to leave fields empty in the inspector whenever you change scenes and let's say the game won't print null reference because it doesn't trigger the specific code for it to trigger?

pliant bridge
#

i think it is, it won't print null, just none, u can't see the object even object is spawned i guess

strong wren
sage mirage
#

You know there is a problem I have, so I found a way to fix it at runtime. So, the problem is that I have a UI manager object in title scene and a game over panel object in main scene, I do dont destroy on load for the UI manager object in title scene in order to persist in main scene as well then what I did was to create a new script called MainSceneUIBridge and actually connect the local game over that I have in the main scene with the one in the UI manager. Check it out 👇

{
    [SerializeField] private GameObject localGameOverPanel;

    private void Start()
    {
        UIManager.Instance.GameOverPanel = localGameOverPanel;
    }

    private void OnDestroy()
    {
        UIManager.Instance.GameOverPanel = null;
    }
}```
ivory bobcat
sage mirage
#

I think I did right no?

#

because like I said my game over panel object lives only in the main scene

strong wren
sage mirage
#

so whats the best practice just to have it empty?

#

as long as it doesn't print NRE I think I can leave it as empty

#

because on the main scene what I do is actually assinging it at runtime

ivory bobcat
#

I just said this isn't a best practice concern but explicitness..

strong wren
#

It's better to get an error than accidentally do stuff with a prefab. Error will tell you if timing between accessing the object and setting it is wrong.

sage mirage
#

I just wanted to know

pliant bridge
#

Is there any ways to make the shader or lighting for the terrain no more flat?
as i researched they add normal maps for tiles, and then use shader graph, is it true?

pliant bridge
#

uhh i searched on reddit

#

and youtube

#

do you have any ideas 🙁

teal viper
pliant bridge
#

i meant i create 3 tiles with 3 kind of sorting layers, i was trying to make 3d terrain in isometric, but idk how
i made 3 tilemap for making multi-level terrain, like this image. but the image you can easily too see which is lower, which is higher

#

but mine can't

teal viper
pliant bridge
#

How can i do that

teal viper
#

Didn't the tile map component have a tint/color property?

#

Maybe not. But it seems to allow selecting a material. So you could configure the color on a material.
Btw, #🖼️┃2d-tools is probably a better place for this question as it's not code related.

pliant bridge
#

I used default material,it called sprite-lit-default

#

And it all the same

#

So idk

#

Ill see it

distant orchid
#

Hey guys any good tutorials on YouTube I’m very new to unity

frosty hound
#

!learn

radiant voidBOT
distant orchid
#

Learn *

naive pawn
solar hill
#

And you unity learn is better than 90% of youtube tutorials kekwait

naive pawn
#

i mean, that's just because there are a lot of bad tutorials on youtube

polar acorn
sage mirage
#

Hey, guys! By mistake, I have staged my changes in the wrong branch in develop branch basically and I am not sure what to do. I have to unstage them and then stage them on the feature branch I have

#

I am trying to commit and it says changes not staged on the feature branch

swift crag
#

what version control software are you using?

sage mirage
#

Github bro

#

What else

#

XD

#

Wait I know what I have to do

#

I am going to stash the changes and then pop in the correct branch

#

Oh, shit!

#

I got some trouble guys

#

I can't solve this issue XD

silk night
silk night
polar acorn
naive pawn
# sage mirage Github bro

that's a service, not vcs
the underlying vcs is git

you're also using github desktop in that screenshot

obsidian grove
#

am I crazy or is there no way to assign a specific monobehaviour instance to a serialised field?

#

like, you can't drag a specific behaviour from a different GO because the editor UI just doesn't let you

naive pawn
silk night
#

yeah you can

naive pawn
#

if you're referring to the inspector getting changed when you select the new object, lock the inspector

#

(there's a lock icon in the top right)

obsidian grove
#

but then I can't drag a behaviour from a different GO because the inspector shows the one with the field

#

and I don't think you can have multiple inspector windows 🤔

silk night
#

you can

#

also you can click on the 3 dots top right of a script and click on properties, that way you pop out that thing and can drag other stuff in there

polar acorn
#

You also don't need to drag in the behaviour, you can drag in the object and it'll automatically use the one on that object

silk night
#

(unless one object has multiple of that script and you want the 2nd one)

polar acorn
#

You should probably avoid having multiple copies of the same component on the same object

#

Mostly for situations like this where the one you get is ambiguous

silk night
#

of the same concrete yes, ive seen multiple classes that inherit from the same interface on one gameobject with the interface being the field type

polar acorn
obsidian grove
#

ah I don't have multiples of the same component, or a field for a specific monobehaviour, I was literally just doing:
[SerializeField] MonoBehaviour[] blahblah

naive pawn
silk night
#

then you can just drag the gameobject and it will pick the right script

#

also makes handling that field a lot easier down the line 😄

polar acorn
#

What benefit could you possibly have for making an array of monobehaviours

obsidian grove
#

it's because different prefabs with the same script will need to have different behaviours disabled at a certain time

#

depending on the prefab

silk night
#

Yeah then just do {className}[]

#

instead of MonoBehaviour[]

#

oh wait different behaviours?

polar acorn
naive pawn
#

this sounds like something you could make more specific/streamlined with the right abstraction+constraints

silk night
#

my suggestion is give them a common interface that each needs to implement

public interface IEnableableBehaviour {
  public void SetEnabled(bool enabled);
}

then you can make the field a IEnableableBehaviour[]

naive pawn
silk night
#

mhh fair

polar acorn
#

I feel like there's a work flow that doesn't involve dragging in specific components on an object. I'd need to know more about the "why" to know for sure the "how"

silk night
obsidian grove
#

is there a specific reason why I shouldn't do this?

#

it is a bit lazy but this prefab isn't super common so the sloppy workflow doesn't matter

silk night
#

depending on the type of project/collaboration with other people and scope of the whole thing your method is potentially totally fine
it might be less maintainable, less automated, more fragile than other methods but if it works and has no major impact on anything there is literally no problem doing it like you do

#

if you know you would add hundreds of other gameobjects there over time you would pick a more automated solution
if other people need to understand it you would look for maintainability
if that manages the main aspect of your game and other stuff is built around it you would look to build it robust so it doesnt break once other things conditions or mechanics come into contact with it 😄

obsidian grove
#

that's a great response, thank you

swift crag
#

If you genuinely just need to turn behaviours on and off, then Behaviour[] is appropriate

#

Although there is the gotcha of things like Renderers not being a kind of behaviour

#

how annoying

sharp bloom
#

Funny thing; when I first learned about Events, I started with Unity's Event system and struggled with it for months. Then I started using native .NET actions and it all worked like a charm

Now the same thing has happened with async/await, I tried using Unity's Awaitable class, no luck and I thought it was really difficult. I've just learned about native .NET tasks and again, it all works like a charm.

Huh.

teal viper
#

Not sure what there is to struggle with. They're basically the same concepts.

honest iron
#

i made this star, i want it to move and spin like a disc, but instead of spinning its moving like there is an orbit, anyone know what should i do?

sharp bloom
#

Honestly not sure. Something about Unity's own documentation just didn't click for me.

mint imp
#

Hey guys I'm having an issue with input across scenes.
In my main scene I'm using an input reference "Move" that is a vector 2, to get the direction i want player to move. Normal stuff.

but when trying to use the same input reference in a different scene for a differnt player movement script (because its for a top down map view)
It just doesnt recognize imputs remotely?

Every one of those debugs say false regardless of pressing input or not

mint imp
honest iron
#

StarBox - parent with the script
Star - Child with the meshes

real thunder
#

So I want to find the most reasonable target to start homing to for a homing rocket (fps rocket launcher weapon this case)
I thought that that would make sense to go through all possible targets and...
If I just aim for the closest one that won't do the trick, homing backwards is not great
I figured I can sort targets by their distance....
and then... ugh... adding to that distance a penalty somehow using dot product of rocket speed and toTarget... and ugh... yeah... If anyone know about existing good approach or have a better idea let me know, because I haven't yet fugured useful formula out

mint imp
teal viper
real thunder
#

wa

#

what certain radius?

teal viper
real thunder
#

lets say it's infinite

mint imp
teal viper
#

Then just get all targets in the scene and find the closest.

real thunder
#

"If I just aim for the closest one that won't do the trick, homing backwards is not great"

teal viper
#

You said infinite radius

#

Which implies backwards is ok

real thunder
#

not really

#

it's easier to hit target ahead but not behind

#

the point is to get a target which the most reachable

teal viper
#

Then it's not infinite.

naive pawn
#

...no?

sage mirage
naive pawn
#

is this not directional?

sage mirage
#

Guys I cant figure out what to do

naive pawn
#

did you set up the .gitignore correctly to begin with?

teal viper
polar acorn
sage mirage
#

That's my gir ignore

naive pawn
#

@real thunder is this what you have in mind

naive pawn
#

that's missing UserSettings as mentioned

real thunder
real thunder
naive pawn
naive pawn
sage mirage
#

I have used AI to tell you

#

And copy pasted the git ignore

naive pawn
#

yikes

#

maybe don't use AI to feed you bs on stuff you don't understand

teal viper
#

Not a technical question.

sage mirage
#

Ok now I got very confused because I am confused XD

naive pawn
# sage mirage

and yeah this lfs config does not work. that stuff needs to be in .gitattributes, not .gitignore

naive pawn
orchid wolf
#

Hello everyone, I have a question.
So, I want to make item system like in risk of rain 2, but I don't know the right way to store items in Unity. Right now I have scripts where I create option in context menu to create item. (Screenshots applied)
I am sure I am doing something wrong so I would appreciate any advice.

naive pawn
#

there's no "right way", there's several working ways

#

what's the issue you're having?

orchid wolf
#

Let me show

polar acorn
naive pawn
#

how what looks?

polar acorn
#

It's fucking built in

orchid wolf
# naive pawn how what looks?

nvm, it's about logic. I am not planning making more than 1 item with the same logic. So like, I thought maybe there is a way to store logic and then somehow address to it when working with inventory.

naive pawn
#

kinda sounds like you're just describing polymorphism?

orchid wolf
#

Like, what's the point in that if they share same name, values and functions?

naive pawn
#

ok, and why would you have 2 of those

#

like.. yeah, what's the point

polar acorn
naive pawn
#

you would more likely have multiple BaseItems (probably(?) mostly through subclasses), rather than multiple Vampires

orchid wolf
polar acorn
naive pawn
#

why would unity have a separate, different version of a core OOP concept

polar acorn
#

Unity's designed around it, it's one of the reasons Javascript was ditched years ago, so they could go full-bore into C# support for things like interfaces

real thunder
orchid wolf
#

I think I just confused myself, gotta make it simple

naive pawn
orchid wolf
#

thanks everyone, gonna change that and maybe ask again

polar acorn
naive pawn
orchid wolf
#

Now I just need to figure out a fance way to set Name, Description and Sprite for each class

naive pawn
#

you already have serialized fields

real thunder
naive pawn
orchid wolf
naive pawn
#

scriptableobject

#

not a c# thing, the unity thing

orchid wolf
#

ah

#

I think I won't work with so

#

just, general classes

sage mirage
#

Because I really think I have to die

naive pawn
naive pawn
orchid wolf
sage mirage
sour fulcrum
sage mirage
#

I am not sure how to revert this shit

#

XD

naive pawn
sage mirage
#

Maybe to create a new repo and set it up from scratch again

naive pawn
#

why are you even here when you don't read anything anyone tells you

sage mirage
#

get user settings, project settings and Assets files and do this?

honest iron
orchid wolf
#

So this is how it looks now. New question is, what's proper way of loading sprite.

#

I read there is "Resources.Load" but people say to never use it

#

probably because it yields

polar acorn
orchid wolf
polar acorn
#

There's not really a reason for this item to have a constructor. You already have an instance in your assets folder

#

Just assign the values to that

polar acorn
#

You're creating these SOs in the editor, you shouldn't have a Constructor

#

You're not creating them in code

wintry quarry
polar acorn
orchid wolf
#

Thanks, but do I really need to use SO? Yes, I created item in editor. Yes, I assigned values to it. But why do I need to create SO for a single object?

wintry quarry
#

I would find a different way to dispatch the behavior. This will be unwieldy to manage, IMHO.

orchid wolf
#

For example, if we had guns, yes, I would create SO to set damage, fire rate and etc.

#

but each item in my game is unique

#

with unique functions

sour fulcrum
orchid wolf
sage mirage
#

So, I am close to merge my feature branch to develop branch.

polar acorn
sage mirage
#

I don't have much experience in solving merge conflicts to tell you, because it is very rare in my case I am working solo

polar acorn
orchid wolf
naive pawn
#

.name, it's just a field/prop

orchid wolf
#

ah, yeah, GameObject

sour fulcrum
#

Unity.Object*

orchid wolf
sage mirage
cosmic quail
naive pawn
#

also read the things we say

naive pawn
real thunder
#
int dim = 5;
targets = new Transform[dim * dim];
        for (int i = 0; i < dim; i++)
        {
            for (int k = 0; k < dim; i++)
            {
                Debug.Log(k + i * dim);
            }
        }

why does it go 0 5 10 15 20 25 overflow? 🥴

#

oh hey I see why now, posting is amazing

swift crag
#

ah, classic increment blunder :p

pliant bridge
#

do you guys have any solutions for muti-levels, 3d terrain for world generator in isometric/2d ?

cz i was thinking about making a solution like this:
I will only make a ground tile map as a base layer
and a script will be world generator, it will generate clone tilemap that will up up up over and over again to make cliffs, hills, or smt like 3d terrain.

Do you guys have any ideas?

real thunder
#

no, but I feel like performance would suck this way

wintry quarry
real thunder
#

I wonder how does Minecraft does that

#

out of curiosity, geometry wise, how does minecraft terrain looks like?

#

I am not even sure my question make sense in this form

#

but it's clearly not many cubes

wintry quarry
#

like I said, mesh generation

real thunder
#

each chunk is a mesh or something along those lines?

wintry quarry
#

each chunk is a mesh yes

real thunder
#

sounds surprisingly simple but I wonder how bad can it be if you

#

well, build alot of chunks

#

where each one is a very detailed non convex thingie

wintry quarry
#

That's why minecraft has a setting for render distance

#

and why it only simulates chunks you are nearby

sour fulcrum
#

sounds suprisingly simple until you watch a video on world record mob farms

real thunder
#

what's up with that

#

is this related to chunks being meshes or chunks being... chunks?

#

I mean I am talking only about rendering/hitboxes thingie