#💻┃code-beginner
1 messages · Page 778 of 1
oh youre using visual scripting* ?
Visual Studio is a code editor dude, you use C# to code not "Visual Studio code"
i think they are using bolt
just not calling it the right thing 💀
and also yeah visual studio isnt a "programming method"
anyhow #1390346878394040320 is the channel you are looking for.
yes
italian?
you tried restarting ?
i apologize if theres any info im not being clear about, just trying to fix an issue that to me shouldnt be possible?
ill do that, honestly i shouldve done that a while ago
the breakpoint pauses before that line runs
yes, i realize it was a worthless breakpoint, and we moved past that point
the breakpoint isnt hitting
the screenshot you showed just shows that the if was reached, but not which branch it took - you can step forward to see what happens next
they saying when running with Attach Debugger the bool doesnt hit true
it wasn't worthless though. you couldve just stepped forward
do you have domain reloading on for Playmode
yeah, regardless, in debug mode the game runs as intended
is this a setting? where might i find it
that means you didnt disable it so disregard that
the video i posted better portrays the issue
a relaunch of the project did not fix the issue
debug mode continues to work as intended
its strange unless something obvious I'm not seeing rn could be a bug or something..
if you hit play doesnt do the same "Domain Reloading" and all that with progressbar
when running unity in "release mode"?
pressing play reloads the domain yes
heres a video with breakpoints on the conditional , and the assignment line
prob wont do as much but worth trying deleting library folder ?
where might i find that
project root folder
have to close unity, and it will load a while and put you in new scene
i wouldnt be surprised if this somehow ends up being something messed up with 6.2 its been a buggy mess
will deleting the library folder change any project preferences
and, thank you by the way
nah it will not change any preferences
just refresh the cache for assets
this is a particularly bothersome issue, and im grateful for the assistance
ok relaunched, library folder was recreated automatically, and the issue is the same
ill try in a newer editor version
in this video stunned = true never hits
turn off Collapse from Console window, then try instead printing Debug.Log($"airtime : {airTime} stunned {stunned}");
before the if statement
and maybe one after
I mean this in non-debug mode on
see what kinda values you record
alright, one moment
its outputting numbers significantly higher than any with debug mode on
700-800 range
now i have to wonder if its like, more updates per second without debug mode on?
because airtime is just a value directly related to the number of updates between grounded states
in Update()
📃 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 (!stunned)
{
if (Input.GetKey(KeyCode.A))
leftPressed = true;
else
leftPressed = false;
if (Input.GetKey(KeyCode.D))
rightPressed = true;
else
rightPressed = false;
if (Input.GetKey(KeyCode.W))
jumpPressed = true;
else
jumpPressed = false;
}
else {
timeStunned += 1;
}
if (timeStunned >= maxStunTime) {
stunned = false;
timeStunned = 0;
}
if (!grounded)
{
airTime += 1;
}
else if (stunned) {
airTime = 0;
}
}```
ok, update is frame-rate dependent cool
is there a way to, make that a static value or something
well yeah cause it runs every frame
you want to increase airtime / timestunned INDEPENDENT of framerate
which makes sense, i just figured there was a default cap or something
use * Time.deltaTime whenever you want values to change overtime consistent regardless of fps
can i throw it in fixedupdate() instead?
this means it was running way faster than it does in debug mode, which makes sense cause debug mode has overhead
I mean you could but using every physics tick might not be what you want
really i just put it in update because i knew it would increment always, and i was just gonna tweak values based on what felt good, so either way it should be fine, as long as its consistent
there is no harm with doing it at your own pace than physics tick as long as you do it with * Time.deltaTime
ok, ill do that then
you can make it change with your own rate of increase
like airTime += Time.deltaTime * airTimeChangeRate
wonderful, things work great now
thank you so much for your time i would've been here, literally forever
void Update()
{
if (!stunned)
{
leftPressed = Input.GetKey(KeyCode.A)
rightPressed = Input.GetKey(KeyCode.D)
jumpPressed = Input.GetKey(KeyCode.W)
}
else {
timeStunned += Time.deltaTime;
}
if (timeStunned >= maxStunTime) {
stunned = false;
timeStunned = 0;
}
if (!grounded)
{
airTime += Time.deltaTime;
}
else if (stunned) {
airTime = 0;
}
}
I dont know if that was like a test code, but u can do that in the if(!stunned)
so you dont need to check for if Input.GetKey and set bools manually
👍 nice, thank you
oh yeah btw u need to multiply by * Time.deltaTime
this basically runs every frame, so you need to multiply by the time taken between 2 frames
yes, i know
ill edit the code just in case someone else sees this ig
ok done
why is nav thinking
did you like skip through the part where I explain this exact thing
i saw that u explained about deltaTime but didnt see you explain that he doesnt need to set bools manually
huh I never said anything about the inputs
I was talking about the deltaTime thing
thats exactly what i said
Hey guys
I wrote it on the general
But I have an issue on unity when I am using easyroads or similar assets and I do shift click to place roads nods it just doesn’t work
I really don’t know what to do
why are you crossposting then
this is a coding channel
Yeah I know but no one seems to be interested or bothered
crossposting wont help that, also against server community rules..
has it ever occurred to you if someone doesnt answer it means they don't have an answer since this is very specific to your set up / asset? and you have not detailed anything else in the original question to help with that
How would I put a text infront of an image
are you talking about UI / canvas ?
hierarchy order
also this is a coding channel
sorry thought it was a walmart
well so what does a UI question have to do in a coding channel if you are not presenting a code question 🤔
well idk where it is
#📲┃ui-ux ?
well idk wtf ux is
but you certainly know UI...
& if you took the 2 seconds it takes to google it you'd know.. no reason to be lazy
he probably doesnt know what ui is either and knows just the word "UI"
ik what UI is
I just didnt look at it
you can both stop being rude now
User Interface?
yes
it was sarcasm ui vs UI
oh i actually didnt know i made a joke right there i was just too lazy to write in caps one time lol
didnt want to sorry man if that is rude ig
oh well now it is
wasnt talking about you
not sure if i should talk this here. but has anyone ever tried using AI-based IDE such as windsurf or cursor for unity? how good it is to boost the development?
p.s. i know the fundamental of coding, just want to speed up my development
if you mean by speed up , spending tons of time fighting with the editor and bad code needing constant refactor / fixing than sure
is it really not that good? i heard it's better since they have access to your whole project, resulting in better response
Just use github copilot, codex or some other e tension integrated with vs code.
The ides that you mentioned are not supported by Unity, so you wouldn't get any intellisense/error reporting and the AI agent might be missing a lot of tools.
ah i see. i've been using github copilot for some time and really love it. although i constantly keep hit the limit of free tier. i guess ill try to buy a subscription. thanks for your suggestion!
windsurf is an extension so you can just install on your ide and see, cursor is basically vscode so it should still compatible and is really fast you should give it a try if choosing one
Not sure about cursor, but I've tried antivtavity(based on vs code fork as well), and the unity extensions is not available there, so you don't get any language/api support.
i tried cursor about 3 months ago and it recognized everything
maybe the cursor community is bigger so more support idk
the extension are the same as using vsc
@alibinikram muted
Reason: Sending too many attachments.
Duration: 29 minutes and 51 seconds
put a log in oncollision enter
does it run?
that doesn't specifically answer the question i asked
i want to make an script in which makes my camera's forward to my player's forward
sounds like an x/y problem ngl
what are you trying to achieve?
like in which direction im moving my camera, i want my player's local forward towards it
like in FPS shooter games
im using cinemachine
@rahul036560 muted
Reason: Too many messages with links sent.
Duration: 29 minutes and 51 seconds
i know that in order to call static methods, you don't need an instance of the type, but i don't know why i can't use the arguments of the method to set the fields inside the type itself.
Hey, I was trying to hook up a function in the properties pane, but I can't figure out how to get them to show up. I have tried using actions, functions, and events, but none of them show up in the properties pane. I know it's possible because the button does it, does anyone know how to make it show up? For example I want to be able to set propertiy Foo to point to function Bar in the properties pane. Cheers
Static methods belong to the class, not the object, so they have no idea what the instance is. You can pass the instance in as an argument, or return a value you can use to assign to an instance.
More info from MS: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members
In your situation, you could set prefabDroplet as static since it should be global to all ShootBullet instances. It's not clear what targetPosition is though, I presume it's unique for each ShootBullet and so you should pass it as an arg. Just my guess based on your screenshot.
prefabDroplet and targetPosition are not static ^
what properties pane are you referring to exactly?
the inspector?
Yep
sounds like you want UnityEvents?
I'll give it a try
Perfect, cheers!
Well maybe not 100% perfect, any way to pass in an arbitrary lambda? Events will have some limitations
lambda is a poor choice of words, it has to be bound obviously lol
I have a list of buttons and I want to populate them with text, they might not have the same format of text, so I'd like to be able to point button 0 to function Foo, and button 1 to function Bar which can be called in code "buttons[i].text = descriptionsi"
Sounds like you want reflection
doubtful
Hm, why would I want reflection?
sounds like you could just do this in code?
Yes, it's very easy to do in code, just use Functions
ah, did you mean an arbitrary delegate type here
i don't think unity can serialize that, it's just UnityEvents, unfortunately
Cool fair enough, I can live with that limitation. I just wondered if I missed something obvious
So you want your methods from your class to show up as some kidn of dropdown, right?
Or am I getting something wrong 😄
Yes, but the kicker is that functions should be allowed (ie delegates that return values)
i guess you could use reflection like how animation events does it, but.. that's kind of a fragile system. since you're in control, doing it yourself would probably be easier
as I said. you need reflection, when you wanna get all methods from a class
I definitely do not want reflection 😄
Do you want to assign them in runtime?
No, I just want to be able to hook things up in the editor rather than in code
then why not use reflection
In my experience reflection is super fragile in all situations
All I want is to be able to say Public Function<string> foo and point that to something in the editor
As Chris aluded, if Function was serializable then this would be doable easily
couldn't you just have the inverse relation, or an interface
I am using reflection to get a list of methods from my instance classes, I know I have an instance type at runtime. from there I can assign any method and call it in runtime through that instance reference without any issue
ah shoot, can't serialize interfaces.
couldn't you have a base class with a known virtual method, or an inverse relation
I am not exactly clear on how this would work but it feels like it's fighting against how Unity expects you to work
Are you using the function names?
have the provider reference and update the button, or have the button (well, its driver script) reference the provider
the important part is, it works 😄 I have to reflect against namespaces and types to get the correct list
But lets get to your setup. So you want to tie a function, that returns something to an object, that should receive it?
the important part is that it's easy to get wrong
If it works that's good, I think I will not go down that path though 😅
that's the issue with reflection
...sorry to butt in i can see you guys are deep in the middle of something lol. Do any of you have any experience with the unity behavior package
Of course it is. But thats with everything in life, right 😄
: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
@wind forum why not just reference the relevant objects instead of trying to reference the specific function
Than you gotta create some wrapper method that takes some Action object with a generic value or multiple overrides and a receiving object, that you have to cast correctly with some checks to get your connection to work 😄
im trying not to be rude and interrupt and asking if any of you have any experience dealing with what im asking about... hence why i gave some small amount of info.
definitely not
that just wastes both our time
I will try make the example succinct; I have a series of buttons that do upgrades, each has a description text that embeds values from an object; eg "+{bonus} damage, costs {cost} gp". If I was working in a different framework I would use a lambda here.
Out of simplicity.
sounds like something the localization package would handle easily
what im describing is the simple thing
ok.
I am trying to get some information out of a behavior subgraph, and bring it back into the 'parent' behavior graph.. and i cant see to work out how to do this, i've used shared blackboards.. and shared variables.. and... variable overrides...
..but i just cant work it out, and i cant see to find any good examples, that i can 'follow along' with
-so if anyone has any experience with this, any help would be appreciated.
i might be wrong, but i vaguely recall something about graphs not supposed to care about subgraphs
though, this is the code channel. behavior isn't exactly code, try asking in #💻┃unity-talk (though, not many people seem to be using it, so might take a few tries.)
I will google it. Cheers!
As my questions have not been answered by him, I was just guessing what he might need 😄 Still not sure, what he was to tie together exactly. But if you got it and the solution, ill stay silent
how do you go about referencing a GameObject having the static type? is it compulsory to create another class which holds references to prefabs or is there some other way to do so?
A lot of people use Singletons
having the static type
what do you mean by that
yeah modifier, it's not a type
static is not per object
where do you expect that to show
ya, i just got to know that that's why i asked how do you reference one...although, if you do use singletons to refer to prefabs, then welp, les just say, i have a to redo a lot
I don't see why you'd need a prefab field to be static
i think so...? unless you know of a better way to do it.
why does Create need to be static
good question
also, you probably don't want GameObject there
use the type of the relevant component on that gameobject, so you don't have to do another GetComponent
i keep getting more confused as i read your code lmao
what exactly is ShootBullet
is it the thing shooting or the bullet itself
you should probably step back and design it more clearly
so, why is the bullet responsible for creating the bullet (it shouldn't be)
so...i have a unit, which has a collision check in it. if a collision occurs, its supposed to spawn this bullet object. so, this script, is attached to the bullet object in the heirarchy. i am trying to set it up such that, when its instantiated, the script attached to it changes its position by itself. if possible, i just want one script to do that.
you can't
you'll need an entry point anyways
you would have the script that calls Create currently be responsible for the instantiation and initialization
this video does something along these lines though...
🌍 Go to http://admix.in/ and Start Earning Revenue in under 24 hours!
✅ Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=Hp0ovwSC4FE
Let's make some simple Tower Defense AI. Place towers and Fire Projectiles at Enemies in range. Upgrade Tower Range and Damage.
This video is sponsored by Admix
Grid System in U...
is that a screenshot from the video, or...
i tried copying the video, and this is what i came up with...
said bullet in question
i'd rather not go through the entire video, got a timestamp?
https://youtu.be/Hp0ovwSC4FE?t=593 works maybe?
🌍 Go to http://admix.in/ and Start Earning Revenue in under 24 hours!
✅ Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=Hp0ovwSC4FE
Let's make some simple Tower Defense AI. Place towers and Fire Projectiles at Enemies in range. Upgrade Tower Range and Damage.
This video is sponsored by Admix
Grid System in U...
dunno what exactly you wanna see though...
well, whatever you were trying to show me?
the "something along these lines"
that's basically the whole code up until 9:55. whatever he has implemented up until that point, is what i am trying to replicate
for the result produced because of this, you can skip to 10:14
yo can someone explain what this actually means? i dont know the terms well enough to figure out what im actually supposed to do here yet
im trying to use the new movement system beucase how ive been taught is making my playing move backwards continously but becuase of that Im trying to apply it to an already extremely messy project that ive been hacking at
would scrap the entire project but its a group thing so aint an option
even on an entirely fresh scene its still doing it
Don't use the new input system much but sounds like Unity has a singleton instance of a input map and the editor is complaining here that you should use a new standalone instance instead of that singleton asset
If you right click in your directory you can usually make a new input action map and use that
the guy im programming with unfortunately set it as that so I got no choice, what is really good is I resolved the error after turning my whole project upsidedown for it
turns out the input system wasnt offically assigned in the menu for it in scripts
had it assigned in project settings so kinda confused but hey works works
thanks Mao:))
any drawbacks making a projectile shooting weapon using particles?
well physics wise
collisions... I see basic particle system uses simple spheres?
in general should I bother using a particle system or just use GameObjects?
pros and cons looks ambiguous for me
Unity's particle system?
yeah basic one
Whats the contect where you want to use a particle system to detect collisions in a weapon
It has rigidbody support, but I think it's limited. It doesn't have the more CPU heavy speculative modes (but I'd double check on that)
@tired python so seems like the tutorial you were following basically had a factory, with centralized assets.
if you don't have centralized assets, imo it doesn't make that much sense. besides, the logic could be deduplicated from other projectiles too if that's such a priority
don't treat tutorials as gospel, use them as learning resources. make stuff that suits your needs.
you gotta take some time to design your own systems
stuff like flamethrower rocket launcher and a crossbow
centralized assets...as in singletons with references to all the assets in game right?
i looked into what you said about it being static, and i kinda think, if i do remove static, i might be able to implement it
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
public class ShootBullet : MonoBehaviour
{
[SerializeField] GameObject prefabBullet;
Vector3 currPosition;
Vector3 targetposition;
public void Create(Vector3 spawnposition, Transform target)
{
GameObject projectile = Instantiate(prefabBullet, spawnposition, Quaternion.identity);
ShootBullet shootbullet = projectile.GetComponent<ShootBullet>();
shootbullet.Setup(spawnposition, target);
}
public void Update()
{
Vector3 direction = (targetposition - currPosition).normalized;
if (Vector3.Distance(targetposition, currPosition) <= 10)
{
Destroy(gameObject);
}
}
public void Setup(Vector3 spawnposition, Transform target)
{
targetposition = target.position;
currPosition = spawnposition;
}
}
it'd probably be easier to just.. not have Create
using UnityEngine;
public class EnemyCollision : MonoBehaviour
{
[SerializeField] string EnemyTag;
private GameObject target;
private ShootBullet shootBullet;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == EnemyTag) Debug.Log("Duck was detected.");
if (!target) target = collision.gameObject;
}
private void OnTriggerStay2D(Collider2D collision)
{
Transform shootFromPosition = GameObject.Find("ShootFromPosition").transform;
shootBullet.Create(shootFromPosition.position, target.transform);
}
private void OnTriggerExit2D(Collider2D collision)
{
target = null;
}
}
no, this doesn't make sense at all.
so...how would you do it then?
isn't this a tower defense game
why is there a single "shootfromposition"
so like, it's a child gameobject attached to the unit droplet whose position has been set, you wouldn't think that a droplet would spew water bullets at you from its eyes or head right, that's why, i want it to shoot the pellets from its mouth, which is where shootfromposition is set to.
so there's only one droplet ever?
no, there are gonna be many clones of the droplet
ok, so how would you know which shootfromposition to use
use serializedreferences for that, not Find
every droplet has its own shoot from position which is diff
or wait, lemme check
and you're making no distinctions between them in this code
is EnemyCollision supposed to be on your units?
oh ya, it's working aight
i am though
you're also shooting every fixedtimestep?
to figure whether there's a enemy within sight
yeah that does not look very promising
you aren't, you're using triggers
no like, i have another thing which requires collisions
so why is the thing that uses triggers, called collision
My experience with it has been fine with anything but really high speed particles, but with the example of something like a flamethrower you might not want every single particle to apply damage if you're using hundreds of particles, which is where having your own collision checking would be more preferable as you can do it in larger shapes.
or I can just make a cooldown?
well, I don't really know much examples but valve just went for using particles for a flamethrower
oh god there's so many issues with the code you showed...
Well, you also have hundreds of particle collision checking is isn't as performant as a few queries
then what should i name it...isn't it a Collider2D O_O
oh wait, did you mean the class or the argument used for private void OnTriggerEnter2D(Collider2D collision)
Well, you can also make a secondary particle system too if you want that just handles collision with less particles as an idea (no rendering). Oh, another idea is make particle systems in chunks where the parent is the larger colliders and then subsystems for the many particles
yeah now I recalling how much cursed things valve have done I am not sure I should blindly assume their examples are great
major issues:
- you are using
GameObject.Findto find objects by name, when there are multiple objects with the same name. this is unreliable. shootBulletis never set.- you're trying to shoot every fixed time step, with no configurability.
minor issues: - you're using
Findusing a hard-coded string. this is fragile. - you're using tags, which arguably could be replaced by component checks, or in this case, proper collision layer setup. the tag is fragile.
- you're using
Findevery fixed time step, a potential perf issue. - the
OnTriggerStay2Ddoes not check if there is a validtarget.
solutions:
- use serialized references instead of
Find. - get rid of
Create, it's not doing you any favors. - serialize
shootBulletand assign the prefab properly. - you probably don't need
OnTriggerStay2Dtbh - a question of design, really. the way you have it set up means it can't change targets when the current target goes out of range either. - set up collision layers properly instead of the tag check
neither are collisions.
colliders are not collisions.
if you don't understand something there, please do ask. i'm happy to clarify, i just can't read your mind
2 would not work, since these are unity components. they have a lifetime managed by unity.
5 is not true
for 6, Find is an expensive operation, even more so with GameObject.Find.
OnTriggerStay2D is a message that runs continuously. you don't want to be running that expensive operation continuously for no reason.
i don't understand what you mean by this though "set up collision layers properly instead of the tag check"
for 7, OnTriggerStay2D will be called for each collider that's in the trigger. if one of the collider leaves the trigger, target gets set to null, but you'll still get OnTriggerStay2D messages from the remaining one
you can avoid this by just not using OnTriggerStay2D
do you know what collision/physics layers are
https://docs.unity3d.com/6000.2/Documentation/Manual/LayerBasedCollision.html
Make it so literally only the things you care about checking even count as colliding at all
so...suppose the enemy does go out of the range, and hence, target is set to null. how would i get what the target right after that one is (assuming that there are a lot of other targets inside the range)
you'd probably keep a list of all that are in range
and keep on updating it when something does go out of range and then set the target to the first index of said list?
sure, that'd work
how does garbadge and memory allocation works?
Why does a RaycastNonAlloc exists for multiple hits but not for a one, and also, is it bad to create arrays of stuff inside a method just for a use inside of this method?
raycastnonalloc doesn't alloc because it needs you to alloc
yeah I get that part
but why does a single hit raycast don't have non alloc version
then
because it doesn't alloc (i'll get to that, ill answer the other question first)
is it bad to create arrays of stuff inside a method
bad in general? no, not really.
one thing to focus on would be whether it makes sense for something to be an array, or if it could be something else - a struct, for example.
but in the context of perf, you would start worrying about garbage in 2 situations
- you have a known "hot path", aka code that's executed a lot (hundreds to thousands to even start worrying, though). this could be in Update, or inside a loop inside Update, etc.
- you start to have perf issues, and you've narrowed down the cause to excess garbage.
I got a vague idea what every time I create something it allocates hence garbadge unless it's inside a method which means thing will get discarded instantly (heap/stack thingies, I got poor understanding but yeah)
The single version returns a struct (RaycastHit) which is not a reference type and does not allocate memory on the heap. An array on the other hand is a reference type and is allocated on the heap.
Even if its an array of structs
(this will be simplified to the relevant parts, cpus are really complicated)
in typical modern computers with modern programming languages, there's 2 areas of memory, the heap and the stack
the heap is just a blob of memory that can be allocated for various uses.
the stack is a structure that represents the call stack - when you call and return from functions, there's a FILO behavior, this is managed using the stack.
when stuff "allocates", this usually refers to allocating on the heap. reference types, eg classes, arrays, delegates, are stored on the heap, and their "value" is just a reference to that object on the heap
on the other hand, value types, eg structs, enums, are stored directly. if it's on the stack (eg a local variable) the value is on the stack. if on the heap (in a class, in an array) the value is on the heap
that sounds like one could "cheat" by using a struct as an array
so when you create a struct to return, you're really just copying its actual values, rather than allocating stuff on the heap and returning a reference
structs are fixed size
so an array?
I mean imagine if you know you would get 0-10 things
so instead of using an array u could use a struct?
with 10 things?
a struct as a concrete type has a fixed size.
an array as an instantiated value has a fixed size.
different scopes.
what if you had to be able to store more than 10 things
well different situation
Yes, you could implement or use a fixed size struct array for specific use cases if you know the max count
that's, like, valid?
that.. doesn't invalidate my question
There's actually some discussion related to that going on:
https://discord.com/channels/489222168727519232/1444761170279006490
a struct has a fixed size as a type - if you need to store more, you have to change the entire type, whereas the array type can be of any length - just can't change after constructing
then I would have to use an array
or had an infinite amount of structs with different lengths or something
you'd also need a ton of methods to return each one
yeah
you can't selectively return different structs
that's the main issue with the argument of "use a struct instead"
but if you do know how many, then yes, you can use a struct.
we already do
I wasn't saying, like, in general
Vector2, Vector3, Color, Quaternion, etc, could all be represented as arrays
I was assuming situations where I know I would get a reasonable small amount of value types
"reasonably small" doesn't really cut it
you'd need to know exactly what the limits are
Regarding the RaycastNonAlloc stuff, you can (and probably should) allocate an array once in the class and reuse it if you perform the raycast a lot
I know
yeah I do that
Or event a static array as long as you understand how static works
but I got curious why ain't I do that for simple raycasts
yeah I do that
thing is I don't directly see/know how memory management work aside of scary alloc at profiler so
Then you should read about "heap vs. stack" / "reference type vs. value type" / "class vs. struct"
or spend some time with c/c++ lol
"The size of memory required is already known before execution." oh yeah
missed that part
explains struct vs array
I keep watching/reading C++ content but haven't gotten out of my C# comfort zone yet...
It looks so non-standardized and messy to me
well you aren't.. super wrong
it inherits some quirks from C where some stuff was made before it got standardized
what does standartization mean this context?
having an authority that defines how the language must behave, and what a "correct" implementation must implement
C# language specification - it describes the form and establishes the interpretation of programs written in the C# programming language.
people can shapeshift the language? 😮
backwards compatibility is typically one of the most important goals when developing new standards
This is more low-level stuff, like making compilers and hardware work with the language I think
so stuff is typically added, not changed
no
that barely make sense that language with the same name have different functionalities
that's confusing
I can get that new versions getting new features
I interpreted is as different people made their own changes to the language so
and did not merge
well, that is how proposals work
but they don't really get added to the language until consensus is reached that it should be added
There's one standard by one authority, but multiple implementations that follow that standard
so what differences are allowed inbetween different implementations?
well, there isn't an authority "approving" implementations
technically they can have any differences they want
but if they don't follow the standard, then it's just not a full correct implementation of that language
sometimes there are some things that aren't specified, those can be different
some implementations can also add different features beyond the standard as well
like, that?
or also something bigger
sure, supporting different targets could be a difference between implementations?
How garbage collection works can be very different between runtimes, and can affect performance. The standard doesn't tell you how you should implement garbage collection, just that there should be.
standards define what should be possible and how stuff should behave, and oftentimes they give constraints, but they usually don't specify how to achieve those requirements
sigh
tbh i feel like you aren't really asking effective questions because you don't really understand what specs/standards actually do
that many different programming languages were already looking too elaborate to have
and there are different version of those languages
fair point
there's also different runtimes
eg in unity there's mono and il2cpp
well in Unity C# is used through mono, not as a language, right?
or how to call it properly
wait what's il2cpp
C# to C++?
C# > Mono > C++?
that's sure alot of layers to make a silly game running
c# is the language
mono is the runtime
c# is compiled to il, then... i guess converted to cpp. i don't really know how il2cpp works tbh
pretty sure it does not go through mono though
wait til you hear about syscalls and opcodes and d flip flops and jk latches...
technology is amazing
at this point are there even people who have a solid grasp on how all the chain and I mean all the chain technically works
yes, and they are the ones fighting in the nerd wars to determine the fate of future language versions
we honour their knowledge and nitpickyness
hey guys, im a beginner at unity vs code and i wanted to try doing a shoot them up on it. But idk how to make my player flashing when it's get dammaged
break it down into smaller tasks - detect the hit, make it flash
those individual tasks should be easier to research
i did something like that
Hello, im a beginner doing scripts in VS Code, and I wanted to participate this channel. Hope you guys to be respectful 🙂
well, does it work? if not, explain what the issue is in #1390346878394040320
no 😭 cause idk why but the player just stay invisible
i don't think that's how a for loop should work. #1390346878394040320 would be able to help you
https://paste.mod.gg/srigrszkuwmh/0
My obj is initiating but im not able to add force into it , somebody help me correct my code
A tool for sharing your source code with the world!
MovePosition takes a position, not a delta
also why would u use delta time there yeah
what does move position do btw?
well, that'd be correct if it expected a delta
when to use deltatime?
what is delta?
a difference
MovePosition doesn't take an amount to move, it takes a position to move to, as the docs say
you need to use the rigidbody on the instantiated bullet
whatever rigidbody you assigned in the inspector won't cut it
you'd probably be better off learning from a tutorial at this stage
😭
i have rigid on bullet but i don't use gravity for it
that doesn't matter
if (Input.GetKeyUp(KeyCode.C))
{
GameObject bullet = Instantiate(bullet, instpos.transform.position, Quaternion.identity);
bullet.GetComponent<Rigidbody>().AddForce(pushforce);
}
you meant to do something like that I think?
but I would rather do something like
bullet.GetComponent<Rigidbody>().linearVelocitt = pushforce * bullet.transform.forward
idk
@crisp quest you clearly don't have enough fundamental knowledge to start working on your own at this point
use the available resources instead of fumbling around randomly
might sound dissapointing but I agree
yea i have no-one to teach me so and I'm learning things from you guys so
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
there's that and also google
Brackeys and GMTk
i will try it maybe it is what i want so
nahh i dont want perfect code but idea , a ground to work on
no forcemode means it's continuous, which wouldn't work there.
it's not "imperfect", it's broken.
if you want a solid foundation to work on, go learn instead of copying
yeah... had a sense I forgot something
thats why i was messing with my code since 30 mins to figure out it by myself anmd then i came here to take an idea
wait what's default force mode?
Force
i thought if i do error and trials then code behaves differently then i might be able to learn practical usage of different methods !
no clue, continuous modes aren't supposed to be used in the update time step
so you'd rather learn 50 ways to do it wrong than the 1 way to do it correctly?
please stop making excuses and just go learn
you are wasting your own time here
hmm okay
that's not art (arguably), in code you meant to know exactly what you do before you do it
Noted ! i was thinking differently and wrong
trial and error does have its place. but you need fundamental skills and a degree of understanding to avoid the obviously incorrect ways
you don't have that experience yet
my trial and error usually comes from not knowing API well ><
it is actually time wasting , so better i should watch some tutorials and learn atleast what those keywords says
thanks guys to guide me
what would be places for trial and error
wait, not what I would want to ask
I always got a hypothesis and try out to code that
which qualifies in my head as knowing what I do before doing it
are there moments where it's not like that
reverse engineering sometimes, or when stuff isn't documented well, or when stuff is internal or obfuscated
those are just a few examples
you usually shouldn't need it
(in the context of getting code to do what you want it to, i mean. trial and error for something else like game design is fine)
kinda cursed situations but I see trial and error would be useful
trial and error would be useful in game design but not in the context of code . i guess that is what you want to say?
me? I mean that I see now how it can be useful at coding as valid approach
generally I mean
at making a game trial and error coding sounds like a bad idea
eh, who am I kidding, to make games it took me so much trial and error
through shitton of tutorials amolgamating what they talk about into my games
it feels like at any field at certain point you just gain enough knowledge from tutorials/other learning that it feels like you know what you are doing and new info no longer feels like new info but rather something to get integrated with already known system of how things work
before that point it feels like banging a head against a wall, after that point it feels like you are actually doing what you are supposed to do
I wonder if there is a psychology of learning or something which explains those
i guess if we have enough basic knowledge of any thing we are learning then the other thing which are related to it feels like easy and exciting to learn, as we learn capital letters and small letters of english then writing words with letter would become easy and feels creative to us (not easy but atleast creative )
human loves creativity, or you can say that we love to FEEL that we are creating or solving problems (i might be wrong of course)
I sure love feeling that I am creating problems
So, anyone can explain me how really works Player Animations, like an 3d Model ?
Sorry could you reword this to be gramatically correct
Hello! Question about interfaces, why use an interface to tell a script that a class "should" contain some data values such as methods or fields. instead of inheriting a class that already contains those values. sorry if thats wordered poorly.
Interfaces are more like "traits" and classes are more like "parents". You can have many traits but only one parent(s).
So things like "can be attacked" IHurt (or w/e), can blow up IExplode, can be disposed IDisposable, can check pointer events IPointerClickHandler etc
okay.... but what would IHurt contain? because if it had a method inside it for example wouldn't i be required to rewrite that method for every class that contains IHurt?
Interfaces don't actually contain fields btw. They're meant to promise that the type will implement certain behaviors.
search on rigging
would it be efficient to store a large tile map by using a custom class for each individual tile data and throw it into a 2d array, or should I use ScriptableObject?
for reference, I think the world is 1000x1000 tiles large and I'm not sure if a single array is efficient
Efficient for what? And how would you use a SO instead?
efficient to load the data I think. I haven't touched ScriptableObjects yet afaik and using 2D arrays was the first solution I had to reduce lag when loading chunks especially if I was going to increase the world size from 750x750 and my digging led me to this link which I was reading
ScriptableObjects are also C# classes, and they can also contain a reference to a class that you store the actual data in. So its just a matter of how you want to reference/store the data
is there really a difference?
from a performance standpoint, I mean. If it's very minimal, I think I'll stick with 2D arrays.
Again, how would you replace the array with an SO?
or should I use both
You can have a SO that contains an array, sure
I suppose store each individual array into an SO to draw it as a 2D array?
Are you modifying the array data at runtime?
probably not
It would contain functions and/or properties. It's essentially a contract/promise of what this object has to be made of. So yes you would have to add what the interface says to add. Here is a quick example that isn't a good case or anything, just a showcase of what an interface can do.
// pseudo code example
interface IHurt {
// could also have int Health { get; } but kinda icky imo
void Hurt(int damage); // a required function
}
interface IDummy {} // just a dummy interface
// notice one class, many interface
class Enemy : Mono, IHurt, IDummy {
int health = 100;
// realistically I'd have a shared Entity class
// with things like this, but just an example :)
public void Hurt(int damage) => health -= damage;
}
class TucanEnemy: Enemy {}
// can also virtualize it so inheritors of Enemy can change what Hurt does
public virtual void Hurt(int damage) => health -= damage;
// pseudo code example for input on a ui thing
// can have many IPointer* interfaces when needed
class ExampleUIElement : MonoBehaviour, IPointerClickHandler, IPointerDownHandler {
public void OnPointerClick(PointerEventData pointerEventData) {
// this ui thing was clicked
}
public void OnPointerDown(PointerEventData pointerEventData) {}
}
it's generated and barely touched afterwards
(except for the other noise generation that happens after the map is created)
The forum thread you linked to is about a specific asset that just happens to use ScriptableObjects. It's not something that's inherently built in to ScriptableObjects.
oh?
would the best solution just be to store the array into a scriptableobject or am I seriously overestimating performance issues
the editor lags when generating a 750x750 world and I'd rather it not freeze if I go over the 1500 threshold
You're getting hung up on the SO
2D arrays would be perfectly fine?
ScriptableObject is just a basic class that has some extras to integrate it with the editor
sometimes you may end up with classes just doing the same implementation of an interface but it really shouldnt be so frequent that this becomes a concern. If it is, that speaks more about the classes you're making.
you could always make some base class that implements the interface, and other classes can derive from the base class.
what would be a scenario where a ScriptableObject would be applicable? I thought it wasn't good practice to instantiate a new Tile every time it's rendered
I was just going to render tiles/chunks within a certain range of values rather than everything at once and thought a ScriptableObject would be more efficient
hey guys quick question about delegates:
if i subscribe to a delegate, and then recall it without unsubscribing, will it cause memory leaks?
I find that the tree gets nasty fast with inheritance whereas with interfaces, you simply add and implement the certain behaviors you're wanting. Both do get nasty but the first does so more quickly and is less flexible. A change of hierarchy or behavior would devastate existing code with inheritance whereas each interface would ideally be independent and valid wherever promised.
no.. yes..
It's not about efficiency, it's about convenience. You can edit SOs in the editor very easily because you can edit the values directly in the inspector and make new ones with the menus. If you use custom classes you'd have to make a custom editor extension to do the same or work purely in code. Efficiency is pretty much the same.
i think its like.. if both publisher and subscriber are alive.. ur good.. @astral cedar {fun fact, theres (4) Maik's in this server}
but if the subscriber gets destroyed but the publisher still holds a reference to it throu the delegate the GC cant collect its garbage
i could be totally wrong tho.. i remember someone telling me something like that
in this case it's not worth it because I'm not touching the tiles after, right?
not modifying them in meaningful ways ish
i always do
void OnEnable()
{
GameEvents.OnTick += HandleTick;
}
void OnDisable()
{
GameEvents.OnTick -= HandleTick;
}```
Can't tell if it's worth it or not for you
probably not worth it because I can always index the tile in the array and edit it from there. If efficiency's the same then that's fine by me
thanks for the help!
alright good
!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.
yeah i do the same too, but does the OnDisable trigger even if the object gets destroyed? i don't have time to test it
yes
think of it like Disabling first.. and then getting Destroyed/Deleted when u call Destroy() on it
same way OnEnable and Start/Awake get called
so as long as u unsub OnDisable() your always fine..
no leaks.. 🥬
alright thank you spawn
an update, i was able to implement most of the solutions you suggested me, and it works out. now, i only need to setup some sort of a delay to the bullets getting spawned cus there are way too many bullets spawning right now
any code to show?
public class EnemyCollision : MonoBehaviour
{
[SerializeField] string DuckTag;
private List<GameObject> EnemyList;
public readonly List<GameObject> PublicEnemyList = new List<GameObject>();
private void Start()
{
EnemyList = new List<GameObject>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == DuckTag) Debug.Log("Duck was detected.");
EnemyList.Add(collision.gameObject);
PublicEnemyList.Add(collision.gameObject);
}
private void OnTriggerExit2D(Collider2D collision)
{
EnemyList.RemoveAt(0);
PublicEnemyList.RemoveAt(0);
}
}```
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
public class ShootBullet : MonoBehaviour
{
[SerializeField] Transform prefabBullet;
[SerializeField] private Transform transformOfSpawnPoint;
[SerializeField] EnemyCollision enemyCollision;
[SerializeField] int BulletSpd;
private void Update()
{
if (enemyCollision.PublicEnemyList.Count != 0)
{
Transform bullet = Instantiate(prefabBullet, transformOfSpawnPoint.position, Quaternion.identity);
BulletMovement(bullet, enemyCollision.PublicEnemyList[0].transform);
}
}
void BulletMovement(Transform bullet, Transform target)
{
Vector3 direction = (target.position - bullet.position).normalized;
bullet.position += BulletSpd * direction * Time.deltaTime;
if (Vector3.Distance(bullet.position, target.position) <= 1f)
{
Destroy(bullet.gameObject);
Destroy(target.gameObject);
}
}
}
i ideally wanna try to figure it out myself, if you wanna give me advice, you can spoiler your message. chances are, i won't be doing any coding anymore today. my neck hurts like crazy
so rn you are spawning a bullet every frame and you want a small delay?
so like, currently, for every duck that's within range, i am spawning like 4 -5 bullets before the duck gets destroyed, so there are 3-4 bullets remaning undestroyed. i will implement a pooling mechanism later on
do you know how htey work?
ya, its basically a function which goes through all the functions or smth along those lines. i forgot the specifics
i will be able to implement it, i am confident.
cus i remember using it in some part of my code earlier
nice

yo so i wanted to animate my player and every time im jumping it clicking and going back to idle its like doing 0.1 sec jump then go right back to idle how do i fix it? also when i am in the air and i click again jump its working someone know why? where the code https://paste.mod.gg/inpklfhymvlx/0
A tool for sharing your source code with the world!
What are the conditions from jump to idle? What calls OnLanding?
oh its on the controller
im gonna send
A tool for sharing your source code with the world!
Seems like it's detecting ground after you jump and calling your OnLanding. Try logging the result of the OverlapCircle, or using debug rays or gizmos to visualize the circle.
https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Debug.DrawRay.html
https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Gizmos.DrawSphere.html
wait what happend i closed the animator tab and i try to re open it but its not showing the stuff i had on it you know how to bring it back?
\
select the animator you want to view
oh nvm btw when i run and jump its working
Good evening. I am trying to get my "Last 5 Messages" and its content to be displayed on screen. The first image shows the scene while the game is running and the 2nd image is the game itself. Can anyone give me some thoughts, tips, and tricks to figure this out? I have ensured the Canvas is operating at the highest layer
What do you mean by "the Canvas is operating at the highest layer"?
Can you show the inspector of one of your text objects?
Highest sorting layer. Screenshot incoming
Also can you show a screenshot of scene view after double clicking or pressing F on the Canvas object in the hierarchy?
What's going on with this Z position?
whoa!
changing the z value (manually while game was running) fixed it
now I need to see what happened to the z value in the first place
My guess is your code that instantiates them is incorrect
Make sure when you instantiate UI elements that you use the Instantiate(prefab, parent); form of Instantiate
(with the vertical layout group Transform as the parent)
Also make sure the prefab itself doesn't have any weird position values
I think I know what happened. I made a typo somewhere when I set those UI elements. Those 5 messages are static GameObjects based off a Prefab
I have some dynamically-created ones elsewhere
Thank you! My (latest 😉 ) problem is resolved.
hi
My Pac-Man gets stuck in a loop at the passage. Please help (I tried to screenshot but it didn't show the glitch so I took a pic with my phone)
The passages are placed at both sides right?
yes
It is obvious that when the character teleport to the other side, trigger the passage and teleport back.
For a quick hack, make the collider smaller + the teleport position far away from the collider
Maybe teleport next to the other portal relative to whichever side you're on
that worked thank you so much
!vscode
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
I got this reference exception
"UnassignedReferenceException: The variable _sphereCollect of CoinMagnet has not been assigned.
You probably need to assign the _sphereCollect variable of the CoinMagnet script in the inspector"
But the only _sphereCollect I have in CoinMagnet class is non-serialized and already assigned
private Collider[] _sphereCollect = new Collider[20];
Might want to share a screenshot of the error with its callstack visible.
This is far more of a rendering/shader thing than coding, but anyone know where I can ask for help regarding materials, specifically regarding workflows for characters with fur/hair?
I think I fixed it. There was an out-of-bound array iteration because I set i <= coinNum instead of just <
{
var returnCoin = _sphereCollect[i].GetComponent<Coin>();
}```
But I thought that would have to be a null exception, no?
It should.
Yeah, it threw UnassignedReferenceException somehow
So I made a 3rd person character controller, and I wanted to know where you guys put the camera in the player prefab's hierarchy? Right now, I have:
-Prefab Root (completely empty with only a transform)
--Player Object
--Camera
At first I thought about making the camera a child of the player object, but I decided to seperate them in the prefab.
I did this because making the camera a direct child to the player makes it so if you rotate the player, the camera changes position as a child object would. I want the player object to rotate without affecting the camera. Is there any better options? I ask because the Player Object needs access to the Camera and since this whole thing is a prefab, I have to go to the prefab root first and then use GetComponentInChildren from the root. It just seems like a lot and could be done better
For me, I use the Cinemachine Camera as a seperate game object and use the Follow component to, follow the player
Or u can try using Cinemachine. Basically it gives u virtual camera placeholders so u can switch between views
Time to go toy with cinemachine
here's the typical pattern for doing something multiple times, while also handling inconsistencies due to the period not syncing with deltaTime
||```cs
time = 0;
while (true) {
time += deltaTime
while (time > period) {
doThing()
time -= period
}
yield return null
}
yo somethings up with my jump
it detects if im on ground and all that jazz but when it gets to the actual action of jumping it doesnt do it
Does it print the log message?
yee its 3d
Either jumpForce is zero or very small or the normal movement code overrides the y velocity
Show the entire movement 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.
figuring out how to use the posting code thing
A tool for sharing your source code with the world!
does this show yall my code?
What's the value of jumpForce in the inspector?
12, heres the full set of values in case ya need it
rb.AddForce(transform.up * jumpForce, ForceMode.Impulse); this is a bit strange, if you zero out the global Y velocity then this should also use Vector3.up
oh sweet that might be the problem
but that would explain it only if the player orientation is wrong
huh
so like replace transform with Vector3?
yes
Next try to change the jump force to much bigger like 120 or 1000. You multiply all other forces by 10 as well but not this one
aight tested the jump force at 50 and 1000 and no change
how's the rigidbody set up
you've frozen the Y position
//Does anyone know how i can apply a enum to equal to a another int? you can do
//You can do
int testInt = 1;
enum testEnum += testInt
//But you cant do
enum textEnum = textInt //Error! since it thinks i'm trying to turn enum into a complete int
if (Keyboard.current.rightArrowKey.isPressed)
{
if (selectedAction < 3)
{
//Change action +1
selectedAction += 1;
}
else
{
//Wrap back to 0
selectedAction = 0;
}
//Error here
currentAction = selectedAction;
print("Right Pressed");
yield return new WaitForSeconds(pressDelay);
}
Oh. Lol.
This is just annoying. It would be really nice if i could just swap between enums
the way enums are ints is not minimal enough for there to be a single expected behaviour from int to enum
currentAction = (testEnum)selectedAction;
can you give abit of context on what you wanna do here
Yes i can. i'm trying to make a menu here that swaps between current actions
When you press the right or left arrow, and i need to wrap the actions back to eachother
Actions is an enum, not a method 🙂 So you need to cast your int to (Actions)yourInteger
And be sure to give your enum values actual integers attack = 0, and so on. because if you gonna extend them and want to reorder, your integer values are still valid
Sadly i've already tried that.
currentAction = Actions(selectedAction);
oh wait i did it backwards.
🤦
Oh my god it works.
actions goes to the inside 
That's so confusing lol! thanks alot. I really gotta learn these enum rules properly.
it seems essential for everyday use
Its just Method("YourParameters") is always a method, (YourType)yourValue is always a casting against YourType
ahh yeah it's like a reversal cast
i get it.
I have not touched casting at all. and this is what happens when you're unfamiliar with it. Glad there are some experienced people here that know their stuff xD
Again thanks alot.
😃
Hi guys
yo
!ask
: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
and make sure to use the right channel, this is a code channel
Yes I get that
a hell of a lot of people dom't 😬
Meanwhile could you tell me , is it possible to make realistic water in unity using code , like simulation of physics and stuff
If i walk into it , the waves like dislocate
I feel like most of them just read "beginner" and ignore the "code" part lol
Idk how to frame the question
Its like going inside a pool
And you see water displaces
You'd use a shader, there are a lot of them out there that do all this already
Ye i checked out visual scripting and this one. I think you could use both right
shader questions go in #1390346776804069396
Oh i thought youd use like fluid physics or whatever , cause i used basic render pipeline and all shaders were hdrp
Sorry
I didnt know it was shader based only

tis np, was just an FYI

there's no render pipeline called basic - I assume you mean URP?
Ah not that, 3d something , the first one
oh, the built in one?
Built in render pipeline
Yes that one
Built-in RP, the old one that is slowly becomming redundant
I chose that one cause i thought it would be easier
There are shaders that do what you want for that
Vector2 lookInput = inputSystemActions.Player.Look.ReadValue<Vector2>();
I think lookInput is framerate independent? So we dont need to multiply deltaTime with this right?
Mouse and controller stick input is framerate independent, yes
mouse delta is per frame, controller stick input is not
why it is happening and how to solve this
Its warnings, probably due to an editor update and you might need to update your packages. Read the warnings, they actually tell you whats wrong.
I got a classic issue "weapon fov is not the same as real weapon fov" while shooting projectiles (and honestly while making bullet trails too)
Is there an equasion I should use to shift an actual shooting point (it's non multiplayer fps so I don't think there would be issues) so it looks valid from first person perspective with low fov of a weapon? Or there are better solutions?
let me ask AI then
i'll ask AI and tell ya what was the prob
i ain't gonna spam tho
my I ask what is the context when you started to get those errors?
you just said you were gonna spam AI bs
they aren't errors anyways
they're just warnings
you could ignore them
it's internal too, not your own code
you could try a library reset if you think it might be mismatched versions
but i'd guess VS is just picking up warnings from places it shouldn't
I dunno I won't ignore "value never assigned so always null" kind of thing
maybe you just opened an internal file and VS started analyzing
VS doesn't know what SerializedField is. it can't analyze reflection.
nah i didn't
they're all internal, so you can't fix them anyways
so should i just ignore them?
you could, but they could be obscuring warnings related to your own code
what did you do when they started showing up
is your ide configured properly
i was just making my code , nothing much and when i saved it then it started showing up
do they show up again if you restart vs
https://paste.mod.gg/aioyhkvtksyf/0 this was my code
A tool for sharing your source code with the world!
let me check it
VS just got updated and now it is fine
there was an update pending , i guess that was the reason
That might make the job done I guess
mainCam.ViewportToWorldPoint(fpCam.WorldToViewportPoint(point))
It's annoying that I don't actually have a second camera to use but caching will do, no idea how does this work internally mathematically
what was that attribute for a method so you can call it from the editor any time?
yeah first one thanks
can someone help me? im trying to reference another script in a script and im getting the error "The type or namespace name 'PlayerMovement' could not be found (are you missing a using directive or an assembly reference?)"
i have a script named PlayerMovement so idk why its not working
Use the exact class name and if its under any other namespace add it using <namesoace name>;
Hello, I have an issue to change the game resolution in HDRP
I tried to write a post in unity's forums, but, I'm not sure people go in there ^^"
Basically, calling Screen.SetResolution might cause crashes or freezes
I'm using Unity 2022.3.62f2. And I managed to reproduce the issue in the HDRP sample project without changing its settings (apart from adding the scene I made).
--> Hence the following questions: Is it a known issue ? Is there any workaround ?
I'm writing this in Beginner as I believe this to be a basic feature? (maybe I'm wrong?)
The simple script that reproduces the issue:
https://paste.mod.gg/ptotvlrcbkqk/0
!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.
In case the message gets lost in discord's thread, I've copied the message here: #1445446615883055155 message
Hey guys I have a built in project I wanna change to URP. I have a massive built-in particle pack
I can't remember, is it reliable to convert all shaders to URP?
I remember that feature existing but not actually working for 90% of them
Edit: wrong channel my mistake
how is that related to coding?
Maybe try it and see what happens. But yeah wrong channel
Oh shit my bad lol, thought it was a diff channel
I am trying to make a teleport script but the player stops at the first wall because of the Rigidbody, how do I still get it to teleport? (I've tried setting it to kinematic before the teleport and then back but that didn't work)
show relevant code. because it doesn't sound like you are actually teleporting it
set the position
rb.position = newPosition;
you kinda can't not use it
the first O in OOP is "object"
this covers classes and structs in c#, along with the native classes and structs in c++ land
C# is strictly object-oriented
c#'s object type and unity's own UnityEngine.Object should also give some hints
im trying to make a basic sword thing for my game and to get it to point forward i have a child object with the texture at rotation -45, but for the animation to work, im trying to set the rotation on the Z axis back to 0, then after some time reset the Z axis rotation to -45 again, how would i go abt doing this?
i tried changing the transform.up and even tho it does change the rotation, it does it weird and not at the specific rotations i want it to set to
!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.
https://paste.mod.gg/esmjqstyuafi/0 like this?
A tool for sharing your source code with the world!
weaponTexture.transform.up = new Vector2(0,0); setting up to the zero vector is nonsensical
oh alr
You need to give it an actual direction vector
so like (1,1)?
sure, that's a direction pointing 45 degrees up/right
Yeah the thing is it ends up looking really scuffed
i dont know why its doing that since its not the gameobject being rotated torwards the camera
because you're hardcoding the directions and using them regardless of which way the player is actually facing
first off you probably want to be modifying the localRotation of this thing, not world space stuff.
.up is a world space thing
oh okay, how does that work
you do myObject.localRotation = <some quaternion> or myObject.localEulerAngles = <some euler angle vector>
i got it to work now tysm 🙏
Is there a place where I can look over certain terms and variables and stuff and see what they mean?
!api
There's no command called
api.
!docs
i could've swore there was a separate api command. oh well.
anyway @ionic sorrel the api documentation sounds like what you are looking for ☝️
This actually helps a lot! Thank you, I'm new to all of this 

Note that these pages only cover Unity specifics. You can find C# documentation on Microsoft's site https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/
Thank you very much c:
should i be putting this in #1390346776804069396 ?
im gonna guess yes, gimme a sec to do that
done
is there a way to make the editor (not build) open a specific scene when you first open it? (instead of most recently open scene)?
You could have a static class that runs once and loads your scene and then never runs again, using sessionstate for example
hello this might not be the right channel but maybe it is. i have this mixamo animation
where the guy runs
but the end of the animation always resets back into the starting position even when i loop
do i have to write a script in order for it not to go back to starting point?
i guess you could, but it'd be easier to set this up with the animator system. try asking about the issue there #🏃┃animation
and show how you have stuff setup
wrote that in there
thanks
Can someone please help me get Depth of Field working in my 2D game? I thought switching to orthographic camera would help, but it seel doesnt really work?
The frontmost sprite shouldnt look blurred at all, changing the settings in the effect itself doesnt help that
Here's how it looks without depth of field
This is a code channel. Ask in #💥┃post-processing and be sure to checkout the manual as well. https://docs.unity3d.com/6000.4/Documentation/Manual/urp/depth-of-field-volume-override.html
Oh, sorry!
I checked the manual, but it didn't have anything about 2d as far as i've read
Check the different modes and play around with distance options. 2d objects like sprites also can be positioned at different distance from camera in 3d space and probably are a subject to this post processing effect
I think it's the issue with how 2D stuff is handles specifically, i tried adding a 3d cube, and it worked fine on that one
the modes & settings don't change much, all the 2d sprites appear equally blurred regardless of Z distance
Alternatively you can render different distances with another camera. Because effect does work just doesn't seem to respond to distance. (to have another post-processing volume applied to it)
That would probably work, but that sounds very unwieldy? I would need to add a new camera for every layer
this feels like something that should be easily fixible, but i can't find anything. Most of questions/posts asking the same thing are either super old, or dont lead anywhere
and i doubt it's an uncommon problem? quite a few 2D games use depth of field
"elementaddermenucommandattribute" could not be found and idrk how to fix this
theres the full console log
same for this too
the return part
if you're not using visual scripting, remove the package
but its not in unity anywhere
using UnityEditor;
this makes no sense, what?
yep
Can anyone recommend good tutorials that are like "Follow along as I break down this idea?". Most tutorials are usually predetermined about the approach and final result, but I'm looking for something where I can really get into the mindset of "Here's the problem and here's how I would approach it"
It's abit high level but sebastian lagues ideos might scratch that itch
I'll check it out but can you think of anything more specific? I'm quite new to C# but am comfortable with python and tech art in maya. I'm just trying to translate that line of thinking/approach to unity and C#
Honestly not too much I know of that fills that demographic, I wish there was a lot more
You're unlikely to find beginner level tutorials that are like that because any experienced Unity coder wouldn't have a problem with implementing basic stuff
Devlogs or VODs of devs who stream their work might be the closest
I'm not necessarily looking for beginner level (I realize I posted this in the code-beginner channel 😅 ) . I'm fairly comfortable working as an artist in unity but am just finally getting into c#
https://catlikecoding.com/unity/tutorials/ Has very detailed follow along tutorials. But it's more focused on a technical concept, like making a hex map ready for game play.
Sebastian lagues sucks at giving details to what he does, at least in my opinion though i havent seenone of his videos in awhile
This is perfect! Thank you! I'm just trying to hone my skill of "Here's a concept, how do I build it?". I wanted to focus more on specific goals instead of one big overarching game. I usually prefer articles to videos anyways.
He has additional notes on the process as well and there's a lot of insights into coding technique and tooling as well.
I would recommend his Hex Map tutorial just for learning coding even.
I'll start there then, thanks again!
I was tying to make on sprite the litle robot appear in midle of the dialog but i evean wont start the dialog can someone help me with it?
that's not much context to go off of
are await on async same as coroutine?
will send you code
no
they can fulfill the same needs or solve the same issues, but they aren't the same, no.
A tool for sharing your source code with the world!
what we need is more context. what's the overall flow you're trying to achieve, what part are you having issues with?
ahhh
so... i guess i can use coroutine on everything that need async yeah? I'm currently using database now
the isue is that when i am trying to activate the diualog it wont activate
coroutines aren't exactly async, but if whatever you're using to interface with the database works with coroutines, then sure, you can use those
i was trying to activate sprite when some line will be activated and trurn off the sprite when the achive other line
start debugging, at which point does it stop working?
check if your state variables are as expected, see if the coroutine is being called
you aren't giving dialogueManager any info, so i'd guess that you're reaching that point fine, but then dialogueManager just.. doesn't have anything to work with
but you'll have to debug to confirm that
im using coroutines, haven't had a reason to use others yet
coroutines
there is also another, unitasks
if coroutines aren't feeling great to use, then try out the alternatives
decide for yourself
ok thx
Hey! Does UI toolkit world space support events? Trying to add an eventlistener like this Head.RegisterCallback<ClickEvent>(ev => HandlePlayerClick());
But it doesnt seem to register clicks.
Works in my other UIdocument which isnt world space.
Sorry!
I may need some help with some of my code, would anyone here be willing to help me a bit?
!ask
: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
and especially that last point https://dontasktoask.com
people are, for the most part, not going to agree to help without even knowing what you need help with
Well if that is the case... Then I'll say it. I am trying to program platforming in my project. It works for the most part... But with the jumping mechanic I implemented, it is allowing the player to jump infinitely... Even while in the air.
I'm not sure how to fix this.
well first off, you haven't saved in that screenshot
also your ide is not configured
!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
anyways, the issue is that a || b && c is the same as a || (b && c) due to operator precedence.
you'll need some parens.
Honestly... I never knew this was a thing :O
Parens?
parentheses
Oh :O
"parens" is a common abbreviation, typing the whole thing out gets pretty tiring lol
Gotcha, I'll keep that in mind 
you might also see "semis" for semicolons
Okay c:
Sorry about all of this... I'm very new 
This is my first time hearing about a awaitable. Have you used a coroutine before?
yes. I'm testing them now
Yeah... I have no idea what this means 
just use ( ) to group
what's the value of 1 + 2 * 3
impossible
I have isue with that i have sprite that should deactivate after the line in dialog but it dont takes number after 39 in the condition here is my code
A tool for sharing your source code with the world!
do you mean this?
if (i >= 19 && i <= 42)
Robo.SetActive(true);
else
Robo.SetActive(false);```
yes
I still don't know what that means

