#💻┃code-beginner
1 messages · Page 831 of 1
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
No because in editor the assets will keep changes made in play mode
also may fool you into thinking "wow easy data saving"
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
It's so easy that I'm surprised Unity hasn't made a version of scriptable objects that -does- function that way
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
I think unity have avoided making their serialisation usable at runtime as it would introduce new challenges they dont want to solve
they are intended to be changed at runtime too, just depends on what your doing. the 2017 unity talk on them has multiple examples of doing so
I know what SO's do
Hi umm I need help with a code for my uni assignment ^^"
!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
So, instead I can just use a regular class and do change the values at runtime right?
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
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
ahh sorry
Use one of these, list is being updated
https://hastebin.ianhon.com/
https://pastes.dev/
https://paste.yunohost.org/
https://share.sidia.net/
https://paste.ofcode.org/
https://paste.myst.rs/
if you know how to use it
oki thank u
a pastebin that will never expire. forever.
does that work
what's the issue you're having?
If you could explain your problem better? What exactly are you trying to accomplish? That was a bad description.
I see you have a method called AttackPlayer() which is empty
//States
public float sightRange, attackRange;
these wouldn't be states, btw
(the 2 bools are though, as well as walkPoint, walkPointSet, and alreadyAttacked)
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
ahh dang
that's what you're trying to do
what's the issue with the code you have right now
how does the code you have differ from the goal
you'll have to design a system to allow that kind of attacking then
Would u be able to explain how i could
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?
Theres the patroling state, the chasing state, and the attacking state
patroling is when the chickens just roaming
what is the attacking state exactly
dash + destroy player
or do they needa be separate
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?
both ^^"
alright, one at a time
sorry im still learning
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.
Let me look at it
I see you dont have any state pattern
what makes it a state pattern
is the "dash" just higher speed while the player is near, or a distinct boost of speed?
Hello fellow humans
yes to the first one
cool, just set the navmeshagent's speed higher when the player is in that smaller range then
you'd need some way to detect that they're "touching", im not sure if the navmeshagent has something for that built-in
Mmm no idea
also not sure if rbs would interfere with the agent, i'm really not familiar with navmesh
you could just check distance though tbh
how would u usually check for collision
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
Can you send a video by the way of your game to see what's going on?
i dont have alot right now
Yes i am
@sage mirage Don't start with the off-topic here
So where is the kitchen and where is the fox you were saying?
chicken is the cube, the fox is the sphere for now
What about the egg?
egg is the oval looking shape, its wat the fox is going to try to get and get "points"
i needa figure out how to do the scoring as well
this is all kinda unnecessary...
Wdym
this thread of conversation is irrelevant
Ohh right
Pretty sure agents have a callback when they reach destination. Otherwise you need to handle collision events yourself
Ah
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
That is useful then, ill just needa figure out the collision
on top as in literally on top?
if you want to handle collisions there are ways if you want to know...
!learn You should check tutorials about trigger colliders and events on
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
literally at the same position, inside of each other
unless there's a configurable threshold
so would the rb not interfere with the agent?
Yes pls
I don't remember how agent handles physics, pretty sure I used with it for one of the game jams.
Would it have changed from 5 years ago
probably not
(though like i mentioned earlier you could probably just use a distance check for a quick & dirty solution)
xD okay
That is the wrong chat :)
-# breaking news, fogsight caught sending off-topic
It was an agricultural discussion for all concerned.
@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.
yea i dont think i can do manual pathfinding
In Unity there is a built in way to do all these stuff?
what do you think a navmesh is
and it actually does everything?
Like what about pathfinding or whatever you want to do with AI?
NPC's lets say
just go
it man
Why are you asking?
to be sure? i dont wanna break anything
Is there anything specific you're worried about?
just wanna know if i did the increase speed thing correctly
Does it not work?
it gives me an error message when i try to attach the script to the object
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.
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
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".
its unity 6.3
Hmm... Okay. Are there any other errors?
it gave the same error message when i fixed it
Take a screenshot of your console.
Okay. Take a screenshot of the warning that you mentioned.
Something on line 34 of ChickenScript is null but you're trying to do stuff to it anyway
ohhhhh that makes sense
By the way, one guy in this server recommend me this website a year ago or 2. Check it out its amazing, you can find explanation on these errors, warning or whatever related with Unity.
https://unity.huh.how/
thank uu!
I should make settings menu IDisposable?
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
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
ok wait nevermind
if i just set the velocity directly like for example rb.velocity = new Vector2(10, -10); it works, so its specifically reflect
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
ok i just realised this is the weirdest way to code this ever im just gonna use rb.addforce since i think thatd work the same way but if it doesnt illl try this (i was typing this message before you replied)
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
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
show what you tried
so not in the Reflect call then?
that's still wrong
WAAIT if orgot to change the rb.velocity in the second bit
you still need to be assigning to rb.velocity, the only place you would replace rb.velocity with Velocity is inside that Reflect call

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
are you getting the rb every frame lol
you should not, you should cache that retreival
is this in Update?
let me try that real quick if that changes anything
it won't
yeah
it's just good practice
should i move it to fixedupdate
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
ok
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
i used interpolation (both modes as well as none)
and how can i rotate with rb ?
theres this moverotation function does that work?
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
ok you could use that delta, and get the angle compared to Vector2.right, iirc
https://docs.unity3d.com/ScriptReference/Vector2.SignedAngle.html
so i would create a quaternion with the current rotation + the delta ?
and use that on moverotation
you don't need quaternions
it seems the moverotation function takes a quaternion as input
hold on
it takes either a float or a quaternion, and a float would be simpler to work with here
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
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.
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
There shouldnt be anything preventing gameobject instance deletion.
Script on [Pause] gets deleted. Canvas doesnt have any of my scripts
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
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
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
thanks fixed
(just in case it wasn't this) you can use EscapePress directly instead of wrapping it in a lambda
im trying to give players access to customise all inputs in the game
....ok
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
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
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
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?
yes if you want to mutate data from a scriptable object, you should copy it first and mutate that instead. If you're doing this for a lot of values, you should make a class which contains that SO to make it easier
are return/Physics/Vector3 supposed to be colored like that?
or have you actually just.. not configured your ide in all this time
at that point why not just dupe the so? 😛
🤷♂️ why clone it
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
Sounds to me like you want to use events here, yeah
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
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
What events do you need apart from something like Action<HitInfo> HitHappened?
scriptableobject singleton time
I already have an event like this, the question is how do I subscribe to it.
Like if barrels and crates and slimes and everything that has HP fires this event, the damagenumbermanager would need to know about all of those so it can listen to the event
Events can be static?
yes
That unlocks a lot in my brain at once
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
The objects would just invoke the event when they take damage, or you can invoke it from your damage system
(Latter better ofc)
yes, but how would the damagenumbermanager be listening to them
this also has the benefit of potentially simplifying your logic that applies damage if you don't already have it set up like this
I could have two events then really. One "AnyDamageHappened" event and one localized for that object.
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
And because it's a static event I don't need any instance of an HP/Damage component to subscribe to it
correct
That makes sense
I'll try that, thanks!
Also about to rewrite every god object to use that pattern instead
please be careful, static is not a magic ticket to make things easier
Some things should be member variables always. Also a "god" object can be somewhat avoided depending on design and hierachy of your systems
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!
what does it do?
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
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.
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
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
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?
thats just me trying to communicate "flow" not events
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
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
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
//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
Yeah but the issue is the same here. What calls "OnEnemySpawned"
This now requires a reference to the levelmanager, right?
And a player
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
That's kind of a design question, but both are equally common.
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?
the order only matters if theres addition done between
True
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
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.
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
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
I think there'll be quite a lot
Instead of adding / removing buffs from a base damage number, make a list of buffs and then tally them up when changes happen
So you have List<Buffs>, and just add all the buff.amount's together before applying it to damage
theres nothing different about it. No matter what you do, you should always be grouping and summing all additive + multiplicative buffs and applying them at once
Your math isn't how the game should actually calculate it. The real calculation you're asking here is 20 + 10 + 40 = 70% (1.7 final multiplier) or 1.2 * 1.1 * 1.4 = 1.848 final multiplier
additive for example would mean you have a +1. Multiplicative means *1.4
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.
Maybe a "level" has many things that spawn enemies or maybe just one thing. Hopefully you know the answer and know then how this connection works. The point is to either use new events to expose inner events or provide access to inner objects/managers/lists/whatever
it is correct, i used a calculator
yeah I realized right after send 😭 dunno what I was thinking
but yes thank you everyone
I do, my goal was to avoid having all those connections. I'm trying to get rid of them
Is there a good reason for this? one magic leap via a static event is a big assumption that is usually deemed poor design.
Though tbh id say go for it if this is not a big project for many people to work in
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
What i describe allows for this too but i guess that isnt getting through
anyway mull over it or not
In your example the damagenumbermanager seems to reference the levelmanager, so it would at least need that, no?
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
The enemies immediately barking about wanting to contact the damagenumbermanager and all kinds of other stuff was really annoying to work with
Yes. If it needed to be more general then some base class/interface would be used instead of "level manager"
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
A multiplicative buff is a buff that adds multiplicative to whatever buffs are already there.
So 50% + 20% additively is +70%
50% + 20% multiplicatively is 1.5*1.2
the 70% is a multiplicative increase. It doesn't matter that numbers are being added to get there
No, that is called "additive"
increasing something by 70% is multiplication
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
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
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.
That is called a flat buff. You can have a +50% additive buff
This is additive yes
the only thing id be wary of is using an int for the final stat here
foreach(AttackMultiplier am in multiplierList){
ourMultiplier += am;
}
If you switch this to a *= it's multiplicative
why?
you can display everything cleanly as ints in the UI but you're losing out on accuracy if keeping everything as ints
ah ok that makes sense
a 49% increase to 1 damage is still 1 damage if you use ints
gotcha, thank you
0.2*0.1*0.4 is not going to give the correct numbers there
It gives correct numbers for a multiplicative system
its been awhile since ive played games which use these kind of systems but yea i do remember these terms. I was thinking more from a mathematical standpoint
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
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?
screenshot
its just a blank camera, the capsule is probably not infront of the camera
its 2d
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
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)
okay
you should keep the GameView and SceneView tabs side by side its easier to see
i just started all i know how to do is add a object and add gravity thats it
okay
should go through the unity courses
it works now somehow
btw unless code related correct channel for this type of question goes in #💻┃unity-talk
cause now its infront
so unity talk is for visuals?
its general questions about unity
this is more like scene navigation / usage than visuals
btw check out 👇
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
is there a turtorial for top down kinda 2d like the binding of issac?
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
okay
check pins there are also c# courses, I'd start there if you don't have any c# exp
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
thats what its there for
btw new input system has events so you don't have to use update
wdym?
which part
oh uhh input system events for update?
if you never worked with events you should probably learn those first, otherwise is just confusing.
think of it like a method that runs when something happens, like a button pressed etc.
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
oh i know what events are, i just didnt know there was one for mouse movement
ill look into that, thanks
How expensive is GetComponent?
compared to if, very
compared to a recursive file lookup, not at all
everything is relative
you shouldn't worry about the specifics really
Yeah, I might be going down a really dumb rabbit hole lol.
just don't use it in update like every frame and you're fine..
https://hastebin.ianhon.com/d8d1
whys this movement not working TvT
a pastebin that will never expire. forever.
Move should only be called once per frame
gotta be more specific than "not working" though
like it doesnt move when i press play but also doesnt give me any errors
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
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
what's the issue exactly? are those 20 tiles suddenly turning into the whole map or something
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

