#π»βcode-beginner
1 messages Β· Page 809 of 1
no, like why do this
Im delete my script rn
it's not that
just, it's specific to their game
you cannot make it work out of the box for yours
you have to adapt it
Should i make my own?
or edit that to make it work
Cuz, I'm mostly use ChatGPT
oh god...
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
do not use ChatGPT UNLESS you know C# and Unity first
Alr, fine.
ditch the AIs lmao. they won't help you, they'll just give you a facade
well, they do help, if you use them correctly
making the whole code for you is not the right usage tho
Bro, i ain't dumb. Someone who I've knew used to teach me about Unity. I remember the code very well.
well, then fix the code you have
those are basic errors
and the IDE already tells you why it is throwing them
Respectfully no you donβt know the code very well
and a beginner cannot.
Itβs very clear
yep, exactly
Tbh, whatever you trying to say. Irdc. π
that's why i said only when you already know C# and unity
it's quite counterproductive and harmful to suggest that AI would help tbh
If you know those you donβt need chatgpt
Well, do i had to watch some YouTube Tutorials then and instead of using ChatGPT?
it does help for like comments, repetitive code editing, searching trough code and more
They killed it? Nooo
sure, or use unity learn as has been linked to you previously
well, i do use it for stuff like that, and it's working fine
good for you.
What and Where is Unity Learn?
!learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
Because your ignorant of the preferable and ideal ways of doing those things
nope
as i said, if used correctly it's actually helpful
Nah
we do not need to have this discussion, it's not gonna be productive
Hey. You seem to be new here. Just to make it easy on everyone: AI is not regarded well in this community. I recommend not bringing it up unnecessarily. There's no point in trying to convince anyone here - not gonna work. Just a tip from someone that is using AI frequently myself.
-# it's not regarded well in most if not all communities ive seen lmao
ah ok, thx
Watchin this rn.
Not necessarily
Is it on Unity Official Website?
if he didn't know what the errors were, yes he does
!learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
People on the internet tend to only participate in communities that already match their views. Anyways, let's not continue that here...
you've been linked this twice thrice now
Alrighty, Im on the web
Hello, good night, could you help me?
How do I store a certain object in a variable so I can access it later?
For example, here is my code for instantiate my objects:
for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { cellPosition = new Vector3(i, 0, j); Instantiate(terrain, cellPosition, Quaternion.identity); //Stores the instantiated terrain blocks in the cells array for later access } }
I would like to store each terrain block so I could access them later easily. Any tips? Even what to read on docs would help as I am incapable of coming with a solution.
- Make a variable
- Assign the variable with
=
for something like this though you'd probably want a 2D array or a Dictionary<Vector2Int, Cell>
so your actual question doesn't seem to be "how do I store something in a variable" it's maybe "how do I use collection types that are addressable by a 2D coordinate?"
public ...[,] terrains;
public Vector2 size;``````cs
terrains = new ...[size.x, size.y];
for (int x = 0; x < size.x; x++)
{
for (int z = 0; z < size.y; z++)
{
cellPosition = new Vector3(x, 0, z);
var instance = Instantiate(terrain, cellPosition, Quaternion.identity);
terrains[x,z] = instance;
}
}```<https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/arrays#multidimensional-arrays>
Thank you.
I figured I would need a multidimensional array, but didn't know about this "instance" command.
it's not a "command"
that's just a variable name
it can be whatever you want
Instantiate retuns the newly created object https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Object.Instantiate.html
Indeed, I am reading the docs now and realized what you did.
Don't know how I didn't realize it before.
It's cumulative knowledge, congratulations.
π
hi, i have a superclass with a private field called name with getter and setter. i call the setter in my child class Awake() function but when i try to use the field later it is an empty string. does anyone know why
You can't modify private variables outside of the class. Make it protected instead.
Also is that child class being inherited by another that is overriding the awake?
no its not
am i allowed to paste 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.
public abstract class Projectile : MonoBehaviour
{
// super class for all projectile objects in the game
private int damage;
private int shrapnelCount;
private float explosionForce;
protected string projectileName;
protected void SetName(string newName)
{
projectileName = newName;
}
public string GetName()
{
return projectileName;
}
public class LeadBullet : Projectile
{
void Awake()
{
SetName("Lead Bullet");
}
void Start()
{
initiate(20, 2, 5);
}
}
ok so what's the issue exactly?
ALso this code is not complete
im trying to display the GetName() on the screen but it comes out blank
you need to show the full code, including the code that tries to read GetName
I will say though, this pattern is not ideal
Are you placing the two classes inside the same file or just pasted it all together?
why not just:
// in the parent class:
public abstract string Name { get; }
// In the child class:
public override string Name { get { return "Lead Bullet"; } }```
i just pasted them together
Name can be public IMO, no need for protection in some of those variables
the backing field and the setter shouldn't be public
there's a public accessor, that's fine
this worked thx
do you know why my code didnt
can someone help me??? i keep building but my apk file isnt there and it is deleted
You didn't share enough information for me to know why it didn't work.
It could have been lots of things
FOr example were you perhaps trying to get the name of a prefab?
someone
yea this was what i was trying to do
Doesn't sound like a code issue
Since it's a prefab, Awake won't have run on it
oh ok. anywhere else i can go for help
so you were never setting the name
thx
ohh ok thx for help
Hi everybody
Can some one help me with map magic 2
!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
Hey everyone Im working on learning Unity.
I always say learn by doing and making mistakes. Imagine project you want to make it and split into multiple tiny projects, each focusing on 1 feature
Don't use chat bot given code. Always when i use it, I'm going back and rewriting everything myself.
nice, beginner for coding? Gotta say C# is way more better for a beginner lol
Hi, how do I learn to write code? I already watched tutorials and understand what stuff in C# does but I can't write a single line π₯
!learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
u need to learn things that based on wut u wanna make
first, find a thing u wanna make, then learn how to make it, not just learn "how to write code"
its too broad
does anyone know what happens when you release from a pool internally? does the element get released from just the pool or from all collections which have that object present in them?
I just found out that,
{
if (size >= Vector2.Distance(enemiesInRange[i].transform.position, transform.position))
{
tempListOfEnemiesToRemove.Add(enemiesInRange[i]);
_duckPoolContainer._duckpool.Release(enemiesInRange[i].gameObject);
}
}
```will work but
for (int i = 0 ; i < enemiesInRange.Count ; i++)
{
if (size >= Vector2.Distance(enemiesInRange[i].transform.position, transform.position))
{
_duckPoolContainer._duckpool.Release(enemiesInRange[i].gameObject);
tempListOfEnemiesToRemove.Add(enemiesInRange[i]);
}
}
what kind of pool are you using?
unity's built in pooling system
object pool in unity?
yeah im just asking cause its not uncommon to have custom/different solutions for that π
whats the error you get in version 2?
in unity object pool version, release just means unactive it, not actually dispose it
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
so relase not actually "release" from the pool, its still in the pool

nothing is ever "released" from the pool, it's enabled or disabled unless pool size reaches max size possible
yeah, release just means execute the method u put it in before like "OnRelease"
so u said u found a error like ArgumentOutOfRangeException
question remains, why does it effect other collections having the same object
i think maybe its other things wrong
in which of the lines does that error trigger?
yeah i think the error is unrelated to pooling
and u can try to use debug mode to run each code to see wut actually is happening
to see why there is a error
i did see what was happening
in this scenario, after the release happens, enemiesInRange decrements in size...
yeah, we need to see the full code here π
also the duck pool container please
as in the script which has the actual duck pool with all of its functions listed out?
yes, where you create the pool and stuff
wait
maybe it ends up destorying the duck or something
so instead of ReturningDucktoPool, OnDestroyDuck is run
If the pool has reached its maximum size then the instance is destroyed using the method passed as the actionOnDestroy parameter to the constructor.
but it does not
yes, can happen
only one duck
i think u triggered ArgumentOutOfRangeException cuz u changed the size then it happenes
but yeah, idk wut actually happen
u said u already debug it
no change with list or count of objects?
the second one in these 2 versions called OnRelease method, then try to add a element from the list with i for index, but triggered ArgumentOutOfRangeException, and the first one, it get the element firstly, then call OnRelease. so problem is 100% about u changed the list so i doesnt work anymore, and u changed it by calling OnRelease
and u call SetActive in OnRelease, maybe u made a script somewhere did something like "OnDisable"
try to add a monitor for this list, and get in OnRelease method
to see when the list changed, and i wonder if there are any other scripts editing this list?
there are, but since those aren't in the scene, they won't be able to effect it
unlucky there is no voice chat in this server, i was thinking we can watch wut happens while u screen share it
but yeah, try to debug it in OnRelease method
oh! i never noticed this server did not have a vc
just check when and where the list changed
Iβm curious as to whether Unity uses spatial partitioning when checking for collisions?
cuz "Object Pool" donest change it
i will add a log then
yes
firstly detect by AABB box then use it
private void ReturningDucktoPool(GameObject duck)
{
//Debug.Log("This is being called to release the duck.");
//reseting spline animate of the duck
SplineAnimate splineAnimate = duck.GetComponent<SplineAnimate>();
//recent omition
// splineAnimate.Restart(true);
splineAnimate.ElapsedTime = 0;
duck.SetActive(false);
Debug.Log("Disabled was called");
}
private void OnDestroyDuck(GameObject duck)
{
//Debug.Log("This is being called to destroy the duck.");
Destroy(duck);
Debug.Log("Destroy was called");
}
i am srsly confused, why would disabling the enemy duck end up changing enemiesInRange
i did, check my previous 4 images
fist two is before release gets called
where are you calling the RemoveEnemies method?
on trigger exit of another class?
no he has a dedicated RemoveEnemies method at the bottom
sry
it will be better if there is a vc lmao
cant moderate a vc on a server of this size
that's on another child object
show the code please
or maybe if u can make it as a unity package then send it
and we can import it to debug
real
no, there is a reason people dont even want to download txt files here π
{
// Instance
public static GameManager Instance { get; private set; }
// States
public enum GameState
{
Idle,
Building,
Playing,
Pause,
GameOver,
}
// Events
public class OnGameStateChangedEventArgs : EventArgs
{
public GameState state;
}
public event EventHandler<OnGameStateChangedEventArgs> OnGameStateChanged;
// Vars
private GameState state;
private void Awake()
{
// Instance
Instance = this;
}
private void Start()
{
// Init
state = GameState.Idle;
}
private void Update()
{
switch (state)
{
case GameState.Idle:
HandleIdleInput();
break;
case GameState.Building:
HandleBuildingInput();
break;
case GameState.Playing:
break;
case GameState.Pause:
break;
case GameState.GameOver:
break;
}
}
private void HandleIdleInput()
{
GameInput.Instance.GetInputActions().Player.Build.performed += (_) =>
{
// Start building mode
SetState(GameState.Building);
};
}
private void HandleBuildingInput()
{
GameInput.Instance.GetInputActions().Player.Build.performed += (_) =>
{
// Going back to idle mode
SetState(GameState.Idle);
};
}
private void SetState(GameState state)
{
this.state = state;
OnGameStateChanged?.Invoke(this, new OnGameStateChangedEventArgs
{
state = this.state
});
}```
Is this a good way to do a game state machine? im starting to learn and making my first game, it will be a tower defense.
oop, badly embeded
!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.
!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.
lol
please log ontriggerexit
i am 99% sure disabling the object triggers on trigger exit
good and ez way for beginner
if u wanna make it more better, separate all the states as a single file
how so?
each state is a class include reference of state machine, and also OnUpdate, OnEnter, OnExit
look at Finite state machines, its a good way to represent game state
state machine manger when to switch and call them
noice
there we have it π
lmao
Alr, i need some visual or practical explanation for it to see how it works haha, ty guys
what is a good practice to follow in such a case?
lmao
FSM's are a well documented piece of architecture, you will find plenty of videos that visualize it well, maybe even for gamestate
cache the enemiesInRange list in a local var, but it seems you already remove the enemy that you then would want to remove again π
so u actually change the list somewhere lmao
yes, it never occured to me that ontriggerexit would be triggered
Yeah i wasnt sure if you need to wait for next physics tick but it seems that disabling a gameobject broadcasts trigger exit to all current observers instantly
lmao
How would I properly start with developing stuff in Unity? I feel like I know how to use the basic infrastructure of Unity and have decent experience with programming in general as well. I just don't know where to start. I have no ideas. Moreover I don't have a game in mind to develop, I just wanna develop but have no clue what to start with 
Recreate a retro game, with the intent to be learning and not release.
Something like pong, space invaders, breakout, asteroids
My first game that i recreated was Kirby 64 Checkerboard Chase π
was a good learning experience
{
// Instance
public static GameManager Instance { get; private set; }
// States
private IGameState currentState;
private GameIdleState gameIdleState;
private GamePlayingState gamePlayingState;
private GamePauseState gamePauseState;
private GameGameOverState gameGameOverState;
private GameBuildingState gameBuildingState;
// Events
public class OnGameStateChangedEventArgs : EventArgs
{
public IGameState currentState;
}
public event EventHandler<OnGameStateChangedEventArgs> OnGameStateChanged;
private void Awake()
{
// Instance
Instance = this;
}
private void Start()
{
// Initial state
SetState(gameIdleState);
// Input Events
GameInput.Instance.OnBuildingKeyInteraction += GameInput_OnBuildingKeyInteraction;
}
private void GameInput_OnBuildingKeyInteraction(object sender, EventArgs e)
{
// You should only be able to switch to build state if you are in idle state
if (currentState == gameBuildingState)
{
SetState(gameIdleState);
return;
}
if (currentState == gameIdleState) {
SetState(gameBuildingState);
return;
}
}
private void Update()
{
currentState.UpdateState();
}
private void SetState(IGameState gameState)
{
currentState = gameState;
gameState.EnterState(this);
}
}```
First steps trying to implement FMS with the game manager, what do you guys think? i guess i can now handle each transition in the main class and each behavior in the respective UpdateState(); for each file
states should not be hard coded, they should be a dictionary based on a state enum
makes it easier to expand

easy change though
Then im really not getting the logic or how to combine FMS with that, my poor mind
gotta read more
never thought personally of using enums in a dictionary. That actually sounds like a brilliant idea.
So, dictionaries are basically tupples/maps that can handle a key/value entry, so i just can identify a state with the enum and access or handle the state by getting the value...
so, if i get it right, should be like...
public static GameManager Instance { get; private set; }
// Enum keys for states
private enum GameStateType
{
Idle,
Playing,
Pause,
GameOver,
Building
}
// States container
private Dictionary<GameStateType, IGameState> gameStates;
// Current state tracking
private IGameState currentState;
private GameStateType currentStateType;
// Events
public class OnGameStateChangedEventArgs : EventArgs
{
public IGameState currentState;
}
public event EventHandler<OnGameStateChangedEventArgs> OnGameStateChanged;
private void Awake()
{
// Instance
Instance = this;
// Initialize states dict
gameStates = new Dictionary<GameStateType, IGameState>
{
{ GameStateType.Idle, new GameIdleState() },
{ GameStateType.Playing, new GamePlayingState() },
{ GameStateType.Pause, new GamePauseState() },
{ GameStateType.GameOver, new GameGameOverState() },
{ GameStateType.Building, new GameBuildingState() }
};
}
private void Start()
{
// Initial state using enum
SetState(GameStateType.Idle);
// Input Events
GameInput.Instance.OnBuildingKeyInteraction += GameInput_OnBuildingKeyInteraction;
}```
forgot to indent but, this is what i get
im still trying to comprehend the differences, but i can see its easier to expand, instead of hard initializing them you do it on the awake and handle it differently...
just find a game u wanna make
then learn it
Do developers use tutorial/forums while make they games for things they dont know how to do
Yep, how else are we gonna learn . . .
Fr thx
I still have a Super Mario World I was planning to re-create from ages ago 
Problem with my projects so far usually was that I just get hung up on character controllers and then just drop Game Dev altogether 
I do wanted to create my own games, problem is mentally block on what to do and relays on youtube tutorials
Reminder that game development consists of more than just programming. Work on the absolute necessities for the game that you may feel less comfortable with: animation, audio, scene-level design etc.
uhmm, I need help in this coding, it seems that leftshift wont let me do a run and it wont also jump
bad english
π 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.
yes this looks about right for a basic fsm
just one thing, how I have seen in the past, the update function returns a next state, if its still the same do nothing, if its another state you transition
that way you dont have to call from a state back to the manager
i saw something like that
like (currentState != previousState) { state.Exit() , currentState, state.Enter() }
something like that
having an exit method to handle the closure and transitioning to the next state i guess
lmao how character controller become a problem
What does that have to do with me? You can always slot in default shapes, no audio etc. and create the "immersive" experience later, I'd say.
Usually "later" becomes the limiting factor
I mean
Do you prefer if I just didnt do anything at all
Instead of doing some prototyping that might lack game feel for now
From what I've seen, most solo devs have problems creating full blown games because they focus on what they're good with rather than the necessities of the entire game development life cycle. It's usually recommended to start small and get something out there to understand the workflow (of what's important) rather than build upon what you're already comfortable with. You're eventually going to have to work on what you may not be comfortable with.
With the existence of the asset store and a few hundred $ you can also get some nice assets, the problem is the moment somebody notices store assets your game publicly becomes an "asset flip" and you can basically close shop if word gets out
I dont think thats nescessarily true
in theory it shouldnt be as hated, but the occurence of actual asset flips kinda destroyed that path
plenty of really successful games use third party assets without issue
that whole "asset flip" thing really died out back in 2017
because before that unity itself was notorious for the exact same thing
I was more concerned with folks never getting to the other parts of game development. Where later usually implies never.
people saw any and all unity games as asset flip garbage, hilarious because something very similliar is happening to unreal engine now
There is no problem with using assets, it's just that some assets are too popular, which can be a bit disruptive to immersion
okay, then what's your conclusion?
don't start at all?
because as of now i don't "get something out to understand the workflow"
I do not understand your statement. I'm suggesting that since you're already good with programming to focus on the other core necessities.
huh havent noticed that for ue π
only that people think ue = low performance
cause many devs think nanite = instant performance and it backfires instead
okay, but i don't even have a single functional thing in unity so far because i quit all of them even though the functional part being inp rogramming
Really?
"UE slop" is becoming a very annoying and common criticism for any and all games released in the past few years
studios using UE for fast games = low performance as far as i know even being new at this, i read there are lots of forks for UE that are made for fast optimized games with lots of setting tuned low or off.
Thats not really true nor how that works
and that sort of thinking is what leads people to dismiss any and all games made with UE
People who dont know what they are talking about love saying things they have basically convinced themselves to be true
well, Black Myth erased lots of doubts about UE, amazing game with good optimization
Youre missing the point
huh
Unreal Engine is not "unoptimized" by itself, thats not how engines works....
Who is saying UE is unoptimized? π
WuKong?
yeah
people who have no clue how game development works
Ignorant people then
You would be surprised at the sheer amount
UE is indeed quite laggy, its editor
just google "ue slop" or something and be greeted with thousands of videos and posts
Its developers thinking that they have performance by default just cause they use a specific engine that are the problem
Nanite was promoted as the one solves all solution for insane meshes, problem is that only works if you know how to use it, and many people dont and think it still works
Gamers in general have convinced themselves that because they play games they suddenly know about creating games themselves
I think we are going a bit offtopic here though (coding channel)
You might like to eat food but that doesnt make you a chef
However, if a beginner uses UE to play a game, such as developing a game with blueprints, there are many things he can do at the initial stage, because many things are simplified, and UE also has many built-in functions, but it must be said that an ordinary developer can also easily create a too laggy game with UE
Well, im done implementing the FMS with what i have done in the game, working so far, need to start working on EnemyAI and player base / towers logic, but from what i got you can basically extrapolate FMS to any state machine you want, so its pretty useful for NPC_AI in general π€
Decrease the complexity. Narrow the scope. Make something you can finish. Not even for profit but simply as something you've made, that's complete. Carwash has given some suggestions #π»βcode-beginner message
nice
hmm, I guess I will try creating basic retro games
then try to move on 2d jrpg
after this school sem
Game development is not easy (seriously), best of luck 
Those suggestions just seem trivial to implement and nothing that catches my interest in particular. But I guess I can try it out and maybe add my own interpretation of those game mechanics.
thats how it is
there is some problem Im been having in 2d rpg
how would I be able to create a fight mechanics
And what did you mean? Is it forbidden to struggle with it?
I'mma go start a concept first
literal meaning
If you can't build overly complex character controllers, then make it simpler
Definitely. And yet you may even find yourself not even being able to finish these simple clones. Slowly increasing the difficulty of making complete games (not just templates) will eventually allow you to get a feel for what kind of game you can tackle and actually finish.
real
How much simpler than Super Mario are they supposed to get
idk
i dont play that game
I think I often tend to get hung up on recreating the exact same feel as the game I'm trying to recreating though instead of recreating the core mechanics
Implementing the specific physics (rb doesn't give you game physics, it gives you rb physics) is a challenge in itself - to make it feel exactly the same as the originals.
What is your implied difference between game physics vs. rb physics here?
Game physics implying fake physics
Or do you just mean manual velocity-based movement vs. force-based movement?
In what way?
Elaborate on your question. I'm informing you that getting the physics for smb to feel right can be pretty daunting for beginners. It was pretty fun to create the animation curve for smb/platformer jump times.
Hello, I see Unity 6.3 Modules defaults to VS-2022, is this because Unity has compatibility issues with VS-2026? Or am I safe to use VS-2026
I'm pretty certain your IDE version isn't a concern
Awesome, I assumed as much but know better than to work off assumption. Thanks for confirming!
I can't elaborate on my question. I just don't understand what you mean by "fake" physics vs. "non-fake" physics.
So.. moving (or jumping) with velocity using Rigid body physics simulates the quite realistic rb physics system. In games, we usually don't want real physics: jumping with force, friction etc. That is the difference between video games physics and physics based on RB.
And how do you do it? In 3D you have that CharacterController component but that doesn't exist in 2D. So you'd have to still use a RigidBody if you didn't want to do the entire physics calcs yourself I suppose π€
byyyyyyyyy mysterious Math
Kinematics
oh kinematic rigidbody? i roughly remember that term, dont know its meaning anymore though
i have a rough reminder that it didnt actually check physics but i never understood how its useful then
does it check for collisions at least?
how do I properly add situational stuff to a shader? suppose a shader always does the color of a character but also sometimes adds blood into the mix. 90% of the time the character isnt bloody but the shader would still process the blood (and not draw any red cuz some blood parameter is 0) if its just another step. do I add a branch that cuts away blood logic if false or do I change materials between a shader with and without blood math? whats the play?
Generally you don't want branches in a shader
Blood could either be done as:
- A layer in the shader whose opacity you can set (i.e. combine a blood texture with the regular texture using a blend node
- A second material
there are probably other options too
yea u dont want branches if it results in the shader being evaluated twice at runtime but a bool having that branch be true or false for every threadgroup should be fine, no?
branches = too slow?
You use shader variants instead
Small branches are fine but big ones are not because the gpu must compute both cases and then pick one result
a branch that is just a single value selection is okay for example
but a lerp or multiplication to reduce a value works just the same
guys, i need to know, is there any easy way to do billboard UI which overlapping gameobjects?
Your UI should probably be on a canvas which won't need any bilboarding because it's attached to the viewport
ive made it but i still cant see the ui through the objects
If its screen space overlay UI following some world pos then that will work
Im not sure if the render queue can be changed for world ugui
i have something like this
but i want something like this
Is this world space canvas/uitk?
yup
If you want the ui in front of the objects then you can just use a screen space overlay canvas
if so re read what i said before π
if you want the ui intermingled or behind the objects, use screen space - camera and adjust the plane distance to be behind the world objects
You want screen space UI that uses code to follow some Transform or world position
what if i want to do that without any scripts?
is there a way to do this or nah?
Either code or shader fuckery is needed
hey guys, got a question: what would be the best way to store dialogs with? currently I'm using SO's with an array of name+line elements, since they're very easy to edit and iterating, but I am not sure if they're very scale-able when it comes to translating into different languages. especially when translation might be manual (aka by hand), all things considered. should I switch to json in that case, or keep SO's and do something else? much appreciated
darn it
slapping world ugui inside gameobjects is easy but not good
alr, thanks for help
couldnt they use a renderer feature for this?
If using a UGUI overlay canvas you can do this to move a RectTransform to follow a world position
transform.position = Camera.main.WorldToScreenPoint(somePos);
https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Camera.WorldToScreenPoint.html
But why?
To force it to render on top always
that is even worse
loads of ugui canvases in world are slower and a worse solution perf wise
There is opportunity for batching if all done in 1 canvas
The examples dont seem to have any perspective
so can you say the better way to do that, i just dont know
nvm you already linked it
If you know the objects you want some UI to follow you use world to screen point like in my example to move some UI elements each frame
in ugui you can assign that to a rect transforms position property (if screen space overlay is the mode)
Quick question - is it a good idea to connect UI to a script on every frame? (This is really psuedocode, because I havent written it:) So like on Update it would change a number on the canvas (UI) to the corresponding variable. Is that a good idea, or will it cause more optimization problems?
There's almost nothing you can do that will cause framerate issues if it's only a small number of objects/scripts updating each frame.
But you should still consider the value you are displaying. Does the value change every frame? Then fine. Does the value only change rarely? Consider only updating it when it actually changes then.
Gotcha, thank you!
Events are great for this. Your ui can subscribe to be notified when something has changed.
UITK bindings respond on change and pure object binding can also be setup to do this
Dude you literally just saved me from a good solid 30 minute google search. I was having trouble because I wanted to reference it from a bullet prefab that was created a lot, and didnt want to do Unity.Find every single bullet creation. Thank you so much! I'll look into this, I didnt know ui can every check for something to change.
Events are a language feature of c# and many languages and are a great way to inform anything of something happening.
Or if talking about UITK, its binding is pretty good and works with scriptable objects or plain classes (with extra work to avoid constant checks each frame however)
UnityEvents are a replica of events but allow inspector subscription (with worse performance overall)
Im guessing these events are like INotifyPropertyChanged? Just from my few 2 minutes researching this, just wanted to make sure before I continued
There are advanced techniques to get generally notified when properties change but the more general way is you defining your own events and invoking them at the right time
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/events/
A quick example:
public event Action<Bullet> OnBulletSpawned;
//Elsewhere
var bullet = GetNewBullet();
OnBulletSpawned?.Invoke(bullet);
Thank you so much. I never wouldve even thought of something like this. Honestly sometimes forgot how big coding is, lol
why do these have different numbers of characters if A. there are no changes, and B. it doesn't look like there are any differences?
\r\n versus \n
what does that mean?
The one on the left uses \r\n as a line break. The one on the right uses \n
So, every line break is two characters in the first one. 24 line breaks = 24 extra characters
ah
I thought you meant the empty space at the end
interesting - why would they be different?
Typewriters
I mean in the sense of why would the project have two different ones?
like what caused the mismatch
Different programs using different line breaks.
also I'm surprised github doesn't pick up on this
When you make a project on git, you literally get to pick which version of line break you want. It should prompt you the first time it notices a different one, and will convert it
Git even tells you when it does so when you commit it
oh so is it based on your local git settings?
its a group project so that would make sense
"[File] contains [Unix/Windows] style line endings and will be converted to [Windows/Unix] style"
git and IDEs love to fight over the line endings to use
I've noticed that, was super confused on what it meant lol
if you use git via cli it will warn about it changing the line endings next time
Hello guys i have a really good game idea in my opinion im working with cinema 4d unity and mixamo for most of the Animatios but im very new to all of that but its really fun for me to work on my Game Projekt and i wanted to ask if someone here maybe is a little smarter or knew more than me and maybe want to help me with my project
If you need help with anything specific you should just ask
If youre looking for collaborators
: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**
Nah im fine for now its just a little hard to work bc i never did smt like this and for most of my questions i use the claude ai but if i have a specific question in the future i will ask here
Feel free to do so, we are happy to help 
Thank you really much man this game is gonne be very good and now i got a place for questions xD
hey can someone help me make an first person player controller π ?
Do you have a specific question?
Does c# ever get fun because tbh it seems very robotic logic aside from flexible classes. Maybe it's because I lean more towards art since it's my hobby but I feel I'm going to really dislike working with this code as I get better. Just from boredom 
if you want fun, go with ECS, lol
I mean, it's code. It's a set of procedural instructions. If it's ever not seeming robotic then you've got a major problem on your hands
Why do people even use Java anyway. I know it was big in the 2000s. Like many browser based PC games used it. I thought C was already mature by then
back then WORA (write once run anywhere) was big
- mcus and more
Is it really though? I literally only ever heard it talked about negatively
java is pretty much as fast as c
lots of things use java
Hell android uses the JVM
and can run nearly everywhere
even your SIM card, lol
yea its mad. Dont dvd players and other things use java too?
prob
I remember my old phones with java games too
Android uses java because it was a great way to support multiple instruction sets but now its kinda pointless as id say almost all android devices are ARM and then mostly arm 64
well, you could write c++ apps for android if you want i think
but gl accessing android APIs
Yea lots more things use the NDK including unity when using il2cpp
A C Program needs to be compiled for a specific environment. Java only needs the JVM to be compiled for that environment, then can run any java application.
If you're writing software for a smart toaster it's much easier to just port the JVM to it and then anyone anywhere can write code for it without you needing to release tech specs for your toaster for them to do it
why wouldnt they
you compile it once and it runs everywhere
9 billion devices and stuffs wow
i think now it's WAY more than 9 billion
i mean i genuinely think it's a garbage language
but i understand why people would want to use it
I learnt java years ago it's a bit weird but not too bad.
C# is miles better but still not as popular
what do you think which language is my most used language so far 
using Java just feels like you're using 2% of language features in C#
although i heard they actually got some language additions over the years so that's not bad ig
Used as-in with programmers or with applications?
Why would you suggest 2%? The common joke would be that C# is like the child of C++ and Java as it heavily resembles the two (although differs a bit as well)
Syntactically speaking. Back when I learned it, it was like 2% of the features that C# can offer you.
But since then several years have passed so i admit that it's probably not too up2date
Maybe thats why I love it. Since i enjoyed my fair bit of c++ as well 
rezero
I can't follow the downloaded tutorials because they have render issues that won't let me hit play.
I find one of the website tutorials for a little mouse/toy/car whirring around a living room, and the script doesn't work. I copy it to my project and it doesn't work.
Any tutorial on YouTube I follow for making a character controller doesn't work.
I download character controllers off the Asset Store, and they don't work.
Even if I find tutorials to use the new input system, they don't work.
I'm so supremely stressed out. A full week and I can't even get my project started, let alone off the ground. I'm using 6.0. Am I not supposed to be using 6.0? Are the website tutorials actually useful? Cause they start with "How to download Unity" and stuff I don't need
!learn do the pathways on the unity learn site π
but if so many tutorials are not working, that means you are either not paying proper attention to them, or not paying attention to the errors that appear
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
I download them and don't touch anything and they give me rendering errors
ah yes "rendering errors" because that's super descriptive
That's all it says
where?
so the only thing you see when you try to use these projects you are downloading is literally the phrase "rendering errors"?
you're using HDRP ? which unity tutorial project did you Dl
Essential Pathway
The material changer won't let me hit play, and the HDRP error will, but it always comes up
I dont recall essentials needing anything HDRP . can you link it
It doesn't. I just have it on attempting to get rid of the material changer/converter
wdym with "get rid of the material changer"
why. no essentials tutorial requires you to mess with that
also are you using the specific unity version they have on the website
I'm on 6
you do realize there are many versions of 6..
6.000.3. The tutorials are all 6.0. Trying to get rid of the material converter error because it's hard blocking me from the play tab
Cause I automatically downloaded the most recent version, and didn't think anything of it til I saw the tutorials are slightly lower. There are no 6.3 tutorials, highest is 6.0
The website tutorials
what is "The website tutorials"
This link
nav's screenshot is from that link, in the essentials pathway
follow 6.3. and install the latest unity editor version from the hub
None of you are addressing my issue
except you've been here complaining that no tutorial works for you at all, and that was addressed
you're most likely opening up the wrong version of example project with your version of editor
and it's been pointed out that you need to be using the same version that the course you are following uses if you intend to download materials from that course
Any ideas on how I should implement the joysticks? I'm trying to think of a soluton but I'm not sure what the effective way of doing it is
My main idea is to have a empty game object at like the pivot point
and pivot it around using clamp
whats the consensus on how to seralize derived classes without using TypeNameHandling with newtonsoft json? its really ugly to have "MyGame.Inventory.Armor, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" or whatever in the json file, also messes up if you change class name
Hey- having some problems with an ienumerator. Currently trying to get it to move through an animation, but it wont actually call that animation change (nor the Debug within in). It will work if it is a public void ():, so Im guessing it has to be because its an Ienumerator. I wanted it to be an Ienumerator so it would pause and let the animations play out, which wont happen if I change it to be a regular void function. Any ideas as how I can fix this up so it actually calls that animation change?
https://paste.ofcode.org/M3kvJrkaFLaVryQBaPhZsi
Note: It did not work either whenever yield return was placed at the end, or if there was a yield return null (I don't know why that would fix it, but when I googled it that said it may be a possible solution)
you need to use StartCoroutine to start a coroutine. calling the method directly like that returns the IEnumerator but does not call MoveNext on it so it doesn't actually do anything
I hate coroutines sometimes. Thank you, Im an idiot, lol!
each joystick input is a vector2 which goes between range of -1 to 1 on the x and y axis. therefore, you could add rotation to the x and z axis of the models based on what your input is (i.e. joystickRotation.x = input.x * maxRotation)
technically it'd be rotating on x/z since it's aligned on y
rotating on y would be twisting
true, fixed that
i dont think it's possible to have more or less than 1 or -1 but you can use clamp as you mentioned to prevent edge cases
Thank you, I think I got it figured out
please don't crosspost
Guys I need a designer to make my assets
!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**
Arabic only in this channel.
Please stop spamming on the server
Okay, I will stop sending unwanted messages.
is there is a tutorial for how to make boss fight in 3d bec i cant find any thing and i dont understand that much in ai stuff?
!learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
not really i just need an fp controller
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
Is it a good practice, or a bad practice, to update Unity minor versions (from 6.3.0f1 to 6.3.Xf1) when I have a game that's currently on production and people are actively playing it? Will I fix or break more things by doing that? I don't have any particular, specific reasons to update right now, just curious if I should be updating the editor from time to time or leave it as it is ("if it aint broken, dont fix it" philosophy)
generally if it ain't broke don't fix
but there will never be a better moment to upgrade, so it means that, unless something comes to light, the project is going to stay at 6.3.0f1 forever?
and that's fine?
generally yeah
though, ive heard quite a few stability issues from 6.3.0f1
you may end up needing to upgrade
but honestly, don't worry about it til it becomes an issue
you probably have better things to worry about eg bugfixes, perf improvements
Thanks. I feel uneasy about not upgrading, I used to jump to new versions during dev time, but now game is live and it feels weird
I dont have a single unity-related bug though
if you have nothing else to do, sure, upgrade i guess. but it'd just be a DX thing, you wouldn't push a new version to say you bumped the editor version (unless that upgrade comes with a bugfix or massive perf benefits ig)
That just means you have bugs you don't know about π
a related question - we had crashes related to DX12, I fixed them by defaulting to DX11. Is that okay to run in DX11 as default in year of our lord 2026?
(game has great performance on both DXs)
or would it better to upgrade Unity to newest version, hope it fixed the DX12 issue, and stay on DX12?
If you can reproduce the bug, try building a versino with the latest unity version, maybe read changelogs about chagnes in the engine. Find out what is breaking it on dx12
I'd go with the more stable/mature one (DX11) in that case
no practical way to reproduce, it happened to a tiny % of players
but I worry about those things because I have no control over it, it's something very unity-specific of course
Thank you!
If its just a tiny % of players, you might leave it to them or just give it as an extra option to go for dx12, if you cant live with not having the control over it. I could be caused by so many things that are not even on your side too.
How do I create a for loop that waits some seconds in between loops?
I am making a game including lotsa ducks, i want to be able to pick them up and then put them down somewhere else, how do i detect if the mouse is over a spriterenderer (and if the mouse is clicked)
(in 2D)
Use a collider 2d on it then use Ipointer interface with a physics2d raycaster on camera
whats !pointer interface?
hmm leme take a look
Hi, I am trying to make a basic connect 4 game and I am wondering how I can make a 7x6 circle grid for where the tokens drop. I tried making some grids using vids I found but the spacing is to tight.
I am trying to make a grid to fit into the empty areas so I can then make it an interactable area so tokens can be placed
Do you want to place these procedurally? As in, being able to define the size of the grid at runtime, or is it exactly just a connect four?
Exactly as connect four. A token placing slot will be at the top of the case and then when clicked it will go to the very bottom of the case, and if any other token is placed it should go ontop of the previous token if placed in same zone
Hi, is there someone who know how playfab works ? I'm trying to do a 1v1 game and for that, I'm using Playfab. I tried to make it work with SharedGroup, but apparently is kinda outdated and Group works better. But I can't find how to save data in a group, and I'm kinda loss
Playfab has extensive tutorials for C# as I recall, they should cover everything.
You can think of prefab like a blueprint. Let's say if you want to create many instances or spawn them lets say projectiles instead of always creating new objects you just create one blueprint and you spawn this blueprint everywhere in your game. Also if you do changes to this prefab and you override it will apply to all of your instances.
You can make it a completely physics based board with colliders guiding tokens like in real life one. And have trigger colliders on the slots reporting what token stopped where.
they're talking about PlayFab, not a prefab
Where can I learn about this from? or is there a specific term for it I should search
!learn Basics about collider events and triggers
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
Thanks
Actual logic would be when a token stops for more than a second in one place it gets locked in in an array for example to store its final location.
Makes sense. I legit only started using unity yesterday so I am just learning slowly and just copying the code I am seeing from vids and modifying the values to see what they do lol
The actual complicated part would be writing an AI for it, to play against, to make decisions about moves.
For your first project you might want to start with something like pong, where it doesn't have any complexity.
You'll need to learn the basics of 2D arrays which are data containers that are exactly like a grid.
Dropping a piece into the column would set the element of that array to whatever piece colour was dropped. Then you can check the surrounding elements to determine if a win was done.
I would recommend starting with Create with Code course, its an amazing course with Carl as the instructor and don't forget to WATCH first and then DO. I have started with this Course 3 years ago when I started maybe its long like 28 hours but its an amazing course believe. You will create cool prototypes from car simulator to a 2D side scrolling game and a top down game as well.
Oh and dont forget to first learn the basics/fundamentals of Programming in C# before getting into this course , I would recommend learning the basics first because I have learned programming from school when started this course but its not a prerequisite you know I am just giving an advice.
In this official course from Unity, you will learn to Create with Code as you program your own exciting projects from scratch in C#. As you iterate with prototypes, tackle programming challenges, complete quizzes, and develop your own personal project, you will transform from an absolute beginner to a capable Unity developer. By the end of the c...
There are learning pathways btw in Unity Learn Website, also I would recommend starting with Junior Programmer Pathway because it has a lot of courses with create with code included its lika a pack and then moving into Creative Core Pathway.
Also, stop copy pasting and instead try doing some technical design or system design like divide and conquer try breaking the problem into smaller parts instead of focusing to solve the whole problem at once like flowcharts, pseudocode, class diagrams how your code must be structured but you are a beginner what I am saying basically try writing the logic somewhere of what you want to create thats my second advice.
A bit decomposition wont hurt you know
I planned on making it turned base vs another player no ai
Yea, in that case it's simple enough.
But again you have to think of it like having two classes each one has its own abilities and properties so its same think object oriented approach. You wont be able to make it without even knowing the basics of OOP, like if you want to expand later on
for example adding more enemies
like types
each enemy type must have its own strengths and weaknesses
its connect four lmao
Also for learning projects it's good to use as much stuff as possible just to play around with things. For example you don't need to make it physics based at all even, just calculate and animate everything, but it would be a good opportunity to use as many systems as possible for learning purposes.
help how do i add shooting to my game ?
What is "shopoting"?
hi aint really good in code yet, but the player moves faster to the side then it goes to the front / back:
Vector3 input = new Vector3(Input.GetAxisRaw("Vertical"), 0, Input.GetAxisRaw("Horizontal") * -1);
Vector3 movementDirection = input.normalized;
if (movementDirection.magnitude > 0.1f) // checks if player is moving
{
// Move
transform.Translate(movementDirection.normalized * speed * Time.deltaTime, Space.World);
// Rotate
Quaternion toRotation = Quaternion.LookRotation(movementDirection, Vector3.up);
transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotSpeed * Time.deltaTime);
}
I use comments to help me understand the code better
my game is so cool but its not shooter
Decide if you want hitscan or projectiles. If projectiles, you would instantiate projectiles. If hitscan, you would use raycasts
i want rotating topaz and amethist ovals
show the full script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovementHandler : MonoBehaviour
{
[Header("Settings")]
public float speed;
public float rotSpeed;
void Start()
{
Cursor.lockState = CursorLockMode.Locked; //Locks cursor
Cursor.visible = false;
}
void Update()
{
Vector3 input = new Vector3(Input.GetAxisRaw("Vertical"), 0, Input.GetAxisRaw("Horizontal") * -1);
Vector3 movementDirection = input.normalized;
if (movementDirection.magnitude > 0.1f)
{
transform.Translate(movementDirection.normalized * speed * Time.deltaTime, Space.World);
Quaternion toRotation = Quaternion.LookRotation(movementDirection, Vector3.up);
transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotSpeed * Time.deltaTime);
}
}
}
what is shootinbg
huh?
ore a small typo error is a filnl boss
depending on how you wish to make it you can eiter use raycasting or actually shoot out a object using a force
Do you have any other scripts or components on this object, including built in Unity components?
Decide if you want hitscan or projectiles. If projectiles, you would instantiate projectiles. If hitscan, you would use raycasts
i ant simple shotting for beginner swith 20-30mlines of code
Then get to writing it...
If you have a dynamic Rigidbody why are you moving via the Transform
Nobody will write your script for you
wait what does i ant means here
delete this pls i hate this image
Sorry it must be difficult to hit the keys when you are a tiny bug
kuzmo what?
cuzzz, idk, again i dont know exactly how to code so i take what i know and can find trough tutorials
thets bad codestyle
Btw this guy is a crypto scammer and a troll, so dont waste your time
lol what XD
Guess we got two trolls today then.
Hey guys, I'm making a 2D platformer. I wondering is it good to have a movement script and a jump script in different scripts or put them under the same script. I'm just wondering cause I know it runs every frame so I'm wondering if the linVel could get overwritten when dealing with these 2 scripts.
What do you guys recommend?
Pick one - Rigidbody, or Transform motion
don't try to do both
any proof for that?
i am not troll
One script unless you have a good reason to separate them
what do you think about having a dash as well, I presume that'd also be under the "PlayerMovement" script
He had a completely ai generated #1180170818983051344 post talking about some project he has that doesnt exist and how he is going to pay people in blockchain diamonds or some shit to make it for him
il use transform for now, cuz i dont see me actually using a rigid body in the future for this game
ia m just carbby not a trol trying to make small craby ganem for carbby players
@silent cipher Keep it on topic, please.
ah, ok now i see
then remove the Rigidbody - see if it affects anything
ok how do i add shoting wth different rotation speed and speed increasing of bullets
sadly after this it didnt do anything
make a script that does that in update
roation speed shold be arndomized
it's simple
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
thanx
still the same issue, is it some math problem i dont know about like with the sideways going that makes it go 1.4 times faster?
You gotta normalize it. Have you done that?
All the vector normalization you're doing should prevent that
yes
plus you said sideways, not diagonal right?
that is correct
would you like avideo?
oh no
pls help how to fix that type of bugs
maybe its an optical illusion lol
found it
and he says Crabisoft engine?
wtf
nice game is it a platformer named Capsula adventure?
this looks fine to me. I think this is actually a trick of "perspective". Your character is moving the same speed in all directions. But the vertical motion moves it less on a pixel basis because of your camera angle.
or its unfinished
oohhh alr thanks!, I guess it was my eyes that decieved me all along lol
notice how your perfect squares look like rectangles due to the camera angle. The characvter moves the same number of squares per second in either direction
guys who knows how to wriote shooting scripts?
!learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
i see, thanks for the help!
i want learn from real people not youtubers
1:1 help costs money
i can help you too for free
do you want to use the existing tutorials that people have already spent effort on to make freely accessible, or do you want us to repeat the exact same content back to you, wasting both of our times
i can get high-quality, free, ready-made information from the internet, and you can too
nice i need real scripts
also, pls try to improve your english
can we just get to the part where they get banned
!learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
or YT
to learn how they work
so write em
no, you need to learn to make them yourself
and do not use AI pls
how do i meke a movement with speedup over time and rotation with a random class implementtion
@silent cipher you've been told multiple times. stop spamming and go actually learn
!learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
YT
One piece at a time
@silent cipher Stop spamming the channel and make an effort to learn using Unity courses. You are on your last warning here.
@subtle mulch you can stop spamming those links, they clearly don't care
ok
at some point ignorance is just malice
https://www.youtube.com/watch?v=ApLXuMeSVOI literally the first result
use this as a base and add the rotation you need
they dont care
well, i gave the specific tutorial to them
they will
as they did with their "dev log" post
wtf did i just read, i opened that post
i just wanna undo whatever my eyes just witnessed
You should burn that right eye too then
π
well thanks for the warning i suppose
thanx for shooting tutorial
Hello, I am pretty sure that the stamina shouldn't decrease when I did not press shift?
you need { } for your if statement
right
since you don't have { } your if statement only applies to the sprinting = true; line
the rest will run no matter what
That are the conditions of this call?
that doesn't look 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
no idea, maybe it think I am smart but I am actual stupid
that also looks more like vsc instead of vs
at least you are smartter than me
i cant fix movemnt and rotation after watching tutorial
for a bullet
but it spawns
void Update()
{
// 1. Acceleration: Speed up over time
currentSpeed = Mathf.MoveTowards(currentSpeed, maxSpeed, acceleration * Time.deltaTime);
// 2. Movement: Fly forward (Z axis for 3D particles)
transform.Translate(Vector3.forward * currentSpeed * Time.deltaTime);
// 3. Random Spin: Rotate the gem uniquely
transform.Rotate(spinAxis * spinSpeed * Time.deltaTime);
}
is there an error?
Is there? You tell us
How about you just stick to asking the spam machine instead of wasting our time
do you habve the solution of error
giving a shit
You haven't mentioned an error
i had crab pat=rticles do not move and do not rotate
@silent cipher please stop spamming. if you have an issue you need help with, ask about it.
ok, and what debugging have you done? any errors? have you set the proper fields?
Please take at least one second to format your text instead of just smashing your hand open-palm on the keyboard and expecting anyone to read it
ok does it implemnt particles system correctly? using UnityEngine;
public class GemProjectile : MonoBehaviour
{
public GemType gemType;
[Header("Bullet Speedup")]
public float currentSpeed = 2f;
public float maxSpeed = 35f;
public float acceleration = 25f;
[Header("Random Rotation")]
private float spinSpeed;
private Vector3 spinAxis;
void Start()
{
// Randomize the speed and axis for unique gem spinning
spinSpeed = Random.Range(400f, 1000f);
spinAxis = new Vector3(Random.value, Random.value, Random.value).normalized;
// Safety: Destroy bullet after 4 seconds so they don't clutter the game
Destroy(gameObject, 4f);
}
public void InitializeGem(GemType type)
{
gemType = type;
ParticleSystem ps = GetComponent<ParticleSystem>();
if (ps != null)
{
var main = ps.main;
// Ruby = Red, Sapphire = Cyan, Emerald = Green
main.startColor = (type == GemType.Ruby) ? Color.red : (type == GemType.Sapphire) ? Color.cyan : Color.green;
ps.Play();
}
}
void Update()
{
// 1. Acceleration: Speed up over time
currentSpeed = Mathf.MoveTowards(currentSpeed, maxSpeed, acceleration * Time.deltaTime);
// 2. Movement: Fly forward (Z axis for 3D particles)
transform.Translate(Vector3.forward * currentSpeed * Time.deltaTime);
// 3. Random Spin: Rotate the gem uniquely
transform.Rotate(spinAxis * spinSpeed * Time.deltaTime);
}
}
!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.
!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.
Idk maybe it's like
body.transform.Translate
it depends what you name it
also I'm not debugging code you didn't even bother to write
Go ask the clanker for help
ok
i dont know
void Update()
{
// 1. Acceleration: Speed up over time
currentSpeed = Mathf.MoveTowards(currentSpeed, maxSpeed, acceleration * Time.deltaTime);
// 2. Movement: Fly forward (Z axis for 3D particles)
transform.Translate(Vector3.forward * currentSpeed * Time.deltaTime);
// 3. Random Spin: Rotate the gem uniquely
transform.Rotate(spinAxis * spinSpeed * Time.deltaTime);
}
This is the same code
i know
Go to learn.unity and actually learn how to write code by yourself
You debug code https://unity.huh.how/debugging to understand what the problem is. Then if you don't know how to fix you ask questions here, with the code that has debug mesages that show what you've tried.
Don't spam LLM code which you have no idea how it supposed to work
follow the literal YT tutorial i gave you!!!
i was thinkinhg code is not corrrect
Which you would've known instantly with a simple debug message
i forgot it lol
I wrote up someting small here but I'm not sure why my dash isnt working
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
if (isDashing)
{
rb.linearVelocity = new Vector2(moveInput.x * dashSpeed, rb.linearVelocityY);
}
else
{
rb.linearVelocity = new Vector2(moveInput.x * speed, rb.linearVelocityY);
}
}
// On X (Controls)
private void OnMove(InputValue inputValue)
{
moveInput = inputValue.Get<Vector2>();
}
private void OnJump(InputValue inputValue)
{
// print("Input value: " + inputValue);
if (onGround)
{
rb.linearVelocity = new Vector2(rb.linearVelocityX, 10);
}
}
private void OnDash(InputValue inputValue)
{
if (!isDashing)
{
StartCoroutine(Dash());
}
}
// My own functions
private IEnumerator Dash()
{
isDashing = true;
yield return new WaitForSeconds(dashTime);
isDashing = false;
}
just trying to get the basic structure down
how exactly isn't it working? what's the issue?
describe what actually happens and how it differs from what you expect to happen
player just isnt dashing like there's no change in linvel
its as if i didnt press anything
have you debugged to see if OnDash is being called, if Dash is being called, and if the if branch is passing as expected?
and check if your dashSpeed is different from your speed
Yeah i'll go through I know the input is being received I jsut took out the prints, but I'll try to add some more in the update block
Also I know im supposed to be usnig FixedUpdate instead of update right?
for the specific physics things you're doing here, it doesn't really matter
if it were AddForce with a continuous force then absolutely yes
i see
but here it's just setting the velocity, the update rate is limited by both Update (when input is received) and FixedUpdate (when it's applied to the simulation)
Also am I supposed to handle all the linvel setting interactions in Update() like I know it runs every frame and I have Jump here which sets the linvel in its own thing, how am I supposed to know if the update method will take prio or the OnJump linvel?
you're setting separate axes there that don't interfere
there's not really a concept of "priority" for just setting values
but fyi this is handled by script execution order and input messages will run before Update calls
I'm not sure exactly when coroutines get resumed
They may wind up before or after all other Update methods run
the execution thing specifies this.
yeah that thing, i can never remember the proper name
just remember what an old king would use if they wanted someone dead π
ah no i mean the full "Event function execution order"
i keep remembering it as SEO even though that's a separate thing
Does anyone have any good resource for the cross hatching shader?
this is the code channel, shader stuff goes in #1390346776804069396
Thank you
hey yall, hope everyone is doing well!
Just getting back into coding after a long break. I had an idea to create a 2d map of terrain and i want to use perlin noise. I have a grid of sprites that i want to color differently depnding on their height map of the perlin noise.
what is the best way to get a 2d grid of floats that will map to my grid size? thanks in advance
for(var j = 0 ; j < mapHeight ; j++) {
for(var i = 0 ; i < mapWidth ; i++) {
var tile = Instantiate(prefabMapSprite, new Vector2(i,j), Quaternion.identity, tileParent);
tile.name = "Tile" + i.ToString() + "-" + j.ToString();
tileSprites.Add(tile);
var pNoise = Mathf.PerlinNoise((float)i, (float)j);
tile.color = pNoise > 0.45f ? levelColor : mountainColor;
Debug.Log(pNoise);
}
}
i'm getting this in the log for every tile?
0.4652731
UnityEngine.Debug:Log (object)
General.MapGameBoard:Start () (at Assets/General/MapGameBoard.cs:31)
you're making the classic mistake of sampling the noise at integer steps
it will always be 0.4652731 at integer steps
try:
var pNoise = Mathf.PerlinNoise((float)i / 1f, (float)j / 1f);```
so should i divide it by the width and height of grid?
and then add a scale factor and multiply that in to be able to control the noise scale
thank you!
isn't that the same value as they're using now
now is there a way to edit the parameters of the perlin noise that i'm sourcing?
generally what you edit are offset and scale
you do that by multiplying and adding to the input values you pass into the noise function
You could also look at the noise class in Unity.Mathematics, there are alot more noise function options available there:
https://docs.unity3d.com/Packages/com.unity.mathematics@1.3/api/Unity.Mathematics.noise.html
Guys how do you all implement dodge/roll, I need a head up. Here is a code that call it, DodgeInput() is called in fixed update
can I add a monoBehavior to a gameobject and also use that monobehaviors constructor? i'm trying to do it but it's not working
No, what are you attempting to use its constructor for?
to set its unique properties
Create some method on the component that you can call to pass data to it after creating it with AddComponent
Or if you don't need to pass anything then you can just use Awake or Start
public class Tile : MonoBehaviour {
public SpriteRenderer tileRenderer;
public Vector2 tilePosition;
public float tileHeight;
public Color tileColor;
public TileVariations.TileType tileType;
TileVariations _tileVariations;
public Tile(SpriteRenderer renderer,Vector2 position, TileVariations tileVariations) {
tileRenderer = renderer;
tilePosition = position;
_tileVariations = tileVariations;
tileType = tileVariations.GetTileType();
tileColor = tileVariations.GetColor();
tileRenderer.color = tileColor;
}
}
yeah no constructors for unityengine.objects (which monobehaviour is)
so i can just change the name of the public method to something else and will work?
It needs a return type too
horray for Init()
Ought to be a company slogan. "Init() -- for when you can't use a constructor"
im trying to get my character to shoot a projectile out of a wand detached from the body, but my character is shooting the projectiles from itself, but not the wand, how would i fix that?
you need to use the position of the end of the wand as the position you instantiate your projectile at rather than the object's own position
how would i do that? normally im just attaching the script to the object so im assuming its center of mass
also my wand is now floating away
place an empty game object at the tip of the wand as a child of it, then get a reference to that object and use its position as the position you instantiate at
would i be able to stream to you so you can see how bad i fucked up and see if you can tell me how to fix it?
π 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.
hi somebody knows why this feature is making that my game dosent pass from the 60 fps per second
π
EditorLoop is literally the unity editor's update loop. that won't be there in a build
so what i have to do?
that depends, do you have any assets or anything that have any editor code that would impact the performance of the editor itself? if no, then your issue is likely your hardware simply not being good enough
maybe i need to update my hardware
btw im gonna try to build it instead of playing it in editor
i read that maybe that gonna help
i literally told you that the editor loop will not even be present in the build
yeah i notice that
ty
lol
(Spoilers cuz its a quiz question) Does ||public float Speed = 40.0f;|| or ||public float speed = 40.0f;|| follow the naming conventions?
I believe 'speed' to be a public field and therefore it should be PascalCase. Is this wrong?
the former would follow standard c# naming conventions, though it breaks the convention of not exposing data through public fields
Its a quiz question in a Learning Pathway.
then surely the course covered that
You can reply to this after hi benji is finished up, but what do you mean by not exposing data through public fields? I've never heard of something like that. (Although my knowledge is limited - I just use CamelCase)
you should use properties to expose data to other objects, public fields should only be used very sparingly
Ive never even heard of properties. Thats interesting, Ill have to use that then. I guess I have a very bad habit of using public fields a lot then. Is properties a unity thing or just a base c# thing?
that's a standard c# thing
private float speed = 40.0f; public float Speed {get; set;} is probably the proper way.
and this convention is used in more than just c#, even other languages that don't have properties you should prefer to use getter/setter methods to interact with another object's fields (and properties are just getter and setter methods that are used like variables)
well these two things are entirely unrelated so that wouldn't be the correct convention. in fact, with an auto property like that you wouldn't even need the backing field
Ah I see.
private float speed = 40.0f;
public float Speed {
get { return this.speed; }
set { this.speed = value; }
}
Would this be proper?
yeah, that is a full property that uses an explicit backing field
And this would be without a backing field: public float Speed { get; set; } = 40.0f;.
Coming back to my original question. Why does the quiz tell me I'm wrong when I use PascalCase for a public field?
that is an auto property. it does have a backing field, but it is generated by the compiler
because unity's conventions are not the same as the standard c# conventions. which is why you need to pay attention to the actual lesson for the correct answers
If its public, it means its a field right?
I just noticed you had a public field
I checked the course again and the first time it mentions naming conventions it says:
Which of the following lines of code is using standard Unity naming conventions?
This should be the standard:
https://unity.com/how-to/naming-and-code-style-tips-c-scripting-unity
no, those 2 things are unrelated
okay yes public is only a access modifier keyword and can be put elsewhere. If you have an access modifier infront of a variable declaration, it has to be within a class making the variable a field. Or am I wrong here?
modern c# (and apparently modern unity) designate PascalCase for public fields
historically, unity has used camelCase for public fields.
maybe the tutorial is just old and referring to the older standard, the new one seems to have been written in 2025
making the variable a field
which detail are you saying makes this a field exactly?
it's phrased ambiguously so i can't say for sure whether you're right lol
It's a field because its within a class.
it has to be within a class because its public
it has to be within a class because it's a field
you have the right idea about what can do what, but not the right causal link
it can be public because it's a member - fields, props, methods, constructors, and nested types can all have the same access modifiers
no it is public because that is written in the quiz
there is no class anywhere. I'm assuming there has to be
are you asking about the specific quiz question or just what's legal in c# then
one of these seems a lot more useful than the other
the field in the quiz must be a field in a class because that's the only valid context for it to be, inferred from it having an access modifier
but the access modifier isn't what makes it a field
int jumpHeight = 4; this could be a field or a local, no way to tell without more info
Fields were always lowercase iirc
this newer article seems to use the c# standard
Pascal case is a variation of camel case, where the initial letter is capitalized. Use this for class, public fields and method names in Unity development.
Interesting.
I think this quiz answer is a hot take: "Player input should be handled in the Update() function."
But at least it's what the course teaches.
Yes that's correct. You want input in update, physics in fixed update
Does the new input system check input every frame?
Is there a way with the old input system to not have to check input every frame?
Oh I guess it does^^ Maybe its not that hot of a take after all.
Kind of. The events that get fired are called in the update loop, and polling works the same as the old input manager.
Depending on how you've set up your messages, it'll be kind of weird in that it'll be in a different object's update. Whenever your input action's script updates, it'll fire all of its subscribed events, even if they're in other scripts that haven't done their update for this frame yet.
So, it's a little weird in cases where you're using callbacks
You're overthinking a bit. A few bool/value checks every frame is nothing in terms of cpu time. Besides, on the low level, everything is basically "polling". Especially when interfacing with the hardware.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControllerX : MonoBehaviour
{
public GameObject dogPrefab;
// Update is called once per frame
void Update()
{
// On spacebar press, send dog
if (Input.GetKeyDown(KeyCode.Space))
{
Instantiate(dogPrefab, transform.position, dogPrefab.transform.rotation);
}
}
}
I want to know how can I add a time limitation to instantiate next gameobject after the previous gameobject is fired.
like in this case I have a dog when I fire it or instantiate it, I want to add a limitation to spawn next dog after some timeperiod (2sec).
You could have another float field that would act as a timer, each frame you would add deltaTime to it. Before spawning the dog, just check if the timer is over some threshold - if it is, spawn the dog and reset the timer to 0.
I'm not sure how to implement it... its new for me
Make a field in the class itself (e.g. private float timer;) and add Time.deltaTime to it each frame - this way youβll create a timer that will just add time to itself based on the time between frames. The other part is just a if statement and a value assign
I can do something like this:
private int spawnInterval =2;
if(keycode == space && Time.deltaTime > spawnInterval ){
//spawn a dog;
}
but I am not sure how to access current time and how to store it so that I can keep record of it after 2sec, after spawning a dog I can just reset it back to 0.
No, you need a timer I mentioned earlier. Now your code checks the time between frames - so it will fire only if the game is laggy enough to have 2 seconds between two frames
I would make a timestamp when sending. and check the difference to that timestamp when you want to send again.
That could work too
yes, time.deltaTime give the time difference b/w each frame. it remains less than a sec generally
so how will I make a time using it?
how can you record the timestamp? which function
correct me if I am wrong :
void Update{
private float timer = 0 + time.deltaTime;
if(timer > 2){
//spawn a dog
}
}
@chrome tide
// In class but outside of update
private float timestamp;
// In update
timestamp = Time.time;
what does Time.time function do?
it keeps track of timestamp?
You need to create the βtimerβ in the class, not update.
Yeh exactly like benji said
let me just read it
thankyou guys @brisk edge @chrome tide
private float timer;
// Update is called once per frame
void Update()
{
timer = Time.time;
// On spacebar press, send dog
if (Input.GetKeyDown(KeyCode.Space) && (timer > Time.time + spawnInterval ))
{
Instantiate(dogPrefab, transform.position, dogPrefab.transform.rotation);
timer = Time.time;
}
}
I think I should use timer = Time.time in start function
you need to not do it every frame
the conditional check there doesn't make sense
timer is in the past, you're checking if it's in the future
I've wrongfully assumed performance benefits. I didn't realize it was polling on the lower level. I often read in discussions of event driven vs polling that there are performance differences. I would say event driven would imply doing something based on events and not doing something every frame. The new input system is event driven.
A few checks every frame: You can always design a scenario / game where a few checks every frame can be detrimental.
Just increase the amount of playable characters until it is.
event driven vs polling on your level just refers to how you receive input from the input system
imo, just don't worry about perf/internals at this stage
if you're curious, sure, go learn that on its own and then come back to relate that to what you already know
A few checks every frame: You can always design a scenario / game where a few checks every frame can be detrimental.
Just increase the amount of playable characters until it is.
This is kinda distorting what I said. Obviously if these checks bubble up to million checks per frame, that's gonna be a bottleneck. Notice how I said "a few"? That being said, if you have a miliion of objects all running the same code(checks) in update, it's an architecture issue on a whole different level. The issue is not the checks but the fact that you're updating million of these objects per frame.
fair
how to i properly paste the code in?
[SerializeField]
private float duration = 2f;//Cooldown duration in seconds. Default(2). Change the value in the inspector.
private bool Ready => Time.time > previous + duration;``````cs
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && Ready)
{
Instantiate(dogPrefab, transform.position, Quaternion.identity);
previous = Time.time;
}
}```
post my code that is
like this
!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.
Your options are to use an external service for large code blocks or backticks for small snippets (inline)
oh whatever so i have this code that i yoinked from dani and modified myself to fit my game + new input system:
https://paste.ofcode.org/VsHU4gkuWYfp2UwjPFvGpj
but when i land in game theres a hit of intertia. i know that the counter movement script causes this, and I know that if i put "if(grounded) return;" as a line, but if i do that then the player accelerates very quickly in air.
you should not have Time.deltaTime in those AddForce calls
yeah, like i said i just yoinked the code and modified it slightly
is that supposed to deflect or something lmao
kind of
ive made the change, but yeah im very new to coding
in c# anyway
ive coded like everything else in my game
but i hate coding movement ;-;
im giving advice, i don't particularly care how it came up tbh - it's a common beginner mistake, i understand lol, you don't need to provide explanations/excuses
is the unwanted inertia in question horizontal or vertical?
it's sinking into the ground?
Unrelated but personally coding movement is my favorite part lol it's all just a bunch of math π
btw, keep in mind that OnCollisionStay will trigger after the physics tick, so it'll be a step behind
ahah
ohh ok well frick dani bro
The structuring for it to actually be expandable and usable tho is annoying
er what exactly is the behavior you want and what is current behavior that you don't want
yes
aight 2 secs
As it should. Why would hVel not drop?
You land on the floor, you stop on the floor
bro i know im asking how to avoid this
its physics, i want physics but not physics
if that makes sense
so when you land after jumping, your horizontal velocity comes to a halt
as it should, it makes sense physics-wise
but i want to find a way to make it so that it doesnt
you want to maintain momentum when you land on the ground?
can't see previous variable anywhere in this code