I'll come back to it later.
...do you know math
do you know what 1 + 2 * 3 is (im expecting you do)
It has a robot sprite that is supposed to turn on on line 18 and turn off on line 42 but when I put it there it doesn't deactivate when I put a shutdown number below 40 it turns off fine but otherwise the dialogue has 45 lines
if i is higher then 42 guess what happens?
6? or 7? depending on BODMAS or PEMDAS
it does not depend, no.
how do you even get 6 there
the wrong answer is 9
3*3 =6
it wont turn off the sprite?
.....you sure about that?
There are only 39 lines of dialogue in the code you shared
it starts on line 13 and ends on line 52. 52 - 13 is 39
that'd be 40 lines
so when you put a number higher than the actual number of dialogue elements, yeah it never reaches that number so it will never shut off
... you might want to give that another go
whatever, same issue
ohhhhhhhhh i am so dumb
sorry for waisting time
I highly recommend not using magic numbers in your code
your ide can also tell you how many lines there are if you select them all
Also "BODMAS" and "PEMDAS" are the same thing just one of them is british
ok thx
oh
There's not different ways to do order of operations. Math is math. Whatever you call it the order of operations is absolute
No, there is no "it depends". There's the order of operations, then there's incorrect math
So... What exactly would I be grouping? 
I have never programmed anything my entire life. I don't know what anything means 

if ((input1 || input2) && isgrounded)
Oh! I think I get that :O
do you know what 1 + 2 * 3 is
* is multiplication here
god i don't have the patience for this
it's 7, and it's not 9 because you do the * before the +
that's what operator precedence is
you do && before ||
but you can change that with parens
|| is for either of statement is true and && is for both to be true
Anyone found a way to disable this extra 'Unity Serialized Field' text that appeared after latest vscode extension updates?
Theres a lot of unnecessary text on my screen now above every variable and method.
I do like to keep the number of references though
there is no direct setting for that ithink
🤮 at least they fixed some of the performance issues.
I had to literally close vscode any time I wanted to compile or enter play mode, otherwise 30+ second wait
now its fine, but this text is really hard to ignore
that's called codelens, you should be able to search for it in settings