how am it supposed to slice this asset
ok
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
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.
like rename my assets based on the data i assign to that SO
have you tried just changing .name? might not work it's been a second since i've messed with it
yeah i tried it tries to compare something and gives me an error only working way i found is this
I think the right way to do this is with an Asset Postprocessor
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
hey all!
can anyone tell me if it will actually help with performance to call System.GC.Collect() during loading screens?
ok using OnValidate in parent scriptableobject did the trick, still weird though
Post code + unity version
You want Range
I don't think Min has ever done anything in the inspector
range is only if I want to clamp to max as well though
make a really large max
The attribute only affects inspector usage, if it initialised at 0 it wouldn’t clamp it iirc
e.g. float.MaxValue
Online says it should work
probably not
it was in inspector tho and I tried getting the list to 0 and then repopulating
I've definitely used it before but my set up is probably like an edge case of an edge case
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
I know how to paste code, just showing why my set up is weird
nothing weird here
Semi unrelated: highly recommended serialized dictionaries for weight based stuff, works pretty nicely imo https://assetstore.unity.com/packages/tools/utilities/serialized-dictionary-243052?srsltid=AfmBOorl8TU_shqPjDfqs6AdhLZN7bTOYtr6QmM2vYEaWKbhY1mdJTXt
thanks, I'll definitely check it out!
thank you, i figured as much
back to looking for more ways to optimize gc

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
Is it actually creating an issue for you to optimize it?
You never need to call it manually . . .
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
Where/how do you see it?
profiler?
The profiler should be able to tell you what scripts and methods its coming from, no?
unless your semi manually handling gc stuff (silk song does this)
Because you might be optimizing in the wrong direction?
in what other direction could i be looking?
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
kind of too far gone to begin fixing now
yet here you are trying to fix it indirectly
What you describe sounds like a memory leak and is not directly related to garbage (collection).
Use the memory profiler. Make a few captures throughout the game and diff them to see what increased memory consumption.
I get that you are trying to make a point, doesn't change my situation though
it's what i've been doing, I don't exactly know what i'm supposed to look out for, though. But thanks!
If you know this part (pooling) is a problem, I would fix this first, then check to see how much it improves the memory issue
That way, you can pinpoint and focus on the next issue . . .
Any idea how I could determine how much of a problem it actually is? Stuff I should look at in profiling?
managed language for ya
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?
probably lower the weights in the RIG
assuming by "Setup IK" you mean the animationn rigging package
that didnt help
yes
weird
you probably set it up wrong in the first place
try lowering the weight on the IK component itself
they should all link to Rig builder though
wtf it still didnt work
this is so weird
i even have Foot IK disabled on the animator
which IK components are you using exactly ?
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
which version are you using ? I wonder if it could be a bug
6000.0.67f1
have you tried disabling the TwoBone IK entirely ? does it restore the animation
let me try that
nope
the only things that move are the arms
its really strange
well the arms are stuck in a pose
they just rotate
was it working before you added RIG/IK to it
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🥲
this would be a #🖱️┃input-system question
just poll it
copy 🫡
they have an event listener..
copy ^2
or just assign the ReadValue result to a variable that you then pass to the Move call each frame in Update
oh that's playerMovement, i read it as playerControls
but yeah there's several ways to go about this
I did the caraible method thanks my gs ❤️
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)
That's what interfaces are for
right, i forgot about those even though i'm using one of them. thanks
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
Other solutions besides interfaces:
- Events/delegates
- Abstract classes/methods
You can cheat and serialise a MonoBehaviour or Component reference and cast at runtime. Best used with a validation however
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)
English-only server
who told you this ?
I've been here for a while and I know..
Mod also says so below the message you replied or you just blindly skipped seeing that? #💻┃code-beginner message
idc
حمار
الزبده يا اخوان في عربي ولا
<@&502884371011731486>
idc you know
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
when you load the scene, thats whats loaded in not all 5 load
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
Ok so the performance is based on the first scene INITIALLY, right?
Performance is based on whatever scene is currently loaded.
you open a scene, it loads whats in it.. simple as that
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
I'm not sure how to parse these questions... 😅
thats more a design thing, not performance.
make it easier on yourself and make each one a scene
Okok ty guys, sorry if questions seems dumb but im on early-developement 🙂
its fine to ask, no need to overthink performance stuff . just make things
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.
I've seen lots of creativity flows get interrupted by over fixating on the minor details, micro optimizations w not much benefit
Ok ty again
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.
i'm not 100% sure what you're asking here. are you asking how you access the Z axis of the rotation in code?
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
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
Ah its hard to describe in text I guess. But like uh, will a picture work?
unlikely, but you can try 🤷♂️
the disconnect here seems to be your utter lack of understanding of how components and your code work
Yeah 😅 go easy on me, its my first rodeo like I said
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
anyone know whats wrong with the code?
!ide 👇 use a real IDE to code, not notepad++
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
For starters, it's in notepad.
when i open it it opens a notepad
thats what it opens automaticaly
Follow the ide config above.
which ones the one you use?
Vs code. But I'd recommend to start with vs as a beginner.
which ones easyier long term
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?
bc if i pick one im not swapping
start with visual studio which should have been installed along with unity by default
okay so how do i even get it to open with that
what
look at the bot message
Kinda? I wanted to tie it to a parameter so I could call it and use it in an if statement because I couldn't make a script that works without doing so
Use Visual studio. It's easier long term. Once you get experienced enough, switching is not gonna be an issue.
wdym what? i linked to a message that has relevant links for the configuration
okay thanks
so you want to compare the objects rotation to some property in an if statement?
"tie it to a parameter" is a nonsense phrase. you appear to want to get the input to store in a variable like you are doing for the horizontal and vertical axes that you use for movement. take a look at the Input Manager settings in your project settings to see what axes are already set up that you might be able to use for this
downloading it
yeah, so the car can rotate itself back upright if it detects that its close to flipped over
follow the ide set up guide linked above and you should be good to go
you should really lead with this next time because you said a bunch of stuff that is entirely unrelated to that concept
i still dont see how input is related 🧐
Im sorry, I tried to explain it in a way that made sense to me... im really bad at this...
I really didn't know what I was looking for
for future reference: https://xyproblem.info
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
is that why the car jitters when trying to rotate itself back? It also only stops at the value I set the if statement to like (if x <= 0.2f) then it just flips until 0.25...
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
yeah I figured that out last night 😅 but i any higher was too strict of a requirement...
youre missing the point
oh, sorry...
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'
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
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
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...
youre not really wasting anyones time
thats the point of this channel and server
knowledge is never a waste of time
I feel like I pissed off boxfriend kinda, I guess I did kinda sound like a know it all earlier 😅
are you still a game developer if all your codes copy pasted
mow whats wring with it
what does the error message say
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
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
could someone copy paste the code for movement maybe?
there are hundreds of tutorials for movement, pick one and follow it. we don't do code handouts here
okay
how do i find one for the top down veiw type of movement
nvm
found a 3 minute one
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
what does this error message mean
!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.
this happened when I did that. The character has disappeared.
Do you know what the issue is that caused this and how to fix it?
what is URP
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
I just created it today
So what used to be here instead of (Script)?
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
nothing
Changing the input handling does not (should not) affect the rendering in any way
should I change it back then?
Why does it say MC
that is what I titled the script
But you just said there was nothing
I thought you said what was there before I added the scipt, that is the name of the script, that is the script
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
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
Send a screenshot of a unity script open in VS code first (don't crop it)
Does this help?
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
Follow those steps^
More help here
https://unity.huh.how/ide-configuration/visual-studio-code
okay
I am following the steps, when it says Set up Unity
Update the Visual Studio Package, I am not sure what to do. It says on Unity go to windows, then packages, but I don't see them. I am on Unity Hub though, what is the difference between Unity and Unity Hub?
Unity hub and unity editor are separate. You use the hub to open your projects and install different unity editor versions
Open your project and find the package manager in the unity editor
thanks. Makes sense
ayo does anyone know when the next unity asset sale is? and if hot reload is worth it?
Documentation says FindObjectsByType<>() return Objects[] but when I try to assign it to the GameObject this happens
Why?
Enemy is not GameObject
at the beginning of your foreach you should have Enemy not GameObject
you're trying to find a script
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?
Objects aren't always neccasarily GameObjects
I need to access the transform of objects with the enemy script
Ooh
you can access .transform on any MonoBehaviour
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
This seems like a major sidetracke from the fact they just are using the wrong type in that loop
xD
that's already been pointed out
Understood, thanks!
no worries man
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?
not sure what you mean by "count them all as enemy"
the enemy there is just the name of the variable used in the loop
Can Shader Graph can replace a Fake Shadow from prefab?
FindObjectsByType block create list and we are assign every objects in the list to the enemy variable?
it means for every enemy found do something
Heh
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
But the enemies die and when they all die, they respawn, how else can I update the list constantly?
C# events
Ohh I have to deep dive to the events got it
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);
}
}
}```
what
right now this only works with one coin, i cant drag all coins in there
make an array or a list
[SerializeField] GameObject[] coinObject; for an array
i think i see what you mean
no this script is attatched to the player and it checks if the player collides with the coin object
you can directly destroy the coinObject without needing a class reference
but I can only put one object in the serialize field
that worked! now I feel dumb 😭 how could I know theres something like that 🙃
for the future you can also access scripts and components inside that other.
other.GetComponent<Transform>(); for example
what you have to understand with OnTriggerEnter is that you already did that without noticing
you're checking if other (the object you're colliding with) has a tag of "Coin"
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
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
this did work but what you're doing is destroying the Collider inside the gameObject
when you do Destroy(other.gameObject) you're destroying the object itself, not the component
ah so I can destroy single components on that object like animation, rigidbody and so on?
yup you get it
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?
i think it is, it won't print null, just none, u can't see the object even object is spawned i guess
It is indeed fine as long as you don't try to access it while it's still null.
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;
}
}```
If you get an NRE error, you need to reconsider stuff. If not, you're fine. This isn't to do with some sort of "best practice" but rather explicitness.
In order to not leave it empty I add the game over panel object as a prefab so that I can assign it in the title scene
I think I did right no?
because like I said my game over panel object lives only in the main scene
I would avoid mixing instantiated objects with prefabs to avoid accidentally doing stuff with a prefab instance.
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
I just said this isn't a best practice concern but explicitness..
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.
so whatever it is
I just wanted to know
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?
"no more flat"??
Who "they"?
Maybe explain what you're trying to do first.
Because its still not clear.
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
If you look closer this screenshot applies a tint based on the depth of the layer. Lower layers seem darker.
How can i do that
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.
I used default material,it called sprite-lit-default
And it all the same
So idk
Ill see it
Hey guys any good tutorials on YouTube I’m very new to unity
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
youtube has a search bar
And you unity learn is better than 90% of youtube tutorials 
i mean, that's just because there are a lot of bad tutorials on youtube
Why YouTube specifically
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
what version control software are you using?
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
idk one of the other 500? https://git-scm.com/tools/guis
close all software that might access the project, then try again
(vscode, unity, ...)
Github isn't software
that's a service, not vcs
the underlying vcs is git
you're also using github desktop in that screenshot
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
well with those options, you're crazy
you can
yeah you can
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)
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 🤔
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
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
(unless one object has multiple of that script and you want the 2nd one)
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
yep, that's it, thanks
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
You know what, fair. Hadn't thought of that.
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
you can have multiple inspector windows
Why
yeah then make that a specific class, not MonoBehaviour
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 😄
What benefit could you possibly have for making an array of monobehaviours
it's because different prefabs with the same script will need to have different behaviours disabled at a certain time
depending on the prefab
Yeah then just do {className}[]
instead of MonoBehaviour[]
oh wait different behaviours?
This sounds like you should just have different prefabs
this sounds like something you could make more specific/streamlined with the right abstraction+constraints
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[]
you could have it be public bool enabled { get; set; } so monobehaviors would already implement it, probably
mhh fair
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"
Event based pattern comes to mind here, but the way they are trying to do stuff is exactly what I tried in the beginning 😄 part of the process until they learn there is a better pattern
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
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 😄
that's a great response, thank you
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
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.
Not sure what there is to struggle with. They're basically the same concepts.
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?
Honestly not sure. Something about Unity's own documentation just didn't click for me.
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
What does the gameobject look like
Ive seen a similar issue when rotating a parent object, the child objects would "Orbit" if they were not positioned centered where parent is
StarBox - parent with the script
Star - Child with the meshes
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
Is the transform for the Star object at 0, 0, 0 ?
yes
Get all targets in a certain radius(dot product or angle checks), then find the closest one.
Homing radius/range.
lets say it's infinite
Share your code
Then just get all targets in the scene and find the closest.
"If I just aim for the closest one that won't do the trick, homing backwards is not great"
not really
it's easier to hit target ahead but not behind
the point is to get a target which the most reachable
Then it's not infinite.
...no?
is this not directional?
Guys I cant figure out what to do
you should have UserSettings in your .gitignore
did you set up the .gitignore correctly to begin with?
So you want an aglorithm to find an optimal target. Then you need to specify these optimal conditions. Like:
- a function of minimum dot product and distance.
Resolve your merge conflicts, either manually, or by checking out whichever branch's version of this file you actually want
That's my gir ignore
@real thunder is this what you have in mind
where'd you get this from
that's missing UserSettings as mentioned
you should generally be basing the .gitignore on this
https://github.com/github/gitignore/blob/main/Unity.gitignore
yeah that I figured, what I haven't figured is how exactly it should look like
probably in ideal case that meant to be some formula including rocket speed, homing capacity, distance to target, angle to target
but I won't mind something simplier yet bit more complex than just "closest one but filtering out thigns behind"
yeah in this case aiming for closest is not ideal
do those "lfs settings" even work in .gitignore
ok, then you have to figure out how to determine "distance" in a way that "closest" represents something more meaningful to your specific situation
yes lfs is working
I have used AI to tell you
And copy pasted the git ignore
It sounds like you can't decide on what these conditions should be. We can't really help with that. It's a design question and is entirely up to you and your project.
Not a technical question.
Ok now I got very confused because I am confused XD
and yeah this lfs config does not work. that stuff needs to be in .gitattributes, not .gitignore
ok, let me summarize.
- you used AI to generate this.
- you don't understand how to actually use it.
- it's now broken, because you tried to use a hammer on a screw
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.
Why would you use AI to generate a gitignore for Unity when Github literally lets you pick Unity from the dropdown when making the repository
https://github.com/github/gitignore/blob/main/Unity.gitignore
A collection of useful .gitignore templates. Contribute to github/gitignore development by creating an account on GitHub.
how what looks?
It's fucking built in
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.
kinda sounds like you're just describing polymorphism?
Like, what's the point in that if they share same name, values and functions?
If they share the same name, values, and functions, you should just use the one asset for both
you would more likely have multiple BaseItems (probably(?) mostly through subclasses), rather than multiple Vampires
Yeah, but I thought maybe there is any Unity-way solution. Of course I can create several sub classes to "BaseItem" and change their logic.
Polymorphism is the "Unity-way solution"
why would unity have a separate, different version of a core OOP concept
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
I knew it from the start and meant by saying adding penalty to a distance
I thought this scenario is common enough so someone can tip me an algorithm but it seems like instead of saving time on that I ve wasted several people's time a bit 🙁
I think I just confused myself, gotta make it simple
you could probably add a multiplicative penalty (maybe curved like 0-60 has 1-1.2 then 60-180 has 1.5-8, that kind of idea) with regards to angle difference
thanks everyone, gonna change that and maybe ask again
This seems like a specific enough situation since you'd need to factor in things like turn radius and acceleration, I don't think you'll find a bespoke algorithm for this. You could just come up with some equations to compute how long it'd take to reach something based on your own parameters and then just run that function on every possible target. Not sure you can get faster than that
you could have multiple instances of like, HealingItem extends BaseItem if they had the same behavior with different amounts or sprites, for example
but for different behavior, you would have different classes
Ye, I am about to make several classes
Now I just need to figure out a fance way to set Name, Description and Sprite for each class
you already have serialized fields
oh right, calculate the trajectory and it's length, that would make most technical sense
you probably don't need name either really, could just use the name of the SO itself
I am not deep into C#, what is SO?
Hey! What I am supposed to do now?? I am going to die or something?
Because I really think I have to die
wtf are you talking about
I am changing stuff already
I did some shit
No one wants to help someone saying this
and you expect me to just psychically know?
Maybe to create a new repo and set it up from scratch again
why are you even here when you don't read anything anyone tells you
get user settings, project settings and Assets files and do this?
sorry, didnt noticed discord, i fixed it thanks anyway
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
You should probably just drag in the sprite you want
but that's a script
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
Here, you've got a Vamprite object. Assign the values there
You're creating these SOs in the editor, you shouldn't have a Constructor
You're not creating them in code
there is no need to have a subclass here. These are just fields you should be setting in the inspector on the SO instance
Assuming there's going to eventually be code in those functions for every item, it'd probably need to be a subclass
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?
I would find a different way to dispatch the behavior. This will be unwieldy to manage, IMHO.
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
i mean you don't have to, but that is the intended workflow SO's were built for / Unity tbh
mmmmm, tough for me to understand but ok, gonna keep it that way then
So, I am close to merge my feature branch to develop branch.
Just wipe out your entire hallucinated gitignore and replace it with the one I linked above
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
And then do this:
https://stackoverflow.com/questions/19663093/apply-gitignore-on-an-existing-repository-already-tracking-large-number-of-file
how do I get SO name in script?
.name, it's just a field/prop
ah, yeah, GameObject
Unity.Object*
🥀
Hey! I have solved the merge conflict. I did what you said. So, what is your advice to me? I really would like to have some advice for the next time.
the best advice you're gonna get: stop using AI
Don't use AI
also read the things we say
also gotta set the lfs stuff in .gitattributes, not .gitignore
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
ah, classic increment blunder :p
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?
no, but I feel like performance would suck this way
There are lots of existing solutions for Minecraft-like 3D terrains using mesh generation, chunking, etc. Could you use that?
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
like I said, mesh generation
each chunk is a mesh or something along those lines?
each chunk is a mesh yes
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
That's why minecraft has a setting for render distance
and why it only simulates chunks you are nearby
sounds suprisingly simple until you watch a video on world record mob farms