#π»βcode-beginner
1 messages Β· Page 696 of 1
yeah docs have been kind of helpful but my adhd brain cant handle the big words lol
blueprints in ue5 are life changing
you can use bolt in unity
didn't they change the name back to just visual scripting?
yeah i guess
wrong language lol
honestly its probably best I learn c# and c++ respectively, looks good on the resume
or CV whatever people call it
auto links me there, sorry π
Question, how would you programmers do a non-hardcoded inventory system?
For example, not having a enum of all items that exist (So you don't have to modify it every time).
I've been trying to use ScriptableObjects, which have been pretty useful all things considered, but I'm wondering if the use of C# interfaces would be useful in this situation as well - in addition to the use of ScriptableObjects. This is due to the fact that they would help with customizeable behavior and instance data.
yeah define each item as a scriptable object as base item definitions and everything else that is mutable like amount or any item attributes in extra properties of your item class
also give each item a unique identifier, might be auto generated uuid or your own string
Could you elaborate on this? The message isn't fully clear on my mind.
Just a classic ID identifier that games like Terraria have, I imagine.
you create a scriptable object for each item that holds data like icon, name, price, weight, whatever you need as base data for an item, also add a unique ID to that set of settings
then you can create a class "Item"
that can hold data like amount for example that can change during gameplay and the ID of the item so you know which scriptable object to access for your base item data
that item can then be used to represenent a slot in an inventory, to drop an item or whatever to pull the info from it
not sure i would do exactly as terraria since their ID is the number order of implementation and i could get easy to lose track of the number you are on if you add a lot
Of course, no doubt about that, Terraria's implementation is very crude, but I wanted to make a quick analogy.
a common approach for that is just a long enum so you have a string representation in the code, for low item counts thats totally fine
And that Item class you mention, which is composed by that ItemData ScriptableObject, would be a MonoBehavior or not?
My intuition is no.
i once did it (copying the idea from another...) with a .tsv file π but it's a bit rough...
SOs are good because you can easily combine all data there (unique id, icon, name, enum for like type maybe)
and don't have to rely on finding for example the icon in the files via Resource or having a List or whatever...
otherwise could also do something like
BaseItem -> Weapon -> Melee
BaseItem -> Weapon -> Ranged
BaseItem -> Clothing -> Armor or Cosmetics
For the generic c# class and/or the SOs to make it more specific and have special values
No i would call it ItemData and have it be a property on your monobehaviour as you will have different representations depending on where your item is (on the ground, inventory) most likely
That's crazy lol.
or you even have an itemmanager and only pull item data from there instead of saving the reference to the whole item in a monobehaviour
I use the items name as its id. In 90% of (my specific) cases, the name is unique
i basically do the same for saving data for a skill tree in my game
So a MonoBehavior called WorldItem, for example. This would have this Item class as a property, and then all behavior happens in the MonoBehavior as it should. Is this correct?
Which part of the inventory? Do you mean setting up the slots, accessing the item within the slot, or storing the items in a collection (array, list, dict)?
yeah, i would even just give it the ID of the item as a property and save all items in an ItemManager and pull the info you need from there
Good question. I meant more on the side of item code infrastructure, which on hindsight perhaps it isn't that related to inventory.
but theres a lot of different architectures you can use for that, no solution is more right than another π
As they mentioned above, there are different solutions. There is no one way . . .
I do not question that, for sure.
I'm just in the pursuit of one that is good enough that doesn't make me regret it on the future.
and I think item systems are rather easy to find a written or video guide for, look through some and pick an approach you like
if your approach starts by having the base item data in Scriptable objects you are on a good path
That does give me a sign of relief.
For the last inventory I created, I stored the item ID in slots with their amount. The ID was used to lookup the actual SO_Item within a dictionary via a static method call from SO_ItemDatabase. All the SO_Item's were stored in a list within the SO_ItemDatabase class. The list was used to create the dictionary during runtime . . .
Hm. A dictionary created during runtime does sound like a good idea, I will take note of that.
^ that only works if your only mutable data is the amount though, if you have other parameters on your items like durability remaining for example you need a more complex approach (like a class holding more data)
fwiw, what everyone above is trying to explain to you is derived from the concept of a type object (which in unity often is a Scriptable Object): https://gameprogrammingpatterns.com/type-object.html
As long as you have a unique id for items that can be used both ends you will be good
Yes, this is for a simple item inventory. If you can have different versions of the same item, then you need a more complex approach . . .
That is indeed why I mentioned the use of C# interfaces, for that part that is mutable, instance data.
an inventory is really just a container for meta-data associated with an instance of an identity token.
I will have to take a good read at this later. Thanks for the link.
Could you elaborate on this?
not wrong, its any data that you need to store about some item (e.g. quantity, extra meta data)
it does help if you have many item types to seperate them out
e.g. weapon data, food data
For two of the same item with different stats, I just use a C# Item class holding a reference to the item ID, along with Rarity, ItemAttribute[] (stats) and other fields that are mutable to the specific instance . . .
Is there a better way to do this? Kinda feel like this could get out of hand the more I add
And it's not great for having other weapons
Well, are all of these objects really needed?
It sounds like half of them are redundant
If i dont do that then they just override each other
What application do you use to open C# script...??
!ide
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
one of these (click the links to get a guide)
thank you..
i'm trying to code an C# but when ever i put [selectionbase] on vscode it does not appear..
what should i do..??
"it doesn't appear"
I'm not sure what you mean
like this box from vscode
thats not vscode

thats visual studio
Yea it's not but vscode does have it too
if they did it in VSC and did not appear, its probably not configured
π 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.
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
click the VSCode link if you use that @vestal cloud
https://unity.huh.how/ide-configuration/visual-studio-code
this ones better, also has troubleshooting steps
If your IDE isn't providing autocomplete suggestions or underlining errors in red, then it needs to be configured.
the steps tell u it is lol
yes vsc has weird issue where it doesnt install the required .net sdk 98% of the time
worked on my machine β’ (lucky)
yes π 
i'm new to coding... will my brain going to explode when something is not working?
Definitely but we can repair it as long as you try your best to learn π
btw why SelectionBase? I never heard of that before π
i do not know π , i'm following tutorial from the video
which tutorial?
moving a character in 2d
unity has !learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
i suggest trying these
yeah you should start with the basics before anything
i think i skipped like steps 1 - 5 then :/
example of this is i just learnt what putting [System.Serializable] before a object class does :/
pretty sure that's outside of the scope of steps 1 to 5
fair
not sure if working on 3 different game types at the same time is helping or not
how do i make a raycast not hit the raycaster
we'll see u in a year after u recovered from the burnout π
hey i already went through that like a month ago i'll be fine for like 5 months until the next wave
i usually use a layermask
otherwise you could do a line cast and sort out the one's you don't want π
or i guess make the cast come just at the outside of your collider
is there a place here for npc 2d ai?
the what?
i should say im using navmesh paired with a 2d asset port for it but they kinda stupid and just chase me
navmesh is 3d though? 
could've just said A* lol researched that for a short while
not here lol
well free but it uses the unity navmesh
does A* need a baked map?
it's on git or asset store?
the layermask isnt working
i dont recall :/ got it ages ago
well did you set the layermask to everything else but your player's layer?
yes lol
ah ok... did it maybe break with newer unity?
nvm found it https://github.com/h8man/NavMeshPlus
only ever used unity 6 so no?
then you figure out what's not working and then why... add debug logs as many as you need
its hitting the player :/
oh you said ages ago thats why
said ages ago cause 8 months is ages for me :?
RaycastHit2D hit = Physics2D.Raycast(transform.position, _moveDir * 2.5f, whatIsMoveable);
this is it right?
show code, where you set the layermask what layer the player is on best is a full editor screen
whatIsMoveable is the layermask
layermask should be everything besides the object layermask you are trying to avoid no?
layermask = what should be included in the cast
that doesn't say a lot
ok give me a sec
that's like saying this variable named xhaba3729 is the layermask
just tryna make sure ive structured it properly
i have no clue where you set it
ive checked the docs and that what it says
you could as i said debug log everything including the layermask before that call
but probably you made it public and set in inspector?
yeah
welp they have a unity forum post
or you use github issues
the problem i'm experiencing btw not that it's not working but they are stupid
they're shooting or not
they are
hmm yea then you'll have to play around with their ai
idk how you set their position
90% of their ai is this :/
but maybe take playerpos+ velocity into account instead of just playerpos
yea not gonna get epic results with that lol
:o didn't even think of that
now is your creative time
how would i go about adding the velocity?

how would i even get the velocity?
from the players rigidbody or whatever you use to move it
for a simple kamikaze enemy
you can take the player velocity as a vector then guesstimate where it can hit the player with it's speed
simple trigonometry (probably)
are you saying i can get the velocity by doing the opposite of setting it? ie
Vector2 Velocity = rb.linearVelocity;
yea why not
well no i was saying that cause i didn't know i could do that
this actually worked they got annoying
just added the velocity on top of position?
yeah
are there seriously no voice channels
maybe even more annoying if you multiply velocity by random(1,10) and then add it
Not that kinda server
yeah it just helps a lot lol
gonna try it
you could even calculate the exact position where the enemy is able to collide with the player based on player's current velocity, enemy's max speed and both their positions...
ok can someone help me i cant upload videos and i cbf taking 20 screenshots? we'd have to take it to dms
that sounds like too much math π
well more or less dunno about physics holding up exactly
ye but could be fun challenge
to code it (idk if it's fun to play against)
tweaked the bullet speed and it somehow got really annoying
almost at the bullet hell
just post the !code and inspector of this code where you put it(probably player)
π 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.
just gotta add like 150 enemies on the scene then i'll be there
though im curious a really annoying thing is getting nocked back from the bullets, do most bullet hells have nockback when you run into enemies?
cause it kinda just stuns you and you end up dead
not really
could always just use a trigger 
was just about to do that
nono
no?
oh well it would've just been checking the is trigger tag on the 7 weapons
although I'm not sure it works like i think rn
yeah probably better
kinda they deal damage but dont explode :/
A tool for sharing your source code with the world!
Hello on awake im adding listener to buttons. I would like to add 4 second to delay before action happens to all of them without having to create multiple coroutines.
don't have to repost that quickly
mb bro sorry
hover over the raycast method and look at it's parameters
where would you like the delay? also use async / await its easier
or ctrl+click on the raycast method (idk if that's how you go to the method definition)
right before " Loader.LoadLevelx(Loader.Scene.Levelx); "
Invoke("MethodName", 4);
i looked at the official docs and it said that layermask was next then distance, but its the other way round.
sorry. thanks
yea i had this happen too sometime and no fkn idea for a long time lol
ok i know they don't like when i give answers but put async before the void of this function and await Task.Delay(4000);
thanks lol i appreciate ti
Don't mess with the void. If you look into the void, the void will look at you.
basic example
Point is, you can't use the word "void" in that context. It just means lack of return type.
isn't that blocking whole unity for 4 seconds though?
i love the void
that's what the async is for
at least i dont think so i use it quite a bit and my game doesnt freeze till it's done
alright thx
yeah what i thought it's like putting it off to the side till it's delay is done
then it's called back to it
but if you had something after the SomethingToDo(); call it'll do that while waiting the 4 seconds
this is happening within the awake and not another void. is there no way to delay it within the AddListener
could you share a proper !code cause there wasn't much that i got to see
π 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.
but won't this be an issue when trying to access any unity stuff? since it's not on the mainthread anymore ... right?
you have to put your other calls inside a new method which you call using Invoke
Invoke kinda sucks since async and coroutines are almost constantly better and doing things via strings is icky
why are we using Invoke that's not what i said
@sour fulcrum
Nah
Nah?
it doesn't leave the mainthread
it aint jobs
Coroutines for one are fake async and never leave mainthread and async stuff is almost always thread safe(?) afaik?
unless you are updating say a Dictionary and accessing it after but using a async between updates
nah or afaik(?) which one?
Nah, afaik
... source?
i mean i can go google but as far as I know kinda puts myself as the source aha
sounds like someone could use async for
that is my understanding
load data in background type
Sounds like they just need a single coroutine that takes in a time and a level value though, no?
it doesn't work like jobs though it's all on the main thread it just tells the main thread to do something else (in the case of await Task.Delay(); ) until that delay is do then the main thread goes back to it
all it does is just pasue a task and go back to it later lol
did you read up on it :?
yea a little but probably not enough
fair all i did with it was watch a youtube video :/
Hey, do I have an event call that I don't know of when changing the resolution?
Like I want a bunch of stuff to recalculate if the resoilution changes
i dont think there is one but its pretty trivial to make yourself using Update.
I mean yeah, I could, but I don't want to be each frame checking if the resolution changed when the class doesn't even use an Update method
Seems like something that would come by default for stuff like the UI Layouts
not sure why you dont want to, but this isnt gonna be a performance difference in the slightest
apparently this is a thing, though never seen anyone talk about it before
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/WSA.WindowSizeChanged.html
maybe you can use OnRectTransformDimensionsChange() too
i never understood lambda expressions
why do they work there?
like in the () of a method
are they one of those things that once you pick up and understand, you'll use it a lot?
Not necessarily, you dont need them in a lot of cases but sometimes its just easier to write stuff as a lambda expression. Sometimes it makes readability worse.
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-expressions
Its a lot easier to understand when you write a few examples yourself. The () is just 0 parameters
Mmmm, so where does this come from? Like what class I am subscribing for that?
usually lambda is done just for shorthanding, but here there's quite a difference in creating a delegate (some function pointer) and doing it like this as you don't have the reference to cache if you want to unsubscribe the listener directly
Honestly i just saw this on Google for the first time when trying to find the docs for OnRectTransformDimensionsChange. I have absolutely no clue where this event comes from or if it does what you want. The link says WSA so maybe thats a class? Not on pc so cant check atm
incorrect, async/await in c# will always be on threadPool thread, but the continuation can be(optionally) on any specific thread.
Note : Unity uses it's own singlethreaded custom SyncContext by default so the continuation will always be on mainthread (this does not apply to Task.Runor task factories).
if you're using plain c# (non unity), the continuation will be default to whatever last threadPool thread used
Right but we're using unity this is the unity discord server not c# silly
still your statement is terribly incorrect
eh as i said I've just watched one video on the topic and read a bit Β―_(γ)_/Β―
aight cool
Not like async / await has 2 threads running at the same time or freezing the whole mainthread until its done which is what i was getting at
if it's blocking then it wouldn't be called async/await.. also they might not what you called thread here, those are threadPool thread in the case of async/await
what does it make easier?
like what piece of code that is easier to read would do the same thing
what can i compare it to
usually people use it for 1 liners or in linq
the link i sent above has an example where they use it in the linq select method
int[] numbers = { 2, 3, 4, 5 };
var squaredNumbers = numbers.Select(x => x * x);
Console.WriteLine(string.Join(" ", squaredNumbers));
okay ill try it out
oh interesting
im assuming x is just itself?
is it like a foreach statement condensed into 1 line?
x is just a parameter, x * x is the return value. the Select method handles looping over every element
its less about what the Select is doing here and more than you can pass in a method written in short form
It can be blocking. Just not necessarily where the async method starts. If the workload is not spread properly over time, it will block when it executes the remainder of the method on the main thread. I think that's what they were trying to say.
They give you convenient syntax and functionality to do functional programming in C# with all the benefits and issues that paradigm has.
I did better than yesterday! (past 2 days i only read at night time)
Today i read it early (4pm) and did more pages!
40/220 more to go~
I am still lazy but atleast its getting better π
Hello guys, I'm currently working on a online game and I created the online system using Photon 2, for now I created 3 scenes: the Character Selector that transits to the Create and Join rooms and then when you joined a room it transits to the Lobby (that I called WaitingRoom)
My ideia is choose your character that is saved on a Hashtable that I called "playerProperties" (the character named: playerProperties["prefab]") and then in the WaitingRoom asign the prefab's name to an already existing static class that has every prefab on it (for ex: PlayerStorage.P1Prefab, PlayerStorage.P2Prefab etc) but this doesn't work on the game. I have 4 spawn points (one for each player) and this spawns for example "PhotonNetwork.Instanciate(PlayerStorage.P1Prefab.name, etc...)" but the game does not spawn that so I think the problem is the WaitingRoom script
https://paste.mod.gg/hgdieealflvc/0
A tool for sharing your source code with the world!
btw the P1Prefab and so on are GameObject variables
i think #1390346492019212368 is the best place for this
I think you probably want to ask in the photon discord if it's a problem you have with photon
ok btw try to format your question and check for grammar.. it's not really easy to read
ohhh! sorry I'll check that too π
How can I stop my character from slipping off sharp edges ? I have a sphere at the bottom that checks for ground, and i've had to increase it's radius beacause when trying to jump on a cube i'd get stuck on the edge and not be able to move if I jumped on it perfectly. Now if I jump directly on the edge I instead slip off of it.
Also if I try to jump while being in contact with the cube's side it slows down my jump.
What collider type are you using?
capsule collider
I think all I have to do to fix this is make it so if the character is grounded to manually set the vertical velocity to 0 so he doesnt slide off
but when typing rb.linearVelocity.y = 0 i get the following error : Cannot modify the return value of 'Rigidbody.linearVelocity' because it is not a variable
Linear velocity is a property and not a field (a method under the hood). The vector 3 returned from the property would be a value-copy and modifying it's y component is invalid.
Copy the vector, modify the copies y component and reassign the vector back to the property.
var velocity = rb.linearVelocity;
velocity.y = 0;
rb.linearVelocity = velocity;```
thanks a lot, i'll try it out
works well thanks, I still have the problem with sliding off sharp edegs tho which probably means that I have to rethink my ground detection
It doesnt completely cover the bottom of the capsule which is probably the issue
Maybe I should use a cube to check instead of a sphere
when the cliff breaks, the player continues to walk and if he moves in the opposite direction from the cliff, he falls into the wall
how can this be fixed
https://paste.ofcode.org/dZBvQnjL4kaawdNX8vGXSt
How can I choose a random bool in a bool array that is false, ignroing any true booleans in it?
why do you need to choose one from an array if you just want false?
do you mean a random index
I have 10 bools that when each are true, all enable a different timer to a specific thing. A handful of these bools are activated at random whenever the player fails, until all are activated, to keep things interesting. I'm trying to make it so that when the player fails, 2 of these bools that aren't already true, become true, and have this recur with each subsequent failure.
Alright then make a function that generates a random int from 0 to the BoolArray.Length (or Count dont remember) and do if (BoolArray[RandomNumber] == false) return BoolArray[RandomNumber]; else call the function again
uhh that sounds like a weird solution, bruteforce rather than logic
Fair, still kinda new not sure of what IndexOf does
Just thought of the easiest way i would do it
it's not inherently bad but i think it's not great in this situation with potentially a small amount of options
Yeah it could have a chance of looping the function dozens of times because too many are true
it may involve several retries, and it doesn't handle the case where there's only 1 or 0 options
Maybe making a new array of only the false values then picking a random of those
might be better to just get all the false indices and choose from those
an array of false values wouldn't be useful, it'd just all be false
I meant what you just said silly
Just different words
values and indices are separate things and you should consider the difference
Right right different words, bully π
bool[] test = {true, true, false, true, true, false, false, false, true, false};
var allFalseIndexes = test.Select((e, i) => (e, i)).Where(e => e.Item1 == false).Select(e => e.Item2);
int choice = Random.Range(0, allFalseIndexes.Count);
test[choice] = true;
that should work
pseudo code as i dont have an IDE on hand π
words mean things. you said something you didn't meant, you used the wrong word, and that's ok
but you gotta acknowledge it and learn otherwise no-one's gonna understand you
-# heyyyy you can't just write unchecked code and call it pseudocode π
i actually never left because i too saw that the loop might get stuck for a while ;v
I'll try and incorporate the pseudo code π
You really dont need linq for this. Just loop through, store the index of all the false values.
Generate a random number between 0 and the length of this new array
-# but i just did 
well linq does exactly that for you π
extra garbage smh
I know what linq does. You dont need it there at all
Linq is not a replacement for a for loop
does Select require me to use a library of sorts? it says bool[] doesnt contain a definition for it
but yeah linq is overkill, doing the select just to get the index seems.. not great
yes, System.Linq
but you can just use a normal loop to get something arguably easier to read
Plus given the problem, (and what they said above) its pretty obvious linq is above their level
Its under System.Linq but really just use a for loop instead
I know im getting close to this but I wanted to ask how can I make it so when entering the green zone it adds the new camera which is a child of the new zone into the list. here is what I got so far. https://paste.ofcode.org/vr8d3PuXW77geiZ6xgsYWV
my first attempt i did try using a for loop, i just didnt know how to pick one of them at random AND ignore any that are already true
you are only missing the .Add() call on your list
List<int> candidates = new(); // ideally a class member to avoid unnecessary garbage - if you do that, make sure to Clear the list as well
for (int i 0...yourBools.Length) {
if yourBools[i] == false
candidates.Add(i);
}
/* get random index from candidates */
```on mobile so skipping some stuff
wdym? sorry I'm a bit confused could you elaborate further?
you already get the camera in the OnTriggerEnter function, now you just need to add it to your list property
so this would make a new list with only the false ones to parse through and select however many? Because the position of each true variable in the bool array is required for me to know which timers I need to start
isn't that why people use this instead? https://github.com/Cysharp/ZLinq
you are adding the index to the new list, not the bool itself
im confused what you mean by that second sentence, i don't see how that relates
candidates is a list of indices
ohhhh
its an int list i didnt see
no clue, haven't heard of it
i don't really use linq in general, i don't particularly like the api
im fine with fp/stream apis in ither langs though, idk why I don't like this one lol
sometimes linq is more convenient but most things can be done "by hand"
doing things like sorting to get the first/last thing however is always dumb and should not be done
would it be like this?
yes that looks good
but when I am in the green zone why does it not add it?
yeah well filling a new list with candidates is the same garbage π
ZLinq is very good, a very practical performance optimization that linq provides is lazy evaluation.
best would be to debug the steps on OnTriggerEnter and figure that out
don't quite understand what lazy evaluation means
Isnt the newer version of Linq also zero alloc? I am not 100% sure if you cant just set the c# version to 10 and have the new zero alloc stuff though
that's why i have the comment to not make a new list
Minimized, non zero
I mean yeah, there are things that linq does which will always use allocs (which even zlinq does not prevent) π
To get linq to be zero allocation you loose the syntax niceness or need source generators
this error shows up on line 49 but it looks okay to me. https://paste.ofcode.org/manUtjVactgBPDNeFAr9YA
basically you have to pass the context into the delegate through a structure to avoid the closure and branch execution on known, indexable collections
thats because it seems you are adding a null object to your list, thats why i said you should debug it
When you do foreach(string id in collection.Select(x => x.id)), the IEnumerator essentially re-executes each "loop" to get the next thing (in this example, to get x.id)
This means that if collection is modified during the for each loop it will alter the results.
sometimes you need to do .ToList() or .ToArray() to evaluate it all at once
It kinda is, the end result of the enumeration is not fully "resolved"
lmao I was missing one word which was "other"
CinemachineCamera addNewCam = other.GetComponentInChildren<CinemachineCamera>();
virtualCameras[1].Priority = 11;
This would mean that virtualCameras[1] is null
huh. what shall I change it to then?
when in the triggerzone its going to add a camera which is [1]
If there is sometimes a 1 and sometimes not, you should check that it exists before you try to use it
When I added a navmeshsurface to this and baked it it would set the walkable paths to the windows and other stuff and not the actually floor itself. I tried adding navmeshmodifiers and it still wouldnt do anything.
and yes I did re-bake it after adding the modifiers
try #π€βai-navigation with more detail, but I'd make sure you're filtering the layers correctly
I added this and it seems to be working, but then it starts messing up and i assume picking the same ones over and over, what do you think the problem is?
{
List<int> goodCameras = new List<int>();
for (int i = 0; i < guy14MalfCameras.Length;i++)
{
if (guy14MalfCameras[i] == false)
{
goodCameras.Add(i);
}
}
for(int i = 0; i < guy14CamerasToFUp; i++)
{
int r = Random.Range(0, goodCameras.Count);
guy14MalfCameras[r] = true;
goodCameras.Remove(r);
}
goodCameras.Clear();
}```
Remove is by value, not by index
you want RemoveAt instead
also there's no reason to clear the list at the end there
you only need it if you cache the list instance like i mentioned
ah dammit, i even looked at it and went nah surely we're looking for the value π
yeah i added the .Clear at the end cuz i was getting desperate and thought maybe it was saving it somehow
i mean, i guess this can get confusing, since there's 2 layers of indices here lol
goodCameras's values are indices of guy14MalfCameras
r is an index of goodCameras
ah that's another issue
you're using r as an index into guy14MalfCameras as well
oh i thought i had to
you need to use goodCameras[r] as the index for guy14MalfCameras
so like this?
{
int r = Random.Range(0, goodCameras.Count);
guy14MalfCameras[goodCameras[r]] = true;
goodCameras.RemoveAt(r);
}```
yeah sounds about right
though make sure to handle cases where guy14CamerasToFuckUp is more than goodCameras.Count
perhaps also add goodCameras.Count > 0 into the condition
oh whoops forgot to censor that
How would I remove the camera that was added?
i didn't even realize it was a different name from the above snippet lmao
Im not sure using tags to control this is a good idea π€
yeah i was going to, thanks for all your help everyone 
what is your setup here? separate areas for adding and removing cameras?
wouldn't you just have to specify which camera to remove in the remover trigger
here is the full script https://paste.ofcode.org/v9Bn34z6yq56jnTS6EHuvs . basically when I enter the green zone it adds the camera thats a child of the green zone into the list so I can use it and now when I enter the red zone I want to remove the camera that was added
the point of lazy evaluation is a) that you trade the allocation of a large collection with for the allocation of an enumerator and b) that you can run code in the lambdas only when the item is actually requested, meaning you can iterate over potentially very large sets of data without any need for this data to actually exist beforehand.
how do you want to handle multiple green/red zones?
If it was me id have a trigger that just enabled a camera on entry and disabled it on exit and let the priority ensure its used when active.
but i get you have some other control to change cameras
(perhaps you can also use trigger enter/exit to add/remove the camera instead of 2 seperate ones?)
wdym? I'm using tags green one = AddNewCam red one = RemoveCam
I am bit confused can you elaborate further?
yeah, and what if there are multiple cameras to add and remove?
they will be destroyed then cause I wouldn't need them anymore when going to the other parts of the level
so each part will only have 1 green and 1 red?
Currently you are checking the tag of some other object your player enters which seems flimsy (tags are a bad idea for this)
It would be better if you had a script on some trigger collider that defines the area for some virtual camera to be usable. It can add its camera to the player on trigger enter, and remove on trigger exit.
just remove the last one added or remove the one at index 1, then
tbh the way your saying I should do it seems like a hassle to setup the way I'm doing it is easier for me and why are tags a bad idea for this?
if anything, the way rob suggested is less hassle
on enter -> enable camera
on exit -> disable camera
Its bad because its set up all jankily and is not easy to expand on in future
it presumes some tags are in use and some other component is a child to work.
hmm, so wait I should have a separate script on the ontrigger colliders and what should be in the script?
The script can have a serialized ref to the camera, it can use OnTriggerEnter + Exit to see if the object has the switch player script/player script. If so, add the camera or remove the camera.
so in my current script I should remove the ontrigger stuff
Yes. instead of the player object doing it, the "camera trigger area" is doing that job instead
the ontrigger stuff on my main script should I copy it and add it to the other one?
is there a way to assign a layer to only one face of a cube for example ? I only want the top face to have the "ground" layer so I dont run into issues where my ground detector collides with the sides and detects them.
Yea but the logic needs changing to do:
- get camera script from trigger enter object
- is it not null?
- call function on that component to add our camera
then the reverse for trigger exit (to remove the camera)
no it needs to be a seperate collider on another game object or you need to check the hit face normal to determine if what you hit is a "floor"
Oh how can I do that, so it only detects faces parallel to the ground (assuming the ground is perfectly flat)
You can do something like check the angle between Vector3.Up and the hit collider face normal. If the angle diff is less than 10 degrees for example we can say it is the floor
https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Vector3.Angle.html
because we expect a floor face to have a normal facing mostly upwards this should work
play around with the angle max though to suit your needs
Using this would make slopes also work like normal since I can determine at which angle it isnt considered as the ground anymore coorect ?
Yea. if you make the allowed angle large it means steeper slopes can be used
alright thanks a lot, i'll play around with this
what camera script? do you mean the main one? camera switcher.
yea what you use to do the camera swapping functionality as I presume that is where you keep your list of usable cameras
I hope you can fill in that gap
when you say get camera script from trigger enter object do you mean when I enter the green trigger zone it adds the playerswitcher script in the reference.
nope
what did you mean then?
I have tried to explain the process a few times
If your "switch player camera" script is not on the player gameobject then instead you should have a serialized ref to that on this new trigger script
The process is still the same, when the player enters, add some camera. when the player leaves, remove some camera.
Should it also have a reference to its own camera?
how else can it add the camera?
my bad lol just clarifying
each instance has a ref to the camera it wants to add/remove
you can set input handling to input manager in your player settings (like the error mentions)
or you can use the new input system
where.. is my player settings..?
now that i think about it.. calling it "player" may be a bit confusing for newbies
Peko peko?!
it was player movement code...

from the tutorial it was outdated... .
I mean the setting being called "Player" which some might think is for the playercharacter but it's for the runtimeplayer
which tutorial? !learn essentials should be pretty new
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
I think it's updated for 6.0 but not 6.1 which changed the default input handling type
Ah that's unfortunate and going to confuse many π
Yeah but there's not really a way to radically change the way input works going forward for the better without causing a ton of confusion
There's like, years of difficult-to-update video tutorial footage using Input.GetAxis and whatnot
True but why didn't they do it in unity 6.0 
There's not really a clean way to un-teach people things, which is why most programs carry around their bad early decisions as an albatross for decades
Input.GetKey will always stay in my heart
The switchplayer script is on the main player. also sorry but the way your saying it is very confusing. This is what I have so far https://paste.ofcode.org/KGq2VccZc4avke7dHq6gFj. Sorry I keep bothering you π«
I missed the start of this whole thing but what is it that you're trying to do
Like, what is the end result you're trying to achieve
Honestly the way rob is explaining it is very confusing
I didn't ask what Rob explained, I asked what you are trying to do
Not sure how I'll feel when unity fully removes the old input system i despise the new one
Once you try to code for gamepads with support for rebinding controls you'll change your tune
Basically I have a cinemachine camera a child of the green zone when I enter the green zone it adds the camera into the list and then when I press R the camera changes to the new one and when I press it again it goes back to the main one. when I enter the red zone it removes the recently added camera. So this is going to be reuseable meaning I will be having more camera's/zones setup
I think rob was saying I should have a separate script attached to the collider and at that point whatever he said was confusing to me
And this is adding a camera you can optionally swap to, right? It's not that when you enter the green area you force a camera change until you exit?
Yeah but that's not something i plan on, and im not saying the new input type is completely bad just not my preferred type
What is the use case of this :?
yes you can optionally swap to
just a game feature I am adding
So, you'd put a script on the green box that has a reference to the camera it wants to add. When the player enters the trigger, it puts that camera in the list on the player that entered the trigger if it's not already there.
Likewise, the red box has a similar script that references the same camera, and removes it from the list of a player that has it if it's in there.
Thanks now THIS is understandable. β€
I mean, that's basically what Rob said here:
#π»βcode-beginner message
Except theirs is better because it's just one trigger that adds on enter and removes on exit
instead of two different ones that both do something on enter and therefore have to check if the camera's already in the list
yes but his explanation wasn't as detailed as yours it was just shorter and less detailed
They're both one sentence summaries of it, I don't think I did anything particularly different
I think you're just coming back to it after taking a few minutes off of thinking about it
there was also this #π»βcode-beginner message
Who is this unity chan?
literally click on the sticker it will tell u π
No i know but why is it that I've only ever heard of unity chan here like never seen it in the app
cuz japan! its on the asset store btw
Unity's japanese?
but yea java has the duke (or the cafe)
not japanese i think. it definitely has a market there.. and japan always got them anime stuffs so i guess that's how it came to be
No, but it has a Japanese arm of the engine
Ahh makes more sense than what i was thinking
the coffee is more of a logo, duke is the mascot
Here's a snippet a code from my current project, both the If statement and Switch are supposed to achieve the same goal, but is there a difference in performance between them ? Like is one method more efficient than the other or is it just a matter of preference ? Just to clarify i dont intend on using both, I'm asking here to know which one i'll keep.
https://paste.ofcode.org/BW2hBTtNjgCsSLmwkm7b97
right.. also the duke makes me think of a tooth π
there is a difference on the magnitude of nanoseconds
use whichever you prefer or will be more readable/maintainable
performance just does not matter in this case
I figured that would be the case, but on a bigger scale, like if I were to use hundreds of statements in a script, would one type perform better than the other ?
only worry about performance if you a) start having perf issues, b) are developing for 50 year old hardware, or c) are doing something with millions of objects
no
Mean when i procrastinate learning switch case
Alright thanks a lot for the info homie
it needs to be millions to start being an issue - and at that point i think you have other issues lol
As long as my code is readable I should be fine right ?
and maintainable! don't go around using magic strings and numbers everywhere lol
Dont become like pirate software
don't become like yandere dev
Lmao that's exactly why i'm asking I dont want to end up like either him or yanderedev
if you ever feel like "there should be a better way to do this", there probably is
That's exactly why you should initially prioritize readability over micro optimization
or if you start repeating code a lot, that repetition can most likely be reduced
Yeah I try doing that, like making a separate method just for a specific if statement to keep things organized
there are a few things to avoid in terms of perf in unity, like not doing Find every frame/tick
if you abide by those you most likely won't have to worry about perf for a long while, until you have more experience at least
"clean code by Robert C Martin"
Just started reading that and seems good so far so maybe you can also read that when you got time π
I'll check it out thanks
Only thing I feel like i'm using a lot are if statements, I have one method with a bunch of those just to check all possible movement directions
so the played cant sprint backwards for example
I'm trying to make a movement system that I'll be able to reuse for any of my future projects
Eh, it's not too much of a problem. What you do want to watch out for is having too much depth in your statements and in which case you should be using a state machine
How can i save Scriptable Objects to json? I've searched a bit about them and it look like all the changes i will make during runtime (e.g changing amount of item) will be reset on restarting. I know i can just store objects data in an array but it doesn't felt like a right approach with SO
I'm planning to store inventory items in SO and change they values if it's needed
What does that mean exactly ?
It means if you find yourself creating too much if statements within your if statements then your logic may just be spaghetti and in which case you should look finding some way to group your logic via statemachine
Ah ok, yeah makes sense
I want to avoid that
"depth" or "complexity" basically refers to how nested stuff is
if (a) {
if (b) {
if (c) {}
else {
foreach (var d in x) {
if (e) {
while (f) {
// complexity = 6
}
}
}
}
}
}
this "nested" complexity loosely correlates to actual complexity and can be a sign of the function doing too much
it also quickly gets unreadable
not sure if the term is correct but I try to use Guard Clauses when I can
To avoid nesting statements
that is the term, yeah
it is correct yes
nice
and yeah that definitely helps with making stuff more easily readable
i dont know why GameObject[] bounds = GameObject.FindGameObjectsWithTag("BlockBounds"); is returning null when there clearly are objects with the tag in my scene, i even adjusted the script execution order and added yield return new WaitForFixedUpdate(); to ENSURE that it calls after everything is loaded and its still returning null
There's nothing special about writing SOs that you'd do differently than some plain data script. You'll just be creating instances of the SOs when you load the game.
when/where are you doing the Find, and have you checked the tag to make sure there's no whitespace or whatever
private List<float> distances;
void Start()
{
StartCoroutine(Aligner());
}
IEnumerator Aligner()
{
yield return new WaitForFixedUpdate();
GameObject[] bounds = GameObject.FindGameObjectsWithTag("BlockBounds");
foreach (GameObject bound in bounds)
{
distances.Add(GetHorizontalDistance(transform.position, bound.transform.position));
}
// parent to closest bound
int lowest = GetIndexOfLowestValue(distances);
transform.SetParent(bounds[lowest].transform);
}
You'd probably want to ID your SOs though as that'll be the identifier you need when you create a duplicate later on
and also yeah i dont think it has blank spaces
(also not sure why you're saying WaitForFixedUpdate would wait for stuff to be loaded..)
don't assume, go make sure
Basically instantiate SO from editor and then alter values to meet what's written in json?
because that calls after start(?)
i dont see how else to ensure the other stuff is loaded
if you have a script on BlockBounds, go have it log gameObject.tag.Length or something
Are they active at the time this code runs
thats what im trying to ensure but i really dont know how else to other than the yield
FixedUpdate is kinda unrelated to loading
it calls after start, because, kinda everything calls after start except for Awake and OnEnable
the yield doesn't really do anything for you here
yea so i thought that would suffice
okay so what can i do instead π
no, just being in Start already makes sure stuff is loaded
loading happens with Awake
Can you show a screenshot of your unity window, with one of these tagged objects selected and its inspector visible? Along with the console tab open?
Okay, there's a bunch of errors there that I assume are because this isn't running, would it be possible to comment that out and make sure there's no errors running before them that might be preventing it getting set?
Or just scroll to the top
turning on collapse might help
i do have collapse on, the problem is i get the error from every object the script is on individually
also the top is just that error
ah.
i know it is not optimized but this is like the only solution i could think of after my initial one didnt work π
Seems like it's a tag mismatch. Try removing the tag and re-adding it, paste in the text from inside of your string.
Or, find a way to not have to use Find at all
did this and its still giving errors
Are the objects with the tag on it present in the scene before you hit play
yes
Can you show the full !code of this script?
π 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.
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.
How about this, real quick, comment out the line the loop and replace it with Debug.Log(bounds)
(And please don't use pastebin if I so much as hover my mouse over the page it turns my browser into one gigantic ad. I'm still stuck on Chrome at work)
oh my fault
every single instances gives me this
Sorry, I meant bound
So it's finding them just fine
so the issue is with the part after ..
The issue has never been related to the find not working
The issue is that distances is null
this makes more sense
holy shit is it because i didnt define the list beforehand
do i need to do like = new List
This is why you don't make assumptions - check everything
You could have logged the count of the list to see that it was getting populated
Say I have a fixed height and a fixed font size. How would I go about dynamically sizing the width of a text component so that it always has just enough space to display all the text in a single line?
I added a debug.log to see if its recognising my player being in the ontrigger collider and its not recognising. any ideas?
https://paste.ofcode.org/37GdPmj4fEkZnjWhxZzmeNu
did you mark the collider as trigger in the inspector?
also make sure you gave the player the right tag "Player"
yes and its still not working
it is a 3d envoirement right
yeah
do you have any errors in the console and is the console active?
no errors at all
Might be the wrong channel - does anyone use scrum for game development?
Thats dumb. basically the parent object that has a rigidbody and the script had the Player tag but the child of the parent actually has the mesh and collider and didnt have the player tag
I changed it and it works now
yeah totally not a coding question @runic gust
alright ill ask terrain-3d
what does scrum has to do with terrain 3d anyways?
if you gotta ask - dont worry about it
I don't think it really fits there either
it was a joke because I dont think there is a proper channel to ask such a question
Thats a workflow methodology? Maybe #π»βunity-talk would be the most fitting, you could make a thread if you had specific questions about using it in Unity
Is this correct? it works fine. https://paste.ofcode.org/pQThMqbXnvwm7k9ZcmQw2E

it works to remove it did you say make a separate script for that?
Or do it in OnTriggerExit
is it like this? https://paste.ofcode.org/PeFy7pX5XwhwVpE3XSixxc
when I enter the ontriggerenter and then leave it the camera will be removed
which I dont want
I want it to be removed when going in the other ontriggercollider
Why do you need two
Why not have one trigger that covers the whole area you want the camera to be toggleable inside of
hmmmm good idea let me try it real quick
Yeah thats good im keeping that thanks
also theres another issue
when I enter the collider and when I jump out of it and press R to switch the camera's will switch but I cant go back to the main one when I am out of the zone
like this
Add another check in exit
If you're in the new camera, exit it
then remove it
I did this and it works perfectly now
Hi! Is there a guide how to create "simple" spell casting system? I feel I'm overcomplicating it, but a bit confused how to adjust it.
Basic idea - I have Turn Based RPG. Character have 4 spells. It could be fireball (projectile) or meele attack(without projectile).
Sequence of actions -> Select Character to move -> Select Target -> Select spell -> Cast Spell-> Casting animation + Damage animation (for mele almost at the same time) OR Casting anumation then Projectile then on hit Damage Animation + Explosion animation of projectile -> After damage taken and animations finishes next turn starts.
Truth to be told I'm not even sure how to describe what I have - there is Model(data) View(monobehaviour) Presenter(binds both).
There is BattleManager that handles logic for selection of unit and initiating casting(checks if target from enemy team, if action not yet in progress etc.).
There is CastingManger that gets data for source,target and spell and instantiate projectile, but projectile need to have callback on hit...
And all of this also uses Unitask on top of it, because I want all action to execute "at the same time" but I want all of them to finish before continuing further.
Could you help me please? I feel I just too deep in this code to see simplier solution.
If it's turn based then can't it simply be some VFX? It's not like you need any physics besides some animation of particles
Yep, I don't use physics. The logic for visuals not that complicated, it's just feels too convoluted.
I'll try top cleanup and post some code maybe (just will be still a lot)
I feel like all you need is some call to the skill animation -> await animation -> do damage
same can be said for any other type of action in these turn based games. They're just animations for the most part
So Animation + Timeline + Particle System
I do it like this at the moment
private async UniTask HandleMeleeAttack(BattleUnitState source, BattleUnitState target, BattleUnitSkill skill)
{
var attack = source.Attack(AttackType.Melee);
var targets = ResolveTargets(target, skill);
var takeDamageTasks = targets
.Select(battleUnit => battleUnit.TakeDamage(skill.damage))
.ToList();
takeDamageTasks.Add(attack);
await UniTask.WhenAll(takeDamageTasks);
}
and for range
private async UniTask HandleRangedAttack(BattleUnitState source, BattleUnitState target, BattleUnitSkill skill)
{
await source.Attack(AttackType.Ranged);
var projectile = Object.Instantiate(
skill.projectilePrefab,
source.ProjectileSpawnPoint,
Quaternion.identity);
projectile.Initialize(target, skill.damage);
var processHit = projectile.Launch();
await UniTask.WhenAll(processHit);
}
I feel it's what your'e describing, or it's not?
Yeah, but what I'm saying is you don't need a callback if it's all sequenced
If you're shooting a projectile, then you know the time it should take to reach the destination
Can someone help me get started?
!learn π
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
I believe I get what you're saying. But for meele I feel animation of attack and damage should be not sequenced, since it will feel wierd (first we stab, and only in the animation end enemy takes dmg)
I have checked that place I didn't check it completely but there are some questions I have that are left un answered
like what?
I don't really know how to explain it that's why I haven't been able to google it or anything
without more info not sure how anyone can help out..
ik
I'm going off of old final fantasy games, but that's really what they did. You'd get combo'd but the damage only showed up in the end. Not that you couldn't sequence between hits to show some damage text.
When I have to script where do I open the scripting place
But those game abilities were purely cinematic and no variance between attacks so pretty much sequenced
you need a proper !IDE π
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
huh?
pick any of these and configure it
has anyone used both grok and chatgpt to learn unity/c#? which worked out better for you?
What are the differences why are there so many options?
they're both garbage, don't use that crap for learning
You know, may be you right. I should do it simple way for now. And then can adjust.
Because at the moment I have chain of 5 classes (View->Presenter->BattleManager->Projectile->Back to BattleManager etc.)
Thank you @timber tide !
just install Visual Studio - !vs
!vs
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
β’ Visual Studio (Installed via Unity Hub)
β’ Visual Studio (Installed manually)
When I install it do I have to set it up?
well VS might run like crap if you have underpowerd pc or linux/mac (doesnt exist here)
yes thats why I sent the links, they help you configure it
yes, click the link and follow the instructions.
How do I know if my pc is underpowered?
im like slightly above beginner, i'm very familiar with coding concepts and im doing stuff like using dictionaries and such on my own. what would you recommend?
maybe share what are your specs ?
VS eats a lot of ram especially
Hi! Im making a game where one object goes to another, offsets itself, than another follows onto that one. For this to happen though, I need the fixed update part of the scripts go in a particular order, otherwise an object will be left a frame behind. (I'll wait if I'm interrupting)
I would recommend the stuff pinned in this channel.
The learn site + microsoft docs, I learned from a lot of that and stack overflow for searching answers.
Gemini 3 Pro, Sonnet 4 and o3 are OK for learning, wouldnβt recommend RAGless free tiers. And only ask to explain, never to generate
would be very careful/cautious with anything to do with "AI" you need to verify its not a hallucination and its difficult for beginners
I'd just avoid copilot
Just have a single central script coordinate all the motion.
ok
CPU: 5 7600
GPU:RX 6750 XT
RAM:32 gigs of ddr5 at 6000 MT/s
@rich adder
yeah you shoud be able to run any of the programs
plenty of ram for VS to eat
what program?
I think I was told to use Visual Studio
oh and you're worried about specs?
Visual Studio is fine and usually already comes installed with unity hub
just need to configured
what about Rider? I believe it's free now for non-comercial. Didn't use VS for some time, but Rider feels good.
i thought this was going to be like a how well would my pc run for substance painter with 4k textures
yeah rider is good too if you do non-commercial
otherwise you gotta pay (unless you're student)
does rider have any sort of intellisense?
duh
I clicked the link for visual studio and I have clicked so many buttons already and more just keep appearing
it has a few extra bells and whistles because of the $$
well idk i spent like 2 years coding from notepad++
personally find it to be too opinionated
takes me more time turning crap off I don't need lol. I like the simplicity of VSC
Do I get Visual studio 2022 or visual studio code?
2022
Yes. I would say it has a lot of it. And it has AI tools integrated (I assume it's paid one feature, I bout it)
at the end of the day they both do the same thing so its up to you
ew ai
Yeah but I don't know the differences.
intellisense is not really. "AI"
you're confusing it with intellicode
though the format looks kinda sleek
If you want to up your unity game and generally learn to be a better programmer, rider is the best choice due to its very thouroughly explained code hints
no they said it had ai tools i like intellisense not the ai crap
So I don't even get Visual studio?
In short - you can have only intelisence if you want. But it's also includes different AI, but it coudl be disabled if you don't like. But for small promts it's usually good.
It depends how you configure.
nav you can't say that to me I suck at making decisions and I don
't know the differences
fair
Get rider.
Send me link
A majority of people use visual studio community
windows users*
I would argue both statements are probably true π
Visual studio gets expensive in professional use
when do you have to pay for vs?
Expensive? You gotta pay for this stuff?
i for one haven't spent a dime on an IDE
no, don't be confused. They're talking about if you are in a company making certain amount
Sadly M$ has the same license for both VS/VSC
IDE is?
the code editor
the code editor / visual studio or rider
i doubt our friend here is going to make the next triple a game company or worry about making $1M in a year
how do you know where life takes them?
What do I need
who knows -) but for first few month-years you probably can say so
everyone was a beginner, setting up yourself for success helps π
defaults, maybe check the "associations"
So many buttons again
follow the instructions provided https://unity.huh.how/ide-configuration/jetbrains-rider
If your IDE isn't providing autocomplete suggestions or underlining errors in red, then it needs to be configured.
All of them?
pro tip: read what the menu options actually say, think what they mean, google words you don't know.
yes
ask google or an AI
you're going to have to google stuff
this is like #1 thing you need to do with Development
research
Do I want a desktop shortcut?
com on lets not ask trivial questions
It's a button in here
google what a desktop shortcut is and see if you want one
be a big boy/girl and start making your own decisions lol its okay to mess up
says they wanna set them up for success, also tells them to us AI smh
you are free to have outdated notions about the usefulness of certain AI tools.
I don't like making decisions
Nah respectfully it's just a stupid thing to suggest to a beginner
This server exists to actually help people
part of life, make it a habit
"AI" for a beginner is pretty dangerous especially when they have no way to verify the authenticity of the information provided since they will not research
Well I'm downloading something now so seems like I did something
people are becoming dumber because "AI" tells them what it is with certainty and we all know its designed to give you what you want to hear, not always the truth
you are just patronizing beginners and assume they are all idiots, yet believe you are "smart" enough to be allowed to use AI on unknown subjects yourself.
No we are assuming the people relying on AI are idiots
beginners don't know better if they don't research , thats literally 90% of learning
give them some credit, a person who cant use AI responsibly will fail either way, with or without it
And I atleast have made that assumption based on personal experience
spoon fed answer from AI will not help them in any capacity
Well I kinda am an idiot tbh
then you should probably stay away from AI
There's a reason this server chucks AI dorks into a single space tucked away from all the real support
ironic huh after all you've told them to use it
That's why I'm here
thats not the only way you can use AI
thats how most people use it from what I've seen π€·ββοΈ
you get spoon fed a bunch of silly stuff here too, so be mindful and get second opinions.
you learn critical thinking with researching / trial and error. easily to verify with other human responses. we all know AI just feed you "This is what it is" and most of the time its eeither partially wrong or hallucinated
ask the same question to "AI" it gives you different answers, sometimes its efficent if it nails it and sometimes its some over convoluted bs
well, i find that AI at least gives a more comprehensive overview of what possible answers exist, provides sources (unlike opinionated humans)
"of what possible answers exist" is so fucking stupid honestly
google does this
google has done this
a bit ironic though cause you're saying with certainty that AI could help them , thats pretty opinionated lol
I am actively studying with peers who just came out of high school right now and a majority of them are reliant on ai and said people are absolutely fucked when it comes to their actual education
it's brainrot
most of us I assume started the traditional means "StackOverflow FTW " and research
This thing wants me to buy a license what do I do
dont buy one
It isn't giving that option tho
You can use it for free for non-commercial use
or if you're a student you get it free as well not sure if that covers commercial use
doesn't this mean they can't publish a paid game when using it?
correct
I found the right buttons
absurd terms who would want that
well they can but they have to buy a license
Now I have to choose a theme but they all look the same
people who work on open source projects for example
or just learning , and they want you to get hooked on it in hopes you do buy a license later on
Also like, I wonder how they prove you used Rider
lol yeah same with unity's terms
haha they do analytics for all your scripts/ projects
but still not sure i'd want to use such an app
idk what kinda blackbox magic if any to prove you are making money with that project
I rather not be the one to "fuck around and find out"
Aren't these all the same????
Realistically they probably just don't check at all until they catch someone like the balatro dev under their cardboard box propped by a stick
then payout time
all the colors are different. Are you colorblind?
this is just colors.. pick whatever you want
the "rider" theme is the most useful one for c#
what happened with balatro?
it made money lol
I assume they only care if you're actually making decent scratch (im not a lawyer)
Next I need a build map what is that?
Β―_(γ)_/Β―
you press ctrl+r it waits for another key then you press R again
Is that inconvenient?
thats usually for fast rename / across script
These are the options
stick to VS shortcuts, imo if you are looking at tutorials you might get confused
wait vs has a rename shortcut?
this should probably be a thread if we gonna do this spoon feed stepbystep
crowding the channel for other potential questions
What are these?
Is there a way to prevent a fast moving object to penetrate a wall?
(are you using rigidbody) you can try using continuous collision mode.
also not a code question
you're too fast i was about to say the same but forgot the name
if you are not using the physics system, you could fire a raycast from the current position to the next position
adjust the collision detection/ use a bigger collider/ move w/ physics forces
or do a "validity check" pre-movement
catch 22.. u can't raycast without using the physics system π
I've tried using Rigidbody.Move to move the player, but still it penetrates a wall, so I'll try out raycasting
try changing the collision detections first
Continuous is necessary imo if ur doing anything physics
you should be using AddForce / Velocity .
Thx but I already tested with continuous Dynamics
Ok Ill try with Rigidbody.AddForce
Earlier was asking about how to do things async with unitask (attack animation, create projectile, enemy take damage), was able to do it.
And each method now responsible for notifying others about if it's finished or not (and we can adjust animation now - for example trigger it "finish" earlier, so other action will follow)
private async UniTask HandleRangedAttack(BattleUnitState source, BattleUnitState target, BattleUnitSkill skill)
{
await source.Attack(AttackType.Ranged)
.ContinueWith(() => SendProjectile(source, target, skill))
.ContinueWith(() => PlayEffect(skill.effectPrefab, target.Position))
.ContinueWith(() => target.TakeDamage(skill.damage));
}
I feel this is most flexible approach. Do you see any issues with it?
is there an actual goood tutorial for recreating mario physincs/mechanics in unity? all the ones ive seen are either very outdated or control like garbage and not like actual mario
also id prefer if the tut actually taught instead of saying "type this here" i hate that it is a pet peeve of mine
Don't expect a beginner tutorial to run as smoothly as famously one of the best platform series ever lol
etc etc.. your odds of finding a (one size-fits all) tutorial are slim..
and if u find a tutorial where its "do this and this" and they're not explaining why.. then close it and move-along
these might work
thanks twin
code doesn't go out of style btw π
the editor and stuff may change.. but logic is logic... and even 8 year old tutorials still work
theres always that case of a deprecated function or one thats been renamed..
a properlly config'd IDE will reveal the alternatives
or the newer version of said method for example rb.velocity is now rb.linearVelocity
good luck... tbh i've never seen a good Mario tutorial
maybe i just haven't looked hard enough but lot of em are just basic platformer code and then they capitalize on "mario"
lol
i think mario may have Coyote time and jump buffering
those are two things u can also look into independently
oh, that Press Start perfect jumping tutorial may cover that
he's pretty solid imo and actually explains things along the way
ok so i imported my sprite into unity and
the colors are all out of wack
this is what its supposed to look like
wait nvm
it was cmpression
not a code question, btw. for future reference you should ask this sort of thing in #πΌοΈβ2d-tools
but yes pixelart should have filter point and compression none
Anyone have an idea on this? https://canary.discord.com/channels/489222168727519232/1396147962979029186
dont crosspost
my bad
Im getting this error specifically in build mode: probably about this script
You should not have a Monobehaviour and a Scriptable Object class in the same file
thanks
Can I have multiple SO in the same file?
no unity classes like MB or SO
only POCOs are ok
its good practice to have separate files for each class anyway, less disorganized and costs next to nothing to do so
any type that can be referenced via the inspector needs to be in its own file, and the file since it also needs the GUID and the meta file to properly reference it
regular C# objects and structs do not have this limitation and you can put many in a file or even nest them
not sure if its still a requirement but iirc the class name for a component or so also needs to match the filename so when you fix it i would rename the files to match
iirc that was relaxed with unity 6
me when i spend 30 minutes trying to test a function but forget to call it wondering why it aint working 
hey, how i can make this work via a raycast instead shooting a proyectile?
{
rifle_amount--;
Vector3 mouseposition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mouseposition.z = 0;
Vector3 shootDirection = (mouseposition - transform.position).normalized;
GameObject riflebullet = Instantiate(rifle_bullet, transform.position, Quaternion.identity);
riflebullet.GetComponent<Rigidbody2D>().linearVelocity = new Vector2(shootDirection.x, shootDirection.y) * rifle_bulletspeed;
}```
What exactly about this are you missing in your head here?
what
i mean
i originally made my player shoot a prefab proyectile, but then i decided to change it to raycast, the issue is i dont know how, i tried to follow a tutorial but it didnt worked, it didnt shooted a thing and didnt hurted the enemies
Hello, I'm trying to set up mouse input to switch between 3rd person perspective camera and orthographic (isometric).
scroll up for third-person
scroll down for isometric
Iβm using cinemachine and i made three scripts: CameraManager, CameraRegister, and CameraController. The input works, and the transition between cameras plays nicely. Weird part is that when i scroll down to switch to the isometric camera, the projection stays in perspective instead of switching to orthographic. Any idea why that might be happening?
Anyone know if GUIUtility.pixelsPerPoint is publicly accessible anywhere? or will I need to use reflection (its internal static float)
if it's internal, that should answer your question already
Well for example theres a public getter to it in another class but it's in the editor namespace
was curious if there was maybe others π
Hey, I'm having some trouble with delegates and events in my project.
The intended behaviour: Whenever entering a game level, a singleton GameManager awakes and sets itself plus other important objects (ie the player) as persistent with DontDestroyOnLoad(). Whenever the main menu scene SPECIFICALLY is loaded in, the GameManager is meant to recognize this using an event, and delete itself plus all it's marked persistent objects.
Instead, this setup will strangely work the first time, then completely fail and allow the GameManagerand player to exist in the main menu every subsequent run.
Here is a video that shows the behavior and my entire GameManager script. Below I included the full script in text form.
public class GameManager : MonoBehaviour
{
//Declaration of a singleton.
public static GameManager instance;
[Header("Persistent Objects")]
public GameObject[] persistentObjects;
private void Awake()
{
//If sceneLoaded triggers and this object is in the scene (theorhetically always possible after the first game scene),
// run OnSceneLoaded
SceneManager.activeSceneChanged += OnSceneActivated;
//If there is a GameManager already in the scene (global "instance" has a value attached) it destroys itself.
if (instance != null)
{
CleanUpAndDestroy();
return;
}
else
{
instance = this;
DontDestroyOnLoad(gameObject);
MarkPersistentObjects();
}
}
private void MarkPersistentObjects()
{
foreach (GameObject obj in persistentObjects)
{
if (obj != null)
{
DontDestroyOnLoad(obj);
}
}
}
private void OnSceneActivated(Scene lastScene, Scene nextScene)
{
//Determines if the scene is the main menu, and destroys all of this game manager's persistent objects if so.
if (nextScene.name == "MainMenu")
{
CleanUpAndDestroy();
}
}
private void CleanUpAndDestroy()
{
foreach (GameObject obj in persistentObjects)
{
if (obj != null)
{
Destroy(obj);
}
}
Destroy(gameObject);
}
}
You're doing this:
//If sceneLoaded triggers and this object is in the scene (theorhetically always possible after the first game scene),
// run OnSceneLoaded
SceneManager.activeSceneChanged += OnSceneActivated;```
Even when the GameManager is a duplicate and is about to destroy itself
shouldn't this only happen in the else case in Awake, when this is the first GameManager?
So, I want any duplicates to destroy themselves, and I also want the original to destroy itself whenever the scene changes to the main menu
Yes... I can see that. That's not an answer to the question I asked though.
You still would only want to subscribe to the activeSceneChanged event in the else block of Awake
You also need to unsubscribe in OnDestroy
which you're not doing at all
I didn't know unsubscribing was necessary if the object was destroyed honestly. never used delegates before today
You need to unsubscribe when the event publisher outlives the event subscriber
which is the case here
otherwise the delegate on the destroyed subscriber/listener is still going to run when the event fires
I understand the rest of what you've said and I do trust this will fix it, but I'm trying to reason out why it needs to be in the else section. Wouldn't duplicate versions subscribe then immediately unsubscribe themselves in an instant when they're deleted? Would this cause actual problems with how events work, or is this more of an efficiency or best practices thing?
Wouldn't duplicate versions subscribe then immediately unsubscribe themselves in an instant when they're deleted
Duplicate versions will never subscribe in the first place because we will only subscribe inelse
(im going to move it to the else section if it is a best practice's thing to be clear, i just want to understand the issue better)
else only is running here when there is not already a singleton instance
yo sup
bro i wanna publish my game to app not just in unity learn
do you guys know how to do that
what does "publish my game to app" mean?
u know when we download game from internet then u can find .exe file
@wintry quarry Just for closure did end up grabbing that value via reflection, works fine. Was interested in grabbing it because i'm interested in some runtiem GUI stuff and HandlesUtility.WorldPointToSizeRect is editor only but the only editor only part of it was grabbing that value π
and when u click it u got the game
You're asking how to build your game then?
is that possible?
Is building your game possible? Yes of course.

