#💻┃code-beginner
1 messages · Page 806 of 1
i feel like the only reason my particle collisions isn't working is because of this stupid z component
what the " z component " unclear what that even means
as in the z vector component
position.z
Z isn't a component
i was imagining using kinematic for the player and dynamic for the NPCs and stuff so he can knock them around and stuff
no more like, position is basically like a vector, so z is a component of that vector...
i understand what you mean by that though
it can also be switched on the fly or sim the reaction hit too
i see
wait a sec, do i need to attach a collider to the particle system for it to detect collisions?
so what is the issue, unclear whats going on
didnt read the full convo but did you enable the proper callbacks from the particle event system
this one or
this ends up happening in that case
the particle collides and then moves away, but it still doesn't trigger onparticlecollision
collides with what, also you should enable gizmos AFAIK it should show more
and does duck have a collider
i think it collides with the duck? cus when i have plane enabled, the particle stays in the same place but when i enable world 2D, it goes upwards
yes, it interacts with bullets fired by other units
you copied the code here?
https://docs.unity3d.com/6000.3/Documentation/ScriptReference/MonoBehaviour.OnParticleCollision.html
must either go on the Particle Sys gameobject or the duck
I have a question regarding the sprite editor, how can I edit the animation to start from right to left or move each slice individually? basically want the animation to run in reverse
this isn't a code question
thanks !
using Unity.VisualScripting;
using UnityEngine;
public class ParticleCollisionScript : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void OnParticleCollision2D(GameObject other)
{
Debug.Log("Particle Collision Detected.");
Destroy(other);
}
}
```The above code is attached to the gameobject having the component particle system attached
i also have it attached to the duck (the enemy which the particle is supposed to collide with)
uh where does it say to write "OnParticleCollision2D"
i remember OnParticleCollision not working, so i was like heck, why not just try out 'OneParticleCollision2D;
it should work you probably had something disabled like Send Collision events / World 2D
also a bit concerning you're moving a rigidbody with A Spline Animate
you should probably use the spline only as path but move with rb.velocity or moveposition from the spline path
don't tell me to go back and change it, i will have to rewrite a lot of code to make it work...
pls i beg
aight fine, i will try fixing that too, but i want this fixed first, is there anything i could be missing out on?
first test a simple rb with collider that doesn't move, see if you can get the message to popup
this way you can narrow down the problem better
I have two collisions which should be happening, first, the unit's range collider collides with the enemy, which triggers a collision, which makes the particle system emit the particle. this particle is then supposed to trigger collision with enemy and pop a msg. I tested it with a static rb, turns out, only the first collision is detected
are you emitting particles to the non moving object so it hits it? also put the script on the Particle System gameobject
i am manually controlling where the object is at, so that the collision is detected. and yes, the particle is overlapping with the object to be destroyed. although, now, instead of the object being destroyed, its the gameobject holding the particle system which is getting destroyed
💀
so this runs?Debug.Log("Particle Collision Detected.");
how else is being destroyed
make a vid of new setup if possible so its less confusing
wait, my pc potato
if that line is running that means Particle system is doing the correct thing... the issue may be you moving the duck via teleport / transform instead of physics.
i am using spline animate
yes that basically teleports / moves the transform and bypasses the physics.
oh, i did not know that
its detecting it though 🤔
ya lol
probably moving slow enough to catchup
hey I have a game that I've finished and it works great in editor, but as soon as I build it the framerate drops insanely. it's got a lot of non-convex static mesh colliders, so that could be it, but I don't know how to make it run as well in the build as it does in the editor
Am I correct to assume that is i created a chunk generator to generate 16×16×64 chunks with caves underground and flat above could I technically just use my cave setting in reverse to create mountains and floating island above instead of it being just flat? Havnt done anything yet just brainstorming
Use the profiler to investigate the bottleneck in the build.
trying to do that now, but I'm not sure how. the build is running but the profiler isn't doing anything
You technically could, but it would look good probably. I'm ght want a height map based approach for the surface.
oh I needed to put it in edit mode
No.
First of all it needs to be a development build. Then you actually need to make sure it's running(in the foreground) while the profiler is attached.
attached?
the build is running, and the profiler window is open
i don't know what attached means though
you should still look into moving it correctly via physics and not transform
It seems attached in your screenshot. It means that the profiler is connected to you game.
needing to convert spline space into world space
do you have to open it from the build? the editor window isn't doing anything
Is the window in the foreground?
yes, i will, another problem i am facing is when the particle and enemy collision occurs, the particles moves away. i tried reducing the bounce to 0, but the particle still moves away from the duck
it's not windowed, it's fullscreen, but tabbing into it doesn't put any data in the profiler
no matter what bounce is, it just keeps moving. even if the trigger is checked
Did you build it with these toggles checked?
yeah
why you put bounce on lol
So what does the profiler look like after you tab into the game and play a bit?
if i tinkerwith every property, i might just be able to fix the problem...
You need to select your game process as you did earlier. Not play mode - this is for profiling in the editor.
ok, got it working, now what am I looking for?
is it just way too intensive for cpu only and it's not using my gpu at all?
Go read the docs about the basics of working with the profiler. Once you get the hang of it, share a frame data(hierarchy sorted by time).
if you set as trigger it shouldnt move anywhere..
This does seem weird. Something is throttling your GPU.
Is that data from when the process/window was active??
Or do you have it collapsed/in the background?
Your game will not run/update/render if you alt tab out of it(making it go to background) by default. If you're doing that, it would explain what you're seeing in the profiler.
use Triggers instead of "Collisions" maybe
its been a while since i used PS
i will try it later, the sound my pc is making is kinda scaring me
that explains the spike, it doesn't explain why even when the spike isn't happening it looks like this
Can you maybe play the game for some 30 sec then come back to the profiler?
Or are you saying it's so slow that it's unplayable? Less than a few frames per sec?
yeah like 1 frame per 3 seconds
and 99% of it is this
Yeah, that sounds like an issue. Are you running on a laptop or have several gpus on the pc?
laptop with 2 GPUs. unity was bugging out and kept crashing whenever it would switch between them, so i disabled one of them
that's probably related
but weird that the editor works perfectly fine
Possibly. If you can, try it on a pc first to eliminate hardware/env factor.
Well, I'm at work, so can't really test it now.
oh gotcha, i'll get my friend to try his computer
Anyways, the issue is very likely in your laptop and not unity or your project, so maybe investigate in that direction.
One thing to try is to specify the gpu to be used for the program in your GPU control panel.
Hi so I'm using the unity tutorial for Roller Ball and my code is not working. I followed the tutorial every step of the way but I keep seeing that my movementVector.x and movementVector.y is wrong. I need help as to why this is not working
Sharing the code what you used would be an obvious starter, nobody can guess a solution otherwise.
!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.
!screenshots
No
Be mindful, if someone requests your code as text, don't send a screenshot!
and you're literally trying to use variables that do not exist
But I’m using the tutorial
yeah and you're copying it without looking correctly
You gotta try pay attention to what its showing and why it is a certain way
I was copying it correctly and trying to pay attention to what is showing. I even paused it and then went back
even with garbage photo capture instead of a proper screen
look at those 3 lines
try to make sense out of what is trying to do
even without understanding the code, the words don't match 100%
I’m very new here and trying to learn coding.
I understand but most of this issue isn't even a coding thing
its compare and find difference
do you believe movement and movementVector are the same ?
do you think red and redWine are the same thing ?
forget the code, this is literally words
numbers ? 1 isn't the same as 11
tbh this tutorial specifically is not so good to learn coding, cause it expects some level of beginner c# n mostly you're copying..
I'd recommend something like this
https://learn.microsoft.com/en-us/shows/csharp-fundamentals-for-absolute-beginners
and some unity / c#
https://learn.unity.com/course/beginner-scripting
Hi i need some help currently I am trying to create a game that simulate fixed wing drone flight and I'm doing it by applying force at position using RB but I am stuck at the part were I have to calculate the lift direction as I need the lift to be always be perpendicular to the wind no matter the rotation or position but don't know how to do that tried AI and all but that made it more confusing as so sayes to use cross of vector 3 and -local velocity. Normalized and some give direction after adding in drag need help
Obligatory ai eww
Are you using 2d or 3d?
Wdym "cross of vector 3"? Surely that's not what it outputted?
Actually ignore that question; have you tried looking at the AddForce documentation
3D
Yes but there is not much in the Addforceatposition
And sorry for the late reply
Vector3. Cross to get vector that is perpendicular to 2 given vectors
CrossProduct of what vectors though?
The -ve normalized of local velocity to get the wind direction and the vector3. Right
Anyone know a good solution to reduce garbage from sorting out an array?
I just needed to get a list of RaycastHit's sorted by distance, looks like everyone would need that, yet doing it every frame on many objects I get about 1Mb garbage
something like that:
public class RaycastComp : Comparer<RaycastHit>
{
public override int Compare(RaycastHit x, RaycastHit y)
{
return x.distance.CompareTo(y.distance);
}
}
public static RaycastComp raycast_hit_comparer = new RaycastComp();
int howmanyhits = Physics.RaycastNonAlloc(shooting_center.position, target.coords - shooting_center.position, hits_cache, Mathf.Infinity, check_clearance_mask);
if (howmanyhits != 0)//if we hit at least something
{
Array.Sort(hits_cache, 0, howmanyhits, raycast_hit_comparer);
}
Do I need to, like, copypaste, I mean, write my own sorting algorithm or something? Can I cache something?
Reading on random sites I see they advice to use comparison instead of a comparer, is that the best I can do?
oh no, Array.Sort don't have an overload for comparison and indexes
public static void UpdateHp()
{
_hpTMP.text = ($"{GameStats.playerHp} / {maxPlayerHp}");
gameObjects._hpHand.transform.SetLocalPositionAndRotation(new Vector3(0,0,0), Quaternion.Euler(0f, 0f, ((maxPlayerHp - playerExp) / maxPlayerHp) * 360));
}
the rotation isnt even changing and im not sure why
Use logs , start with the values
lift is perpendicular to drag, and drag is given by angle of attack
im using TMP as logs
no clue what you mean by "comparison" instead of comparer. comparison is an action, not an object
Array.Sort is documented as being introsort, a hybrid between insertion, heap, and quicksort
of these, only quicksort uses auxilliary memory, so it would probably be that
you could write your own sorting with some other in-place method if you want to reduce garbage, i guess?
How to reproduce:1. Open the project attached.2. Open the "SampleScene" scene3. Make sure that Scripting Runtime Version is .NET 4.x...
is it actually causing problems for you
I dunno because I can't even compare comparison vs comparer
because "The issue is that there is no analogical Comparison<T> overload for the Sort<T>(T[ ] array, int index, int length, IComparer<T> comparer) call - therefore, the only solution is custom sorting code"
oh so a comparison is just a comparer but as a delegate... funnily enough one thing where how java does it is easier to use lol
honestly im not sure how using a delegate instead would make it allocate less
the allocation comes from the sorting algorithm, not the comparisons
"GC allocations from creating a delegate wrapping the comparison object"
so like each time comparer create a comparison delegate?
doesn't the compiler already optimize this anyway
famous last words
the comparison object is a delegate, this doesn't make sense
what is the end goal for this? maybe you can even avoid sorting at all
https://discussions.unity.com/t/case-1138093-array-sort-allocates-112b-each-time-it-is-called/736050/3 well unity guy saying use comparer to avoid extra garbage
are you just calling comparers and comparison swapped
possibly you're doing something else wrong if the amount of garbage is causing you to run out of memory
I prolly can this time but in general for shooting and stuff I think I could use knowing a better way to sort hits
do you care about allocations only when you running out of memory?
there is no reason to hyperoptimize something that doesnt actually make a difference
I think that is incorrect. List.Sort says it uses Array.Sort. there's no Comparison overload for Array.Sort. the reasonable explanation would be that it's the Comparer overload that's "canonical" and the Comparison overload in List uses that.
well, 1mb of allocations per frame should have a visible impact depending on platform
and it should cause a lot of fragmentation, it definitely should be avoided
oh wait, Array.Sort does have a Comparison overload lmao
i overlooked the "show more" here 💀
so arbitrary 😔
ooh, the overload you're using isn't generic either. maybe there's some boxing going on as well, since RaycastHit is a struct
can you use RaycastNonAlloc?
they already are
if I was using with alloc I had no issue of not having an overload with indexes
nevermind i had a typo
i think i might see the overall picture now, though i'm unsure (and frankly i'm not too experienced with the internals here so i have some doubt at every step)
- the overload you're using is non-generic, and
RaycastHitis a struct, so there'll be allocations for boxing - the overload using
Comparisonis generic, and wouldn't have those allocations
so if i'm understanding it correctly, the difference isn't inComparervsComparisonexactly
I mean I can likely reduce the number of calls by like once each 0.2 sec or avoid using it at all somehow
still
the simple task of sorting an array of raycast hits should not take that much allocation, I think I have to find a proper way to sort it or write my own
the fastest way to sort is to not sort at all if you don't need it
so, what's the end goal for this?
idk forum and issue tracker don't specify what is being sorted and confirm that comparison > comparer
if you just need the first or last one for example, that would be an O(n) time O(1) space operation
they don't give reasons, and the forum message contains an "iirc". there's no "confirmation" there anywhere, just a claim.
depending on the amount of elements being sorted, you could get away with some pretty dumb and easy to implement sorting algos
if you cannot just get the first/last one
-# bogosort for 3 elements let's gooo
how bad could it be 👀
anywhere from [0, inf) iterations
I use raycastall for 2 things
first is shooting, and it have unreasonably meaningful penetration mechanic taking into account different body parts and order of them being penetrated
second is checking if the target is in reach, which is a pretty dumb case yeah
(I can't raycast once because that ray need to go through other possible targets like if they are blocking the target it's still need to be valid)
just so we're on the same page -
- you're referring to this specific RaycastAllNonAlloc being used for 2 purposes, right? not separate raycasts
- the second one here wouldn't require sorting, right?
second would require sorting because it can also hit a wall at any point before meant target
I am not sure what you mean by this specific, no, they are in different scripts running at different times from different points
you can check for that without sorting
so what is this one for
the one you posted about
code piece I copypasted look the same for both
the second wouldn't even need raycastall 
have a raycast that's the distance to the target, masked for obstacles, if it hit some obstacle then you can't hit the target
but yeah i can see how sorting would be ideal for processing the first case
imagine if there is an enviroment with walls
and there is a crowd characters (they all have same layer)
I want to check if one particular member of the crowd can be reached
through other characters would also be valid
yeah the raycast just wouldn't account for the other characters, that's why i said masked for obstacles
i guess that was ambiguous, i meant having a mask that would only have it hit obstacles
(this isn't super relevant to your original question, just kinda thinking out loud. we can go back to the original question if you want)
Raycast against a specific collider but also accounting layers?
raycasts always account for layers
oh wait 3d has Collider.Raycast, i'm not referring to that one
Physics.Raycast
I don't see anything I coud use
that raycast would hit other characters because they are on the same layer
i'm referring to a raycast that would not hit any characters
i guess it would need a Collider.Raycast first to determine the distance
the distance is known beforehand
since I know against what agent I am checking hence I know position
the max distance, or the distance to the collider?
you wouldn't want to cast only at the pivot though
i guess it's hard for me to say without knowing the full picture of what the input data points are
it's just a condition for a mob if he is within target reach
so he can start backpedaling
won't make sense backpedaling if target is behind a wall
what if that wall is waist height
still backpedaling
i definitely have the wrong picture in my head about what the scenario is lol. i can't make useful pseudocode for that, so i guess this is for you to design lol
if you check for a LoS just to the pivot of the character, it might hit the wall even if a large part of the character is exposed
honestly fine with me
that game have pretty basic leveldesign and AIs
ik ideally I d need to have several points on a target to check against but...
how about checking for a tag/interface
that doesn't seem helpful for the situation tbh
I do check for an interface already
now I should't tho
just raycasting only against obstacles is simple yet clever
you could probably just have like a raycast from the head and then from the waist or something like that
would probably be good enough.. i think
I just need that thing to know if player is in LoS to decide if it need to backpedal or push forward (there is also code checking for angles, and other stuff I don't really remember...)
like if it's too close it needs to backpedal
unless no LoS
this is a gentle tank it won't crush you it keeps distance
I highly regret deciding to just make a reasonably smart tank in a simple game
at the same I don't because look it works, what a waste of time tho...
i wouldn't call it a waste. looks good so far . . .
guys what course would help me understand C#
check the pinned channel messages
Try C# Training course on microsoft learn. The docs are best for learning and deeply understanding C# but maybe they feel boring
hey I just posted a query in the Code-General for Weighted Randomiser system. Please if someone could help me with that It will be of help. :3
quick question, is there any easy way to learn how to convert old code to the new unity input system?
"easy" is subjective, the most effective way would be to learn both
thanks!
hi guys, New here, I have a question about a code not working right(probs new user error) is like 10 lines of code, it is supposed to give me camera rotation with the Horizontal input but is going opposite. non of my values look negative , any help?
You haven't shared anything that can be helped
sorry still figuring it out. here is the code
using UnityEngine;
public class RotateCamera : MonoBehaviour
{
public float rotationSpeed;
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
transform.Rotate(Vector3.up, horizontalInput * rotationSpeed * Time.deltaTime);
}
}
the issue i have is that when i press a or d to rotate is going the opposite way.
!code and check your input values maybe
📃 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.
thank you i was looking foor that
then multiply the input by -1
or just set your rotationSpeed to be a negative number in the inspector
got it that worked i changed vector3.up to down.
That will work too
can anyone help me get it so that my tiles strech and fill the my grid ? id send my code but idk whats the best way to do it ?
it seems to be using the grid size for scaling but it doenst conform to the actual grid
You can adjust cell size on the tilemap.
thats cool and all but.. i need to to jsut stretch to match the grid cell size... and also the rotation isnt takeing etiher
If you are using flat tops you should just adjust the tile
i meed it to just take the orienttstoon and the size of the grid genorsted but ya i should prob just stick to one orientation
that still doesnt fix the fact that it doesnt tile to the grind correctly
but ya ill just make it flat tops only
Adjutst pivot point on the sprite to match pivot used by tile grid
Or change tile anchor on the tilemap
cool ill figure out how to do thag
i tried just changing it in the little drop down to "center" but it was imfact not center
Also this is a code channel. If you have further questions you should ask in #🖼️┃2d-tools
this might also be bcs im trying to get 2d tiles to work in 3d
its fine to use it this way but in the past I made my own hexagon grid because i wanted to change the offset to be opposite
Say I want a list of Actions that all have different parameter requirements. For instance I have a list that points to a Brave() function which takes no parameters and an Attack(Combatant attacker, Combatant target) which takes two Combatant object parameters. How would I go about putting these in the same list especially if I don't know what I want the two parameters in Attack() to be yet (as that is intended to be what the function I'm passing it to is meant to figure out)?
I assume I'd need some kind of really generic delegate and then cast it as the type of delegate it's supposed to be with the parameters it's supposed to use in the function I want to pass it off to but I don't know if that's even possible let alone how I would do it
Dont think thats possible as you cant perform this cast.
Reflection would work (using MethodInfo) as that can be invoked with any args you want.
anyway this sounds like a terrible design and you can probably do things a much better way
Reflection to make core functionality like this work would be a bad bad idea
The idea is that I'm trying to construct an RPG command menu but use the same function to be able to spawn sub-menus
But the commands would be very different for each menu
Then use a class to contain this data that you can inherit and modify
instead of trying to set up many functions you can have many sub classes
I did do that, but they'd ultimately have to contain a function that could have at least two different potential signatures
This is why virtual methods exist
you can have a virtual method with the base type as the only arg (or even just object) to overcome this
Before they all had the same signature (void(StatBlock source, List<StatBlock> targets)), but then I realized one of the commands would have to operate with a very different signature (void(StatBlock source))
I mean, I guess I could just have List<StatBlock> targets always be passed as null whenever this function is actually used, but it seems like there's a better answer than that
Then lets step back. If these things can take different arguments how were you even planning to call them in the first place with these args?
I'm not sure what you mean
Your first message describing a "list of actions"
Right. These are supposed to be the actual functions the buttons on the command menu are supposed to link back to
One is supposed to take two arguments and one is only supposed to take one
If you have a generic menu of many buttons then you should just inherit from some common type that provides a general way to do the task
Its why interfaces exist too
if(menuItem is IThingWithTargets thingWithTargets)
{
thingWithTargets.DoStuff(source, targets);
}
Yeah, I had something like that before. It was an abstract class with two children. One contained an Action<StatBlock, List<StatBlock>> that could be directly called on to be executed (as well as the actual command name that was part of the abstract) and the other was a child that took on a list of these Action<StatBlock, List<StatBlock>> command objects which could be used by the same function to create a submenu if it was called upon to do so. The wrench comes in because, in theory, I would have to now make a third time which just takes in an Action<StatBlock> as its action. But seeing as I really don't think I'll ever be using this beyond one very specific function I'm wondering if there isn't a cleaner way to do this
I think you are making things harder on yourself by trying so hard to use delegates
I dont really understand enough (about your case) to say anything else useful to change your mind either
You can surely have a class to fully contain some state of an "action to perform with data" which can be invoked via 1 single shared function (interface/base class)
I certainly had an abstract base class before and the two children were perfectly serviceable because they'd both see plenty of use. The problem is that, for this one very unique usecase, I'd have to create a third child specifically for this usecase and I feel like there has to be a better way to go about it
just make the class or handle a null arg 🤷♂️
I certainly considered that, but I also ended up thinking the same thing. "There has to be a cleaner way to go about this"
That is the clean way
Sounds like its easy to add support thus showing its "clean"
again i lack context to say more so im gonna check out from this chat
It just feels weird that I'm put into a position where, in order to open the command menu in the first place, the very function that does that has to take a list of targets that it will never get and never use. It just sounds really unintuitive and nonsensical. I think that's what's making me feel like I'm doing something wrong
are there any tutorials you guys like for making a top down rpg? i have my map and characters, just trying to put everything together
no, tutorials that show an entire game is usually not very good
You breakdown the game into several different parts you solve / put together. Following someones entire system is never a good idea, you will find yourself in a hole you can't get out of easily because you already committed " their way" of doing things. You should be looking at individual things, and if possible multiple sources on it so you can get better at making it yourself.
You honestly shouldn't need one. Even something like the old 2d Legend of Zelda games should be pretty intuitive
I think there's at least SOME value in it, but it's only if you run into a very specific problem. But I'll admit that even then the chances that it actually covers that problem are very small and you often have to wade through a bunch of unnecessary stuff just to get to it. A last resort really
guys im kinda confused on how to implement this stair detection in my game
ive watched almost every video but none of them adress the problem
Stair detection?
There isnt a youtube video for everything
i am assuming they want to go up and down stairs, in this case i´d just use a ramp as collider, which i think most of the games do
at leats the easiest way to solve it
There are plenty of examples of this in source engine maps and community hammer videos
https://www.youtube.com/watch?v=d5B9ytF6gas
relevent to the above discussion
Stairs in CS:GO are literally unplayable in SO many ways. Come with me on an exciting journey through history, looking at how stairs are clipped in Counter Strike games. Isn't this exciting!
0:30 - CS 1.6
0:56 - CS:S
1:42 - When did Valve start caring about clipping stairs?
2:30 - CS:GO (Early versions of maps)
3:07 - First step clipping issue!...
Was gonna link that but philip abit weird lately ngl which sucksss
Just put a nice smooth collider over your stairs.
Capsule colliders may already be able to push over jagged stairs otherwise you do need special logic to handle it
Yea he said some weird ass things for sure but I remembered this video specifically
hey yall, i want to lerp a number from x to y then i want the number to lerp again from y to x, im facing problems with the while loop that im using inside my coroutine, could anybody help me with solving this? , if anybody want to see my code and get more info to help me you are welcome in the dm
we don't do DM help here.
!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.
send it here.
sent it where? you share the link here 😐
ohhhhhh
this is my first time doing this sry
so i gotta make a page for the code then send the link for it ?
a powerful website for storing and sharing text and code snippets. completely free and open source.
this is it
so what's the issue?
where is timer set? looks like a mess
what's the intended behavior
seems like there's a lot of stuff in that second while that should be outside
i want to make an object moves all the time like forever at x speed like it is swimming in space and every 5 seconds make a dash smoothly then return to normal speed
Id use MoveTowards and temporarily increase the max step
then you'd need the coroutine to go on forever
yeah and im using invoke repeating to repeat the process every x second
Yea dont do that
what :/
Its not wise to mix that with a coroutine
you can do it all in 1 coroutine that keeps running as Chris stated
but then how to make the coroutine stop for amount of time
Invoke/InvokeRepeating are relatively inflexible, it's much easier to just manage it all with coroutines
alright
WaitForSeconds or WaitForSecondsRealtime
so after it exits the second while loop i make wait for amount of time then it would go to the first loop
so, a looping behavior
you would have another loop covering the inner 2 loops for that
while (true)
{
float timeA = 5f;
while(timeA >= 0)
{
//do stuff
timeA -= Time.deltaTime;
yield return null;
}
float timeB = 3f;
while(timeB >= 0)
{
//do different stuff
timeB -= Time.deltaTime;
yield return null;
}
}
Perhaps a setup like this would be best
thanks ❤️
Hmm I've done some of the Unity Learn beginner projects but Idk I feel like I didn't really "learn" what I followed with. I think Ima just start making something and figure it out im like a more hands on person 🤔
thats the first step to leaving tutorial hell!
I mean I only did it for a couple hours and I kind of understand the concepts of what does what I guess
It takes time to learn how to use an engine and how to program but some people rely on tutorials soo long they dont learn how to tackle problems on their own
yeah I can def see that tbh
like my first interaction im just like ok what do I even do 😂
This applies in general btw, not just in this situation. never a good reason to use invoke
so it is a bad thing to use?
Hello, I want to implement delay to button press action, but i'm not sure if solutions I found on forums won't hold up my script.
Things that i found revolve mostly around using "CooldownTime-= Time.deltaTime;" and if statement in update. Since I'm not experienced I'm not sure if it wouldn't be better to just us IEnumerator to do the delay independently. Code I want to use it in is quite long and I would love to know which method is more optimal.
Ye
Both are fine approaches
Thanks
But a cool down with a timer is better. 🫣
Could put things in methods and use early return if you find it nicer.
i'm mostly worried about performance, doesn't have to look nice
but ty for the answer
don't worry about perf until either it becomes an issue or you need to do something 1000000 times
Both have a cost, but a lot of things happen behind the scenes to execute that IEnumerator. I would lean towards simplicity.
sure
im so sorry for the late reply lol, i have seen them briefly but i trying to implement a floating collider that floats above the ground so stairs beneath them automatically push it up, the only two solutions i know are either hard forcing the transform.pos to snap them to the ground and one is a physics based spring system, none of them allow external forces to override the snapping (for example jumping and stuff)
#- sorry for low quality lol
Rigidbody move
the spring equation F = (x * k) - (v * c) works very well to keep him on the grond but the issue is its also pulling down, i dont know how i could suspend i apply other forces,

okay so i kinda solved it, if you guys would maybe want to know id drop the snippet
sorry rob for da ping 
time to clean da codeeee
does anyone have a good solution for how to make a character selection for an online game using mirror?
#1390346492019212368 is likely the right place
alright ty
does anyone have any clue why my guy tweaks like this?
like, it doesn't move right, the models shakes a little
How are they moved? physics or direct changes to the transform?
What's the update method looking like.
Is there a quick way to find the class name of a given component? (e.g. TextMeshPro - Text -> TMP_Text)
is this in update or fixedupdate
is it the camera stuttering or the player stuttering
I've got no clue what my teammate is doing
📃 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, that's probably update's fault.
how i speed up the load time the project browser
technically TextMeshPro - Text would be TextMeshPro, TMP_Text is a superclass that includes it and the UGUI version
Like chris mentioned, fixed update vs update can cause this.
Yeah, mentioned. I was just about to correct that.
also what type is the rb?
cool, that doesn't answer the question though.
yeah, i don't know off the top of my head so i'd went to find out
sorry
i mean what kind of rb is it
These are the attributes
contextmenu > edit script seems to work to at least bring up the file in your ide. i don't know of any more direct method
for built-ins, there's also the question mark icon that brings you to docs, but that seems to.. not be ideal in the case of components from modules
ok, so a dynamic (non-kinematic) rb
MoveRotation and MovePosition are intended for kinematic rbs, so using them on a dynamic rb can have some interpolation issues.
if you want a kinematic rb, well, make it kinematic
otherwise, move it with other methods (other than MovePosition/MoveRotation)
also enable interpolation, and afaik you'd want continuous collision detection as well
though, as mentioned before, also check if your movement code is in update or fixedupdate, and check if it's the camera or the player that's stuttering.
okay, thanks.
Thanks! I'll take a look on all of that
Is an if statement where you call it or in the method body not sufficient?
!help
No Category:
help Shows this message
Type !help command for more info on a command.
You can also type !help category for more info on a category.
Use
!help <command>to get more information
!help
!info
!list
!ping
!avatarinfo
!bannerinfo
!guildbannerinfo
!guildiconinfo
!guildmembercount
!guildsplashinfo
!searchdocumentation
!stickerpackinfo
!report
!warns
!support
No Category:
help Shows this message
Type !help command for more info on a command.
You can also type !help category for more info on a category.
!list
!list <commands|features>
!info
Website: https://sapph.xyz/
Dashboard: https://dashboard.sapph.xyz
Server: https://discord.gg/5BtABzAGCf
@xge (Lead developer)
@blitzluchsy (Developer)
@gersti (Developer)
@kaeraart (Design & Moderation)
@pandarex (Documentation & Moderation)
guys im looking for a website designed for code so i can share it
like paste.mod but website is down or sum
📃 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.
man im just trying to find this
for future reference you can also just google "pastebin" (that's what these sites are called)
this info is in #🌱┃start-here as well as a list of commands
Hey I need advise, trying to learn Unity for game projects, trying to currently make like a party selection but I'm completely lost, where should I be going to improve my own learning so I can get better idea on what's supposed to be done?
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
hello everyone.
I currently have a sprint in my character movement that modifies the camera lens fov. Unity keeps asking me if I want to save after I end play mode. Is there a way to stop that prompt without turning all other prompts like that off?
hello
hi guys
What exactly is it asking to save? 🤔
So I want to put a "blank" white circle inside another circle to form a donut esque thing, nothing going wrong with that of course, but the problem is that I want to make their radiuses dependent on public variables and I'm having the error below
Assets\BalancingScript.cs(9,32): error CS0236: A field initializer cannot reference the non-static field, method, or property 'Component.transform'
with my code being
using UnityEngine;
public class BalancingScript : MonoBehaviour
{
public float normalRadius = 5;
public float invertedRadius = 4;
Transform NormalCircle = transform.Find("NormalCircle");
Transform InvertedCircle = transform.Find("InvertedCircle");
Vector3 normalScale;
Vector3 invertedScale;
void Start()
{
}
void Update()
{
normalScale = new Vector3(normalRadius, normalRadius, 0);
invertedScale = new Vector3(invertedRadius, invertedRadius, 0);
NormalCircle.localScale = normalScale;
InvertedCircle.localScale = invertedScale;
}
}
Modifying scene objects like a camera during playmode shouldnt prompt anything like that @vapid egret
Maybe you have some editor window open that is prompting it, like shader graph or some other asset editor
You can not use Transform.Find there, but you can use it in Start for example. Declare the variable outside of Start though
I'll do that, but I must ask, why?
Although the best way is to make it serialized and assign in the inspector
Field intializers might run before the Unity object is fully loaded, which Transform.Find depends on
how do I do this, is this public variable related?
[SerializeField] Transform NormalCircle;
Where do I put this in the code
public is serialized too but we dont need it to be public here
The same place as usual?
Same place yes
It will have a null (none) value by default
So you need to assign it in the inspector or in Start
Inspector reference is usually preferred
It's asking if I want to save my character lens field of view, which is 60 on standard run and 80 on sprint. If I exit game mode before it reaches 60, which is the default, it will ask me if I want to save it.
Modified objects include:
Player/PlayerCamera```
I believe there's a toggle for that?
Do you know where it is? I've been looking around and I've found prompt settings that will turn all warnings like that off, which I don't want. My camera is working as intended though
Should I ask in the Cinemachine channel?
Heya! Is there a way to make exceptions to disabling all InputActionAssets? :<
Basically In a dialogue scene i want to disable all player inputs except the continue key! Or can anybody think of a smartwer way :<
Consider disabling specific input action maps instead
You can have a "Gameplay" map and a "Cutscene" map
https://docs.unity3d.com/Packages/com.unity.cinemachine@3.0/manual/CinemachineSavingDuringPlay.html
turning this off means that it won't try to save play-mode changes
(it won't silently start saving the changes)
Thank you very much!
By default, nothing you do in play mode will permanently change your project
well, nothing done to objects in the scene 😉
I've tried reading the docs, i absolutely do not understand what an action map is 
an InputActionAsset contains many InputActionMaps
each InputActionMap contains many InputActions
which are individual actions
for example, my game has maps like:
- "Humanoid"
- "Spectator"
- "Menu"
What is the proper way to teleport a player (using CharacterController and Starter Asset's FirstPersonController)
This is my current function, and it logs that it successfully placed me at Spawned at Entrance: (0.00, 0.00, 0.00), but in reality I am in the exact coordinates as the previous scene I came from.
a powerful website for storing and sharing text and code snippets. completely free and open source.
LOL It was right there! Here I am looking in preferances and settings and stuff!
!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.
jesus christ
My bad
That's actually interessting but not suitable for my dialogue case! c:
why not?
I tried to disable a specific event before where the player can move, but then he's still able to turn around.
And I couldn't think of a way where if I make a seperate input map that I can stop the movement input and have a dialogue input
you can disable and enable individual maps
The page not loading for me I got bad connection, did you disable the controller before teleport
so, when the game starts, you enable Gameplay and disable Dialogue
Yes
when you enter a dialogue scene, you toggle both
wait
I'm astro stupid 
you're right
10h of work + unity back to back might fries my brain a bit too much 
Just make sure that you always re-enable the gameplay map when you're done
I have a controller whose job is to look at the current game-state and decide which maps should be active
e.g. if the player is controlling a humanoid entity, then turn on humanoid actions
ok thank you
@swift crag how are you assigning the action maps? Are you looking for the Player Input and then are able to access the maps somehow? I mean I can't just Serialize them and put them into the inspector... right?
Wait can i 🤔
There is no InputActionMapReference, yeah
void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log("Entered Trigger.");
CollidersInRange = true;
Debug.Log($"{collision.gameObject.name}");
_particleSystem.trigger.AddCollider(collision);
fart();
}
You have to get them by name from the asset (i believe PlayerInput can give you the maps, too)
!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.
by name sounds so weird
@rich adder these two objects are triggering
both of them have only one box collider
well you don't declare what collder it should look for right?
You're saying anything that enters, causes a collision
Damn action maps are complicated af 
It's impossible for another collider to exist, cus those are the only two objects which are present on the scene which have colliders attached to them, literally nothing else has a collider
Just following up on git questions. Am I doing this right? When I want to make a change, I
-
create a new branch from main with some short description of the changes,
-
commit and push all local changes to this new branch,
-
then when done merge the branch back into main
Or am I using git wrong?
Well if you have the scame script on both of them then both fire that something has entered
We're lacking infos how your scene is set up
perfectly valid. Working on another branch is best when you want to avoid adding in progress changes to the main dev branch
Branches are more for different experimential features or if multiple people work on different stuff and don't want to push it onto the main project without testing first.
I recommend having a testing branch, where you implement new stuff, depending on size of the project you can also have multiple branches for different features and later merge them. Idk if I would create a new branch everytime I want to change smth
Only one of them has it
Aye bros, any idea why my values don't seem to be surviving editor close/open?
[SerializeField, ReadOnly] int persistentGuid = 0;
#if UNITY_EDITOR
void OnValidate(){
if (persistentGuid == 0)
{
persistentGuid = Random.Range(0,1000);
EditorUtility.SetDirty(this);
}
}
#endif
There, i just quickly pasted the nessecary parts.
It works just fine but persistentGuid doesn't seem to be serializing (OdinInspector's SerializedScriptableObject) and is set to a random number each time
Specifically the persistentGuid just isn't saving and im not sure how to save it. Ctrl+S doesn't save all assets apparently
Why does that have rigidbody without collider btw
Shouldn't you have 1 as the min value?
Doesn't really matter, no matter what i put I can't get that value to save
even if i just set it to 42069
Okay I finally got them to save by adding AssetDatabase.SaveAssets(); i there but I don't see why it's nessecary, surely there's other ways to save dirty assets
static Database _cachedDatabase;
void OnValidate()
{
if (EditorApplication.isPlayingOrWillChangePlaymode) return;
persistentID = name;
if (persistentGuid == 0)
{
if(!_cachedDatabase) _cachedDatabase = Resources.Load<Database>("Database");
persistentGuid = _cachedDatabase.GlobalGuid;
_cachedDatabase.GlobalGuid++;
EditorUtility.SetDirty(_cachedDatabase);
EditorUtility.SetDirty(this);
AssetDatabase.SaveAssets();
}
}
#endif ```
There we go. Now that they actually save, every single scripted object will automatically get a unique string and a unique ID starting from 1 (rather than a massive guid number)
my project is loading so slowly, how can i do some kind of performance audit or something
not really a coding question..
try deleting / refreshing cache
delete library folder
Is there no way to outline text in a textmeshpro on a per instance basis without having to create a material preset?
prob not
hello
anyone knows why my water is always pink
I have rtx 3060... Its enough ig 😭
i guess no one
Not a coding question. Read the asset's documentation, it has instructions how to convert it to the render pipeline you're using
In future ask in #1391720450752516147
Pink means the shader is broken, probably means its incompatible with the current rendering pipeline in your project.
Idk what that means
#1391720450752516147 <--- (ask more there)
how can i save and load game?
thank you
Google is a good resource though probably the first thing that comes up is the Brackeys tutorial on save and load system, don't watch that. It uses the binary formatter which is not safe and should never be used for anything (the vulnerability wasn't known when the tutorial was made). I'm not sure if you can even use it at all anymore, at least it should show a warning every time it's used.
Saving data is critical for any game. Whether you need to save high scores, preferences, or game state, Unity offers a variety of methods – from PlayerPrefs to serializing data, encrypting it, and writing to a file. In this video, we share some valuable tips on creating data persistence in Unity.
Speaker:
Bronson Zgeb, Senior Content Develope...
https://paste.ofcode.org/mYscMJUwkNjeiD2KgyBSNf
I've been trying to make a simple mini game where everytime I press space I inc a number, which is a number on a slider, which then will increase, aslong as I don't reach the final goal. Everything works semi fine aslong as i don't use Time.deltaTime. I know however that I need that, otherwise my value will perma decrease way too fast.
If I use time.deltatime I'm instead not loosing value, but fruthermore increase it.
I think it's a small mistake somewhere but I can't figure it out rn
your increase and decrease values diff rates are probably the cause
nothing is “wrong” with Time.deltaTime itself
seems you decreasing slowly over time
increasing in big instant chunks
Yeah but it doesn't decrease at all. With delta time used, i somehow inc 3x my input value 
probably your Input,
put log inside IncreaseSliderValue and see how many times it gets called
you most likely need
if (!context.performed) return;
slider.value += sliderIncrease;```
not Time.deltaTime at all
Hey guys! I was wondering if anybody could give me advice. I am making a game in which you have spells that automatically activate every set given of time, but Im not sure how I should go about doing that. Is it optimal for me to make a base class for the spells that have most of the base functions for the spells and then for each spell I code I make a new file for the spell which extends the base?
yes
scriptable objects for each spell probably
Okayy thank you!!
doesn't matter if they are components, SOs or Pocos, the common idea is to have some inheritance there
I'm not sure what those are, but I'll do some research on them and learn about them
okay that's actually interessting. you're right I had too many inputs. I'm not sure why "if (!context.performed) return;" fixed that issue.
Do you know where I can read more about that?
not spells specific, but i have "abilities" a they are either Instant or primed.
here is a an arrow you can shoot that creates a "rain of arrows"
this is older code, an yes normally I use properties but was for a jam years ago xD
So the neat thing is, i properly inc now instead of having the input value go x3.
But it still doesn't decrease my value when I use time.Deltatime 🫠
Did i perhaps write that line wrong or smth?
because by default that function is being called with started, performed and canceled at once
Oh intressting. Def. need to read up more about the callback context
always check the manual / docs
its overwhelming at first, because there is a lot there and much you can do
Yeah I've been doing that the last couple of days. Learning a lot the last few days, so my mind is a bit overloaded with infos
thinking about it 5 days ago I couldn't write a single line of code haha
I started with the older Input Class, very limited but got the job done..
tbh it took me almost a year / committ to kinda grasp the new input system and still there are new things I'm learning
Learned about action maps yesterday and how to change the input depending on what kinda scenario I wanna do. Pretty neat
yeah they have really good features, I'm glad they swiched it . You had to use assets to get this in depth before and even then it wasn't as good
the interaction type you can do etc. really cool
hm anow that i think about it, with the new input controller i could technically easily support gamepads 🤔
ya it also supports specific gamepad types or other devices
Hmm so I was able to make a version of pong but I did have to google a bunch of stuff with making the scripts and stuff. I still feel like I need a lot more time practicing with these scripts and writing the code before I start trying to make out something of my own. If anyone has some advice or tips when it comes to scripting, feel free to let me know I would appreciate it a lot. (Just trying to not watch these tutorials and copy paste since I'm more of a hands on learner)
Heya. If you want a very advanced version of this you can have objects that all use the same scriptable object code but let you select the spell functionality from a dropdown.
Just make 1 scriptable object calls SpellData or something.
Then make a class called “BaseSpell” and put [System.Serializable] above the class name. (It should not extend monobehavior)
In the scriptable object make a variable called
[SerializeReference]
public BaseSpell SpellCode;
Now you can make many spells using the same spelldata object, and each one lets you select the BaseSpell class to be used. Sort of like selecting which brain the spell will use. Much simpler than creating a ton of different scriptable objects
(Btw im on mobile sorry for no code formatting)
I use this all the time for enemies and their ai, weapons, etc. its cool cus you can duplicate enemies/weapons and just swap the ai.
ooh that sounds interesting, I will look into that
I'm trying to create a top-down character and I've set my player's Rigidbody2D to be Kinematic.
I have a test object with another Rigidbody2D that is set to be static.
The player walks straight through the test object, and I haven't been able to figure out why.
This is the player's script (minus some boilerplate)
...
public Rigidbody2D body; // assigned RB with inspector
...
void FixedUpdate()
{
body.MovePosition(body.position + (moveAction.ReadValue<Vector2>() * Speed) * Time.fixedDeltaTime); // Speed is a constant and I'm using the new Input system.
}
Is there some alternative function I'm supposed to be using?
I think you need to change this
https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Rigidbody2D-useFullKinematicContacts.html
Same thing's still happening, unfortunately.
Are you sure? the description for 2d kinematic describes your issue
https://docs.unity3d.com/6000.3/Documentation/ScriptReference/RigidbodyType2D.Kinematic.html
yeah, I read it.
do the walls have a rididbody2d set to static?
yeah.
it shouldn't be able to go into the red square
but it can
ehh whatever I'll just make them both dynamic, thanks for your help
That only allows collision messages to be sent, the kinematic body is still not going to be affected by outside forces
the fuck, they say "it will collide" so
When this happens, collision callbacks will be produced when kinematic/kinematic or kinematic/static pairs collide although no actual collision response will happen. In other words, callbacks will happen but the Rigidbody2D will allow colliders to overlap similar to the situation when a Collider2D is set to be a trigger.
Just make the player dynamic, the walls can remain static.
Or you can go back to Kinematic and implement your own method of stopping against a collider. Since Kinematic bodies aren't affected by any forces, they can't be stopped by other colliders.
Basically they affect physics but physics doesn't affect them
https://i.gyazo.com/d1d84c136db4f674ce56036da8f1ee19.mp4
Yep, this is what it looks like in editor
How to start the base class
[System.Serializable]
public class WeapBase
{```
And how to use it in your scriptableObject, so you can also change their custom variables:
```cpp
[Title("Weapon Code")]
[NonSerialized, OdinSerialize, InlineProperty, HideLabel]
public WeapBase WeapCode;
I'm using odin inspector but it's prob similar without
I'm trying to rotate my camera (the player's vision) according to my mouse movement, I'm in first person and I locked the cursor itself but I wanna rotate right when I move my mouse to the right and vice versa
how can I achieve that?
I tried doing smth like this
_virtualMousePosition = mainCamera.ScreenToWorldPoint(Input.mousePosition);
Quaternion rotation = Quaternion.LookRotation(_virtualMousePosition);
transform.rotation = Quaternion.Euler(0, rotation.eulerAngles.y, 0);```
but I'm unsure of the validity of this as the cursor is locked (and also the rotation does not work)
is there a way to not rely on the cursor?
You should be using the mouse's delta, not it's position
When using the input manager, there is an I out axis set up for that already
so something like this?
void RotateWithMouse()
{
InputAction lookAction = InputSystem.actions.FindAction("Look");
Vector3 mouseDelta = lookAction.ReadValue<Vector2>();
_virtualMousePosition = mainCamera.ScreenToWorldPoint(mouseDelta);
Quaternion rotation = Quaternion.LookRotation(_virtualMousePosition);
transform.rotation = Quaternion.Euler(0, rotation.eulerAngles.y, 0);
}```
Why were you using the input manager in the previous code and now using the input system? Are you just generating code with AI or something
trying to convert mouse delta to a world point is not going to do something useful
no I just thought you meant the new system so I went there I swapped to use it
I was just used to the old input system
Even still what you have is very wrong. As was pointed out you shouldn't be using a position at all. The delta will just be the number of degrees to rotate that frame. Also do not find the look action every frame. That's pointless, store it in a variable to reuse it each frame
i've used a tool before that optimizes the project, now i lost the tool. the thing is, outline drawing is changed
i've put a material into a 2d sprite
it was okay, it was rendering as it should like a contour
however after using that tool, the renderıng changed
it got more harsh
does anyone know a setting related to this
yo guys, I'm new to this sevrer
some of the children have colliders on them, i remember reading somewhere that the rb gets inherited by child objects unless you attach an rb for every child which has a collider attached to it, in which case, each of those colliders will act differently
I am learning about AudioSource right now and it seems like any given AudioSource component can play only 1 audio clip at a time and if you were to try and play, let's say a gunshot sound but a gunshot sound is still playing, then the first sound would immediately end and the new sound would play. After googling around, is it correct that to work with this "only 1 clip at a time per AudioSource component", I'm suppose to have X amount of AudioSources already ready to play the exact same sound or possibly dynamically add AudioSource components?
The AudioSource component has a function inbuilt to it called. AudioSource.PlayOneShotClip
Which would automatically instantiate a game object with a another audioSource that would play a audio clip and destroy itself.
But it's abit limiting. So you could just create your own one shot audio function which can be alot more flexible.
Oh wait, this is the code channel. Why are you asking this here?
oh lol oops
got it sorry, and thanks I'll check out what you said. It just looked silly to have so many audio source components get spammed in the Inspector so I thought I was doing something wrong
does this make me a professional tehe
You do know that is only inside the outer if statement, right?
i just realised that lmfao
Can someone share me a method how do I plan on making a game? We have a capstone project ongoing and all of my ideas just scattering around on how I map the excel file to JSON
For example a turn based game, it's a simple me action, end turn and then enemies turn but by the time it has game conditions, passive abilities, debuff and etc this is where I get bamboozled on what's going on with all of these

Why does my InputAction trigger on other keys in certain situations, I'm so confused 
You're missing a semi colon on line 14
I installed obsidian but I still don't know where to map things out and what to include for my json file aside the ID, Name and description
me??
if it's any consolation, that array doesn't live outside of the method so it gets cleared at the end of the method anyway
empty it? Wdym? It's going to get garbage collected
how about you provide actual useful information about your issue and someone can help you instead of expecting people to guess at what the issue might be
why my firebase code cause my unity to silently crash with no logs?
it works in editor, but on windows build, the app just forceclose
you would have to share the code and include how you hooked up the input action asset to the code as well
Did you check the application logs?
Yeah I'm stupid, I figure it out.
Why do I always figure it out after I type it out <-<
for some reason none of all these pastebin links are loading for me
maybe because I'm travelling abroad right now
I just want to play in a window build and editor at the same time, for multiplayer testing
does firebase hate that?
anyone has a clue how import models from blender into unity ? it keeps fucking up my model
that has nothing to do with code.
go here #💻┃unity-talk
https://paste.ofcode.org/bZfM9atub7tErj5Ljjm3Qf
Somebody got an Idea how I'd make it, that once the dialogue ended I let them patrol again?
This is the script on all my NPC's.
And this is the dialogue manager:
https://paste.ofcode.org/93FACJAEPcn6BKN34VuFwH
My first idea was to make it on the NPC's skript but then I break the patroling of everyone and also I'm unable to reenable the isPaused
Implement an in-dialog state on the npc and switch in/out of it on dialog.
what is a good program to write the code in atm i am using JetBrains but it keeps showing errors and doesn't compile correctly. is there a different program i can use?
What errors?
JetBrains Rider, or something else?
its JetBrains Rider 2, I'm following a video on you tube and write the code exactly like its written in the video but it just keeps showing a bunch of different errors, when i get to the part of the video that shows a test it doesn't work. if i listed all the errors ill be here all day
2? That sounds like an extremely old version of it possibly.
You should be on Jetbrains Rider 2025.something
You also need to make sure you actually set it up properly
Have you installed the Jetbrains Rider Editor package in Unity?
And have you set unity's external code editor to be Rider?
See notes/instructions here: https://www.jetbrains.com/help/rider/Unity.html#enable-the-unity-support-plugin
sorry i misread its JetBrains Rider 2025.3.2
ok good, you should continue with setting up as per that link.
everything appears to be setup correctly, maybe its just me ill go through everything again maybe i missed something that's causing the code to freak out
You have the package in Unity?
And your external editor in Unity is set as Rider?
yes
Can you show a screenshot of the "freakout"?
Rider is one of the better IDE imo
hey people, Im having a couple issues with loading prefabs from bundles in the editor since the game developers swapped to asset scenes.
they allow us to make custom maps etc for the game and i was using the editor outside of runtime could load prefabs etc with coroutines
since they swapped to asset scenes my map editor cant load prefabs from the bundles any more and ive been stuck in this loop of using a closed source
runtime application to manipulate the prefabs in my maps and then using unity to do terrain and splat etc etc
ideally id like to keep my workflow in unity outside of runtime if possible as it lets me use custom editor scripts and assets from the asset store to aid in making maps.
if anyone has any idea about how i can get this fixed up id be greatly thankful
is there a way to figure out the rect transformation size for a canvas? Not sure if anyone understands what I mean there so I'll try to explain what I'm doing- I want to know the min and max X and y points of a canvas, as the player can drag around a image and I want to make sure it cannot go off the screen, I also need the size to help kinda scale certain variables I'm using.
Not sure this matters, but I'm building a game for android so I'm currently using a Canvas scaler as well.
What I've tried- Not much honestly, I'm quite stumped on how to approach this, I could have the player kinda as a calibration to move a slider to both ends of their screen, but thats going to be inacurate and annoying. I also searched my problem up online and didn't find any information that lead me in the direction of a solution.
RectTransform.rect
Ah, this wasn't what I was looking for but led me in the right direction, can't believe I didn't check canvas's methods enough to see if it already existed 😅
Canvas.pixelRect was what I needed
'preciate it anyway 😛
Hey ! I'm trying to see and understand the new InputSystem, for my older projects i kind of copied what I saw, so I'm trying to make a player controls script for my character on my own, and even when trying to understand it's kind of confusing and I'm seeing a lot of unique method, so that's why I'm asking here, how do I make a simple character controls script ?
#🖱️┃input-system and you should take a look at the input system samples (which you can find in the package manager) as well as the Learn course: https://learn.unity.com/project/using-the-input-system-in-unity
In this project, you'll learn how to take advantage of Unity's new Input System.
Thanks a lot !
Input system docs has a pretty solid migration guide https://docs.unity3d.com/Packages/com.unity.inputsystem@1.18/manual/Migration.html#directly-reading-gamepad-and-joystick-controls
I recommend starting with direct reading until you have a need for input rebinding and/or local multiplayer.
So I have a mob with several colliders which able to shoot downwards and upwards and I want to check if shooting is obstructed
said mob and possible obstructions (other mobs) and targets (same mobs) obviously having the same layermask so
So I wonder is there a better way than raycasting for everything and sorting through that?
I guess not
Sorry it's really not clear what you're asking here. What would "obstructed" mean?
Ideally you just make a layer mask that includes only the objects that you consider to be "obstructions" and do a raycast with that
obstructed mean shooting would hit something else but the target
Do a raycast towards the target with the distance to the target.
If it hits the target, it's not obstructed
If it hits something else, it's obstructed
but what if it hits the other target
wdym "the other target"?
well to be honest I could make a layer for each faction
Why would you need that?
Can you explain what "target" actually means in this context?
And "other target"
How many targets are there?
I thought that line "said mob and possible obstructions (other mobs) and targets (same mobs) obviously having the same layermask so" would explain everything
And how are those different from all the other mobs
That line to be percfectly honest makes very little sense to me
there is a generic I-shoot-things mob
and they have different factions
so by "target" do you mean "anything in a different faction"?
to be clear I meant a mob which is a "target" within an AI script
but anything in a hostile faction would make sense to shoot through so
Do a raycast:
- If it hits nothing, it's not obstructed
- If it hits a mob:
- check the faction. If it's the same faction as the shooter, it's obstructed
- if it's a different faction as the shooter, it's not obstructed
- If it hits something that isn't a mob: It's not obstructed
then this
I did that at first but it kept hitting the source mob
target could be anywhere, behind, almost under, almost above, raycast kept hitting some minor parts of a shooter itself
...
...
yeah I should probably use a layer for general big colliders of mobs for a check, not the body parts
One way to get around this is to just temporarily put your own collider(s) in a different layer which is excluded by the mask
oh that's a clever hack
e.g.
int originalLayer = gameObject.layer;
gameObject.layer = tempLayer;
// Do your raycast
gameObject.layer = originalLayer;```
is this in 2d or 3d?
3d
if it's 2d you can use Collider2D.Raycast to ignore the current collider
oh in 3D you can't hit a collider the raycast starts in anyway
the collider it starts but what if u hit a knee or a backpack
(don't you love how 2d and 3d have exactly opposite behavior in regards to this)
Do you actually need those colliders?
and/or does this raycast actually need them?
yeah as I said I can prolly just raycast only against generic capsule colliders I use so player don't go through them
I ll remember that for later, it won't fuckup physics or performance or something unrelated in miraculous ways right?
not that I know of
good enough for me
Hello everyone, I have a question - How hard is it to transform my game into a simple multiplayer world?
combat doesn't happen in the overworld scene, but separate battle scenes, so overworld would just handle monster spawning and character movement/ their own data
I am not competent in that but so far take my unexperienced advice
how hard - yes, pretty hard but doable, annoying type of hard
having to think of and separate everything you need to sync from everything you don't and making only your player to be the player sound pretty annoying
realistically, would it be better to pay someone to handle this for me?
or is that insanely expensive
if you plan on keeping developing probably bad idea
yeah thats a good point
this has been a hobby project for a while and its now getting to the point where things are getting done
game is like
either multiplayer or singleplayer by design
for sure...
by that I mean if you have multiplayer you meant to extend it keeping in mind it's multiplayer or you would have to do twice the job
Is there a place I can share some screenshots of what I have and ask if its worth pursuing
get some feedback really
some people manage to make multiplayer mods for singleplayer games and it's pita
there is a RimWorld multiplayer mod which have huge issues with keeping up with game updates and DLCs
im not expecting this to be that size lol, i have a bunch of friends we just want to play together
on the other hand I don't think it's insanely hard to make multiplayer it's just like 2 times more things to do and keep in mind (for basic at least) but like take everything I say with a huge grain of salt I just tried to make very sloppy multiplayer once and quit fast
🤷♂️
wait till someone more knowledgable come here I gtg
Having a very simple scene work in multiplayer is easy with the integrations offered these days.
BUT as soon as you add just a bit of complexity you will encounter problems that you have never seen before, that have little resources on the internet and are hard to fix.
The structures and logic needed for multiplayer is often different than what you know about singleplayer game dev and often feels like its counterproductive if you introduce it after the singleplayer is already done because it works against all that you know about good practices
Then there is the problem of server costs, badly optimized games can really eat your wallet if you are using dedicated/cloud infrastructure.
If you want it as a playground to test it, go for it, if you are expecting to upgrade a shipped application that goes out to players you are in for a hell of a wild ride
Ofcourse the type of game is HEAVILY influencing how complex it gets, if you have a turn based 2d game networking can be relatively simple, if you have fast paced real time combat in 3d with physics good luck, you are going to need it 😄
otherwise players just walk around in the overworld
If its via steam transport (e.g. dedicated lobbies) and thats the only thing you want to network that sounds fairly doable
But if you have never worked with networking, just introducing it will be a good task 😄
Honestly, could I find a third party dev to help me with that portion?
Yes, but it is unlikely to find someone skilled who does it for free, but here is a good place to look:
!collab
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**
im trying to create a unit spawner, i have it spawnning but once it spawns the unit i want that unit to move to a target postion but im stuggling to find the nave mesh agent bcs all the sources i have found say to use a serielized field but i cant do that as the prefab with the script doesnt exit untill it spawns... how would ju get the agent when the unit spawn?
i hope that makes sence
you would get it from the object you spawned
i need the object spawned to get it from the nav mesh when it spawns
if the navmeshagent is the "main" component you need to use from that prefab, you could have the field typed as a navmeshagent (rather than GameObject) so you would get the navmeshagent directly from the Instantiate call
i mean, i guess docs? i feel like what i said is pretty straightforward. what part about it are you stuck on?
like this?
but how would i fine the agent in here?
also ignore the _agent that was a difrent attempt that didnt work
i tried using the gameobject.find
but that didnt work
wherever you spawn the new unit, you would grab it from there
wait so set a serialized field on the object it spawns from then hand it over to the spawned object ?
not sure what you mean by "hand it over"
you can do GetComponent on the spawned object or reference your prefab by its monobehaviour and instance it through that, gives you the refernce instantly
well, get a reference somehow
Life's a game of passing references around as method parameters and such
idk how else to word it bcs idk how to use it.. but basicly get the field on the spawn
weren't you trying to get the navmeshagent
yes
i may be going about this all wrong tho im super new to using navmeshs in unity
i need my spawn object to be able to pathfind to the target
Wouldn't it just be referencing its own NavMeshAgent?
you would just assign that in the inspector
it doesnt have a nave mesh ? the ground has a nav mesh ?
you don't need a reference to the NavMeshSurface (if that's what you mean)
you just call e.g. _agent.SetDestination(destinationPosition);
yes that's a navmesh surface but you don't need a reference to it for anything here
i think they want the spawner to set the target on the spawned thing after spawning
so they need the ref to the agent fetched from the spawned thing
Those two components should NOT be on the same object
oh
the surface goes on... the surface (the ground)
The agent goes on the character that moves
then the tutorial i watched is stipid
if it actually did that, then yes
technically th NavMeshSurface can go on pretyy much any object
including an empty one
it doesn't need to be attached to the ground itself or anything
so put the agent on the spawn object and jsut use the agent.set destination?
If by "spawn object" you mean the object that needs to navigate and move around yes
like so ?
it should't have a Rigidbody if it has a NavMeshAgent, generally
afaik
ah ok
it seems like those two would be competing with each other for moving the object
And you need to assign this Agent field here
by dragging itself in there (or grab the title bar of the NavMeshAgent component in)
you definitely still need that code that sets the target after spawning though (from the spawner)
so do i need to get component in the script or jsut cant use serliazed fields.. bcs it cant save them
i cant sent them before its spawn in
you can from the prefab if it's on the same object
next qesution could u build ur own agent ? so u could customize the way it moves
im asumming if so its super complicated but still
i don't know anything in this realm
also... it doesnt know how to walk around things by defult lol
i need to figure out how to get around obsticals now
I try launch unity and its package maanger error intried 10 different versions none had security alerts
Give them a NavMeshObstacle component
or include them in the navmesh baking layers
Bake the nav mesh base on mesh/colliders
found it as u sent it thank you derp.. im used to unreal engine it sorta jsut auto does that as long as the object has a colider
thank you guys for all the help
It can, if you set up the NavMesh surface baking settings to detect it
Is someone able to help i tried many versions all give me this error
ah cool, tho i feel using the navmesh obsitcal is prob better practice
depends. If the objects can move, then you want an obstacle. If they are static, baking is more efficient
the security alerts would be completely unrelated to this, the security issue in question doesn't affect the editor
have you tried reinstalling the editor
And don't repost the same crunchy phone image while the old one is still on screen
Ive unninstalled and reinstalled unity every version dosent work
Hey, I've made a mesh in code but the edges of the mesh don't look good (kinda blurry). I suspect normals to be the problem, I used mesh.RecalculateNormals(); mesh.RecalculateTangents(); mesh.RecalculateBounds();
If two faces share vertices, then the normals will smoothly blend between the faces
You need to split the edge to get a sharp boundary
(that is, you need two sets of vertices)
I see thanks a lot
I don't know if there's a convenient way to do that
or if you'll just need to do it by hand
(you'd look for 2+ uses of the same vertex and add new vertices)
you'd need to make sure that all of the triangles on one side of the edge are using the same verts
Hi everyone, I need to ask: does anyone have a good tutorial for learning how to create a first-person camera in Unity? I have no idea how to do it, and I've seen a lot of tutorials on YouTube, but most of them are basic and don't explain it completely
I don't have a tutorial, but there's a ready made (Free) one available on the asset store, from Unity. I believe it's called "First Person Starter Asset"
thanks, I'll watch it
yes go watch the asset 😐
hi
Any tips on turning a test scene with all your features into the actual game or to start making levels?
My game involves going to different planets so should each of those be a unique scene or do i switch them out in a "game" scene?
Ive kinda delved into this before but just wondering what others do or what is standard.
That’s a pretty vague context to something that can be handled in various ways.
- What’s the transitions like?
- Is the game segmented?
- What’s the contents of a planet?
I guess my question is more simply
"Any tips for transitioning between scenes?".
For my game i want a scene of a map, where you select planet.
Then each planet would be its own scene.
but if i need to change something fundamental like my player.
Then i would need to revisit each scene to fix it.
Whats are scene templates vs just making new ones.
Are you literally talking about the unity Scene or like refering to active objects and wanting to switch between those as a whole.
The player should either be:
- an object that survives scene transitions (you can use
DontDestroyOnLoador put the player object in a scene that you never unload) - a prefab, so that you use the same asset in every scene
Or use additive scene loading/ load content yourself with prefabs or by creating objects
literal acene
So i could do the same thing for my manager scripts?
Indeed. If you're planning to do a lot of scene loading and unloading, I'd throw them into a "Gameplay" scene that you load and unload when you start and stop playing
How can I make this point change location with each key press and still follow the player? I want to do this to make a weapon.
you probably need to animate it to move to match the sprite
I had already tried that and it didn't work
it certainly will if you have it match and also use animations to change sprites.
Otherwise you need to manually setup local offsets based on some other state
Did that "not work" or could you just not figure out how to implement it? Because if you want this thing to move with the animation, actually animating it with that animation is the way to do it
Hey everyone, I keep seeing this cool effect in a lot of games of the sprites slightly moving to add some juicyness. I wonder how can you reproduce this effect? Here is a gif of a game jam game that has this effect
This is a code channel. And it's just different pictures animated.
Cool question though
Shader is prob the ideal route but you could prob do a version of that through code
this is usually done with separate sprites, afaik
i feel like using a shader could probably mess up emphasis / foreground/background separation
there's even a plugin for aseprite to achieve this, i believe the effect is called "boil"
Oh ok, its sprites, I see thanks! I sometimes see it on text too so I was curious, may sometimes be shader yeah
I've been searching for the name for so long lol thanks a lot, indeed line boil brings some results, I'll look into it
My first idea was that it was generated by shader, that's why I asked here, but true I could've gone to artistic channels
This might be a dumb question but if there’s a plugin why can’t we shader it
Quality control?
Just found this video about a shader in shader graph that knda ressemble the effect https://www.youtube.com/watch?v=xDCRah7BbIo
Bytesize Gamedev is a series of videos featuring tiny tutorials, delivered in 60 seconds or less. In this video, learn how to make a sprite wobble effect using Shader Graph and URP.
This video was previously posted on Twitter: https://twitter.com/daniel_ilett/status/1318598139419480070
Unity 2019.4.12f1, URP/Shader Graph 7.3.1
---...
For that specific example, it doesn't look like it's shader. There are deliberate straight lines created in two swapped sprites. But yes, nothing stopping you from using a shader with modulated distortion.
Any ideas how to log data and save it to the database.
I'm currently using Unity Game Services for authentication and storage for player files etc. I want to create an audit log much like
[Timestamp] [User accessed this place]
[Timestamp] [User talked to NPC]
The actual main thing would be to keep track of what the users are doing. I'm using Unity Dialogue System by PixelCrusher so I think I have some event system that i can use when user starts or stop certain dialogue. Just wondering how to store it to the database to analyze
What exactly are you having issues with? How to write to the database? Or what exactly, because from what you read, it sounds quite straight forward. Have some static logging class that everyone can enter and that has access to your DB, send you revents to the class of whatever type and timestamp and upload it.
i would imagine so
Okayy would Unity Analytics be okay for it?
Sounds like this would be the right thing for you to use: https://docs.unity.com/en-us/analytics/events/events
Just be sure to cover some information in your game, that you are gathering this information in your game.
!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.
can anyne help me with this?
im trynna make it detect when the player has a certain effect applied to them
using arrays and lists but im having a problem with the "common" array
i cant get it to contain only the common elements between the effects list and the applied effects list
also can anyone suggest something better than having all the functions in my classes be public?
It's not clear to me what you mean by "common" array here. In fact there are no arrays in this code.
To check if a list contains something you can just use myList.Contains(theThing)
for example:
bool containsPoison = AppliedEffects.Contains("Poison");```
You said:
im trynna make it detect when the player has a certain effect applied to them
And I'm not sure I understand why checking that would require checking for common elements between two lists
ah i forgot the [] next to the string called common
ToList here will return a List<string> not a string[]
so it's wrong anyway
actually now that i think about it
idk why i was trynna do that in the first place 
so instead of writing string[] common = ..... i write List<string> common = new List<string> {......}; ??
wait then what does the enitre function return
no
the right side is fine
leave it alone
why when i use the smooth damp or lerp with camera to follow the player is shows the color of background
Colors being rendered by your camera have very little to do with either of those functions.
Maybe what you're describing is that your code is inadvertently moving the camera to a place where it can no longer see the player (or anything else), so you only see the background
A common example is if you're forgetting about the z axis in a 2D game and so you're moving your camera to the same z position as the objects you're trying to render
oh
thanks it work i didnt thought about the z axis in my 2d game
it make a lot of sense now
<33
is there a way to remove listeners on an event Action directly, rather than doing it on the listeners?
I could do it either way but I feel like for a pool it makes more sense for the object to clean itself up, rather than whatever used it
do you want to remove specific ones or all?
oh interesting - what about when I invoke it again? do I need to set it to something?
well, depends, which type of event are you using?
oh action is not an event listener, you just save a reference to a method 😄
so yeah you can set it to null and just do a null check before invoke
What would you consider an event listener?
so just to confirm: this becomes not null the moment anything subscribes to it
so if there are no subscribers, it is just skipped?
yeah, with action you can only ever have one subscriber, the next one would override the earlier
are you sure?
I don't think that's the case
pretty sure Action is just a reference to a single method
how are you subscribing to it?
cap
oh im an idiot, i switched it up with Func 😄
Action is just a void delegate that exists for convenience
yeah my bad, had it switched up
You don’t need func prob
yeah keep the action and if you write null to it, it should just flush all listeners
As sidia and plenty on google said setting to null should work
I understand why you’d be confused by that behaviour tho
yep, its weird 😄
I mean it makes sense as long as you keep in mind what the action actually is
I'm slowly getting it, but my brain is still not developed for it lol
yeah but usually you set something to null if you do = null, with action is just throws away all listeners, its a bit counterintuitive
I don’t necessarily agree tbh
It’s functionally just a list of functions, if that was actually the case setting it to null would be an actual null list
I guess it's the same as a list, which you can also do List ... = null, which clears it
unless it doesn't work like that
That would be a null
oh wait yeah it is different
no a list will really be null after that, you need to construct a new list after that
yeahh
I do personally prefer how unity events wrap the += and -= in AddListener and RemoveListener
So much so that I have my own version that just rips that 😄
https://github.com/IAmBatby/IAmBatby.IterationToolkit/blob/main/Runtime/Scripts/ExtendedEvent.cs
R3 supremacy!
Oh does that do similar?
I mean it does a lot more, but yeah it offers similar functionality to yours in this case
nice


