#💻┃code-beginner
1 messages · Page 626 of 1
what happens when you change to this tool?
I can click the snap points but dragging does nothing
The cursor changes to the arrows you would normally see, indicating an intent to allow for adjustment.
I CAN still click/drag the yellow Text Mesh Pro boxes
this isnt in a layout group or something right? does it work if you make a new scene and spawn a new canvas + image?
What is a layout group?
And yes, a new scene works. Like I said, feels as though I must have toggled something that is really well hidden...
layout groups auto set the width/height and position of its children depending on its settings
same for other components like aspect ratio fitter
Well I haven't done such a thing intentionally. Given I can still use the inspector to fully customize the objects, that also wouldn't seem to be the case?
At the top level I have a Canvas of type Screen Space - Camera. It uses a Canvas Scalar for Scale with Screen Size, Expand, which is how I usually approach mobile dev Canvas spaces.
Below that is a Rect Transform of type Expand. And below that are the various elements I cannot edit.
They are all set for a center anchor point on their Rect Transforms.
But even global objects in the scene cannot be edited. I have a group of Manager objects that are just off-screen, and various other housekeeping objects that exist on top of the heirarchy. They too are uneditable live in the scene view.
can someone help. i have been trying to implement ads to my game for around 2 days now and spent over 10 hours on it, it just wont work i tried the unity advertisment legacy package and now i am trying the levelplay mediation. just someone please
Does LZ4HC compression method have any peformance penalties apart from longer loading times? Can't find a definite answer
see #854851968446365696 for what to include when asking for help.
Have you marked any of these objects as static?
A full screenshot of the entire Unity editor with such an object selected might help
Will do, and no nothing is marked static.
mate you haven't even specified what part you are actually struggling with. and this is a code channel so we expect to see the relevant code. if you don't want to actually provide the useful information that would make it easier for someone to help you then kindly fuck off so other people can get help
i am strugling with basically everyhting, no need to get salty tho
Ok try this? I just right clicked and added a New Empty Object.
It also cannot be modified in-scene.
so then what, you want someone to hold your hand and walk you through the entire process? if that is the case, then go read the documentation
basically yeah, i dont know any code really. i am being honest
then start by learning wtf you are doing. there are beginner c# courses pinned in this channel to get you started
i made eveythign with chat gpt, why would i learn coding if it can do it all, it did all but the last part in my project was adding ads and now i am stuck. so i came here to ask for help
lol no wonder it won't work. the bullshit generator was generating bullshit for you
kinbd of shot my self in my own leg with not learning
And thus did he learn, that ChatGPT could not, in fact, do it all...
no everyhting else works liek a charm
yeah
well we don't help with AI generated bullshit here. so go learn c#
check your layers as i think there you can change interaction stuff too
iu thougth people would be nice here and not hostile. i would save a lot of time if someone just helped me a bit and i would pay for it. other wise i would have to learn coding just to add ads to my game, but i agree with you
if you want to pay someone to help you then post on the job forum 👇 !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
if you want someone to help with your AI generated crap, then go somewhere else.
if you want to actually learn, which is what this server is for, then start by learning the c# basics since you claimed you don't know them. there are beginner courses in the pins
i dont have time for that, but thank you
Can’t teach someone calculus when they don’t know their abcs, respectfully. It’s just not what these channels are for
i dont need teaching, i just needed for someone to do it for me for a price
and we don't allow collaboration or job posts here as the bot message said
Hence me saying that’s not what these channels nor server is for
i dint know that, sorry.
then read the information provided to you
thank you for tellign me where to look
you would also have known that if you'd bother reading #🔎┃find-a-channel like you were instructed to 20 minutes ago
true
When I went to windowed mode in game and then back to full screen these black bears appeared where the windows top bar UI was, does anyone know why?
if (Input.GetKeyDown(KeyCode.F11))
{
Screen.fullScreen = !Screen.fullScreen;
}
well that code wouldn't have caused black bars to appear. if you have some sort of letterboxing set up (which is not something built into unity so you would have had to download an asset or set it up yourself) that may have caused it. otherwise it might be a bug of some sort (possibly driver or display bug or an engine bug)
Im confused because they didnt exist when the game first launched in full screen until i pressed F11 to go to windowed mode. Now it is there even after i relaunch the game
Nothing seems amiss?
If anything was locked I'd expect to not be able to actually edit it in the inspector, you know?
has to be something with those objects then 🤔 can you show all the components on one of em?
I did already above where I added a new blank empty game object to the bottom of the scene.
Such a strange thing to run into. I spent years working in Unity 2021 w/o this happening. And its been months in Unity 6 before this popped up out of nowhere.
unless there are new options that affect this stuff in the scene view im not sure what it could be
No worries, I appreciate your taking a look. Probably some silly Unity 6 bug/corruption... I can still do everything I need by dragging the invisible sliders over the inspector variables at least.
yet here u are
people put alot faith in those things...
feel similar to me as bringing my cellphone w/ me on a commercial airliner..
asking chatgpt to help me fly across the country and expecting to live thru the experience
it accually did good job made me a whole working game, but the only part it couldnt help me was with the ads, hope it wont replace coders in a few years
anyway.. back to the question. I don't do Ads so i can't honestly provide any help
i can wish u best of luck tho 🍀
thanks
u might find some useful stuff on the unity discussions forums
lol, i figured
you need to use the correct type..
i think its TMP_InputField
ok let me try that
"Assets\NewBehaviourScript1.cs(59,30): error CS0119: 'GameObject.GetComponent<T>()' is a method, which is not valid in the given context"
this is a syntax error... ur code probably is out of order.. (a function outside the class or something weird like that)
these errors are meaningless without showing us where its underlined in IDE
at very least show whats on that line number
soo many things about that line makes my head hurt
Sorry hold on ill try fixing it and if i still cant ill send more stuff
if u use SerializeFields u can drag and drop the component right in the inspector
ir ur using GetComponent.. make sure ur getting the exact same type
this is the code i wrote i might have done something stupid on it
So..i'm trying to get this item to self destruct when collides with the player, they do collide in playmode but for some reason nothing happens, why?
(Yes i have set the player tag to player, yes i added the item into the variable in the editor)
https://screenshot.help/, but also, !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/, https://scriptbin.xyz/
📃 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.
No
Be mindful, if someone requests your code as text, don't send a screenshot!
chatyou = ChatBubble.GetComponent<TMP_InputField>.m_text();
missing parenthesis
👇 @toxic quiver
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
Discord is not launching on my pc
Are you sure this code is running
Well it certainly isn't because nothing happens
And also every other game object with collisions towards this gameobject doesn't work aswell
Start using Debug.Log. Put one before the if statement.
And if that's not running at all, then you don't have the appropriate conditions in the scene for OCE2D to run
The Three Commandments of OnCollisionEnter2D:
- Thou Shalt have a 2D Collider on each object
- Thou Shalt not tick
isTriggeron either of them - Thou Shalt be moving via a 2D Rigidbody on at least one of them
IEnumerator IdleMove()
{
while (true)
{
IdleMoveUp();
yield return new WaitForSeconds(3f);
IdleMoveDown();
}
}
void IdleMoveUp()
{
transform.DOMoveY(transform.position.y + 2f, 5f);
}
void IdleMoveDown()
{
transform.DOMoveY(transform.position.y - 2f, 5f);
}
Why does the object keep moving up with this script?
If anyone is familiar with Dotween
not really related to scripting, but are colliders hollow?
all colliders aside from Mesh Collider are convex so no
shit
am I doing something wrong?
now i need to find a sphere mesh
how do you know thats the proper Random class?
what are you actually attempting to accomplish? (also mesh colliders are hollow too)
Try UnityEngine.Random.Range
a sort of zone that stuff can be spawned into
Random random = new Random()
hard to explain
just make it a trigger?
why do you need a collider for that?
Look up maths involving points inside a sphere
ok this works thanks
to check if the thing is inside of the zone or not, TOTALLY forgot about istrigger thing
do you know Why it works though?
well for a spherical zone, it's literally just a distance check. otherwise there are Bounds you can use
Yes it's due to ambiguous reference, System.Random and UnityEngine.Random are different classes, gotta specify which one to use
okay
thanks for the help!
thats not the issue
Shit I don't know then
Uness Rider doesnt underline it at all
it sort of is though, seems like they were using a different Random class than the UnityEngine one if using the fully qualified name fixed it
Anyone know?
i'd bet they have their own Random class
Yeah but shouldnt there be an ambiguous error ? since they supposedly have both namespaces?
maybe yeah it wasnt even from System.Random
Same for me
oh rider is different
it goes into UnityEngine namespace then Random namespace then returns the Range function
this isn't quite what nav was referring to. using the fully qualified name completely bypasses the error nav was expecting
Random is not a namespace
normally even just putting Random threw ambiguous error thats why I got confused myb
mine stops at Random not Range 😢
yeah that would normally be it if they had using System, but i'd be willing to bet they have their own class called Random and is likely either the type they were currently working in or is in the same namespace as the type they were working in
Yeah this makes more sense
anywhoo if you have multiple spots to use Random if you dont want to always type out the fully qualified namespace, you can do
using Random = UnityEngine.Random
Is this the same person as earlier this week?
cuz someone had this exact random problem
issues with the Random class are pretty common, but it's usually due to System.Random
yeee, the other one wasnt which is why i asked, probably nothing
Ya some times you don't even realize the System namespace is there
I think visual studio adds namespaces based on what it thinks
yeah its sneaky sometimes
Yeah
so many times i had VisualScripting namespaces, like what?
Like for vectors system.numarucs and unity engine
gotta pay attention to what you are autocompleting
Got that right
Well gtg
Bye
speaking of which, anyone know sometimes why using Mono.Cecil.Cil; is added ?
No idea
guessing this something to do with IL or something..
can someone explain me Transform?
Im spawning an enemy and it just falls through the ground here is my spawner script code (the original enemy does not fall through the ground but the enemy that spawns through the spawner does) https://paste.mod.gg/ndnocokhwnto/0
A tool for sharing your source code with the world!
maybe forgot to apply a hit box on him or smth
what about it?
it's the component that describes the object's transformation in the scene
hierarchy relationship, scale, position, rotation
and what about the translate?
that's position
that is a method on the Transform class and the documentation makes it pretty clear what it does
hey so im making an animation to play when i shoot a gun but it seems to be looping when i click and the loop is turned off can someone help?
A tool for sharing your source code with the world!
unless you literally mean "what is an object's translation" in which case, yeah, it's the position
its there
pro tip when using paste.mod.gg: include the .cs file extension in the file name so it provides proper syntax highlighting
The code you shared is completely unrelated to any animations
the only thing I see in there is playing a particle system
it's in the second file in the link
mbmb
most likely an issue in your animator state machine
wdym?
I'm using DrawMeshInstancedIndirect() to render a bunch of quads with a compute buffer storing their positions. The issue is that when I need to add more positions dynamically, I have to overwrite the entire compute buffer every time, instead of just appending new points. This causes the performance to tank because the GPU buffer needs to be reallocated each time. Does anyone know what to do instead?
the issue is probably in how your animator is set up
i dont know what could be causing the issue like the loop is off and the Has exit time is also off
for what does the zero stand
the 0 stands for 0
yes but why is there a zero
you should start smaller, there are beginner c# courses pinned in this channel that you should start with instead of skipping straight to learning unity if you don't know what numbers are for
Maybe use the newer version, RenderMeshIndirect:
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Graphics.RenderMeshIndirect.html
It lets you pass in a commandCount so you can have a larger, preallocated, buffer with some headroom but only draw the amount of meshes that you actually have
ik what numerbs are for and stuff but i dont understand where there is a 0
okay, then let me rephrase
if you don't know what
numbersmethod arguments are for
Oh I didn't know I was using an older method thank you. But how does this solve my initial issue?
I need to write to the buffer like every frame and it is not really efficient with my current method
So that you don't have to reallocate the whole buffer when it grows larger, unless you exceed the count you first set it to
Oh hmm, what do you write into the buffer?
Does it have to happen on the cpu?
Oh cool that would be perfect then
Yeah I am raycasting and I need to store the hit position to the buffer so I can render a mesh
Some sort of scan effect?
Lidar effect yeah, similar to scanner sombre
Ideally you'd do that all on the GPU with some depth buffer tricks etc
I already have it set up to render thousands of quads with a shader and it works fine, the issue is adding new positions. With DrawMeshInstancedIndirect() it seems to reallocate the whole buffer each time
Tell me about it
Just saying that the bottleneck is often the CPU -> GPU bandwidth
With the current method you still need to send a bunch of data from the CPU to GPU when the buffer changes, I think
So optimally you would do it all on the GPU
But that's a bit more advanced
i have a ton of missing textures and im not sure why
Yeah well I tried a few other things but it quickly grew out of my grasp. Looked into, but didnt try, buffers I could append to or doing the raycasting in a compute shader
I have a script and gameobject enabling sth, where do I put inside the object its supposed to enable?
Can you rephrase that?
not a code issue, but you've downloaded an asset that was made for a different render pipeline than the one you are using. you need to fix the materials so they use shaders from your current pipeline. if they are made for BiRP but you are using URP or HDRP then you will have a convenient material converter you can use
so i know where to ask for next time where do i go for asset issues like this
kk
I looked into trying to raycast using a compute shader but I would have to implement raycasting from scratch
Or ComputeBufferType.Append but I am not sure if it will help
But it got very difficult
anyone know how to sort this? ive deleted library and still cant get it to go away lol. was fine till i moved project and downloed from version control...
How can I make the object not blink at it's spawn position? (SetActive way doesn't work because you can't teleport a GameObject in SetActive(false)
lines I have the problem with:
Rigidbody2D coinRb = Instantiate(coinPrefab);
coinRb.position = new Vector3(spawnX, 0f);
void Update()
{
if (Time.time > _nextDropTime ) {
_nextDropTime += _period;
float spawnX = Random.Range(_dropperStart.transform.position.x, _dropperEnd.transform.position.x);
Rigidbody2D coinRb = Instantiate(coinPrefab);
//coinRb.gameObject.SetActive(false);
coinRb.position = new Vector3(spawnX, 0f);
//coinRb.gameObject.SetActive(true);
float flyX = Random.Range(-10f, 10f);
coinRb.linearVelocity = new Vector2(flyX, -5f);
}
}
Try setting the position of the transform property rather than the position of the rigid body property.
The rigid body property called position would update the position using the physics simulation, which may occur too late and produce what you're seeing - there might not have been a physics update that frame.
Rigidbody.position allows you to get and set the position of a Rigidbody using the physics engine. If you change the position of a Rigibody using Rigidbody.position, the transform will be updated after the next physics simulation step.
coinRb.transform.position = ...```
oh yeah thanks I forgot rigidbody stuff update every FixedUpdate
using UnityEngine;
using UnityEngine.SceneManagement;
public class ButtonAction : MonoBehaviour
{
public GameObject pauseMenu;
public void QuitButtonAction()
{
Application.Quit();
}
public void ReturnAction()
{
pauseMenu.SetActive(false);
}
}
anyone's got an idea why the button does not actually disable the pauseMenu?
I'm assuming you're asking why the function is still called even if the unity object is not active?
Calling functions from non active objects will still operate. An object being active or not simply affects whether it's Unity callback methods would be running or not.
ReturnAction which is the action assigned to onClick component of the button is not through ButtonManager object is supposed to disable the pauseMenu tree, but it does not
also the transitions arent working but thats not as important as that
You can absolutely teleport disabled objects. The only thing i can think of kinda like that is that you can’t give disabled NavMeshAgent’s a new destination
hello would anyone have some time to help me with making the horse jump when i press the spacebar when the horse has detected the jump?
Basically when the horse approaches a jump it will raise its head which should mean the horse is ready to jump, then press spacebar to jump. but im not figuring out why it wont jump at all :D
None of the debugs in the jump void work at all
Ill send the code if anyone is available to help also im working on 3d unity
In both images, the pause menu object in the hierarchy is inactive. It seems to be doing what you're telling it to do What's the problem?
when it is enabled using esc key, which does work properly I cannot disable it using the button
Use a different key for testing in the Editor as the escape key removes focus on the Unity Editor.
Where do you assign pauseMenu in your ButtonAction script
still nothing after assigning to space
do u have a graphics raycaster on ur canvas?
oooh i think i know the problem.
(not related to the topic)
the script is contained in ButtonManager which is used in onClick component, where function ReturnAction is called
So with a different key to enable the object, you're still not able to set the object inactive using the button? Are you able to set the object inactive using the button if it's active by default? (Is the button working at all?)
it does not work even if canvas is enabled by default
So your button setup has probably got some issues. You may want to provide an image of the inspector of your button object (components and all)
how i fix this when i use unity version control
the highlighting doesnt work either and its the case with all the buttons because quitting button also doesnt work
how i fix
Can you show the inspector for your canvas?
i need help fixing this when i use unity version control
please can i have help fixing this
Not sure if that's got anything to do with coding. If not, try asking for help in #💻┃unity-talk
I have a coding structure question: So, I want to make sure my game is suited for turning it multiplayer, although im not worried about that for now, meaning there is a player prefab and i want only its movement and the player's stats to be individualized.
However, a problem I've come accross is overusing singletons to manage. For example, I have a PlayerStatsManager, managing high scores, levels unlocked, etc. Also, I have a CheckpointManager that stores the player's last left off checkpoint in each level
However, I also have a PlayerResetManager that keeps track of the resetting of the player and the ongoing timers the player has in each level that saves when they leave mid run.
Im aware this is not a good structure, but I don't know if I should simply make a couple more singletons and have like 7 singletons, one for timer, stats, checkpoints, resetting, etc? Or if i should make one GameManager that does a lot of these things by itself.
!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/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
https://paste.mod.gg/mmtxobdavirp/0
I try to pause my game. It works because It enables my Pause Menu. But I can still play the game in the background. What am I doing wrong here?
A tool for sharing your source code with the world!
I want to make sure my game is suited for turning it multiplayer
you've already fucked up by not building it with multiplayer in mind from the start. multiplayer isn't something you can just slap on later, you have to design everything with it in mind from the start or else you will just end up refactoring everything as you attempt to implement it.
PlayerManager can simply just contain the list of players w/ ids instead of a single player.
not really helpful
More that you should have a list (dictionary is better for ID lookup ) of NetworkPlayers on your NetworkManager
oh thats a good idea making a player manager
🤷♂️
just preparing you for the reality of needing to refactor everything later because you decided way too late to start thinking about networking
you dont know any context and are not being helpful. This is my first time making a game and I need to learn how to do all this stuff, and my game isnt very large, it only consists of 2 scenes with very basic scripts that I have already starting remaking from scratch
you can start refactoring things now with some advice that people might give you, but it won't be enough. you'll be doing it again when you actually implement multiplayer because, again, multiplayer isn't something you can really just implement later on. it has to be planned from the very start or else it will be loads more work
ill keep that in mind
yeah so if this is your first time making a game, then ignore that multiplayer exists. you definitely do not have the experience to do it.
plan for your third or fourth game to have multiplayer, not your first. your first game is going to be a mess. don't make it 1000 times worse by attempting to brute force multiplayer into it later on
It sets my Time.timeScale to 0 indeed. But I can still play the game. I do not have any checks for my player movement or any other script. I thought setting it to 0 would pause everything.
add angular drag/damping, perhaps
really the hard part of multiplayer is interoplation and all that jazz, but if you stick to a strict server authority approach it's just an extra step of asking the server if they can use their input
and if you don't care about some client authority then let them do w/e they want with the camera since it's not like you're making the next new counterstrike
more conceptionally difficult in the implementation
Games like Risk of Rain are purely client authority, so if the client says they warped 100 units in a single frame then the server will be like "ok that's fine"
and tell everyone that it was legit
It will make Time.deltaTime return 0. That's it.
Well I thought it would stop all Update and cause me to not move around at all
yeah
I think I need to add checks on my scripts and return if isPaused true.
No, if it stopped all Updates from running, how would you ever change it back?
That I never thought of.
Damn. I gotta go into all my scripts and add checks.
Yes, that's basically how pausing will need to be done for anything more complex than a physics demo. You'll need your own method of disabling things
I should've done it from the beginning and not the end of my project. Thanks digiholic.
u not noticed anything odd in ur scripts this whole time?
Not at all. Its my first game...
I am trying to instantiate a gameobject, but I am having trouble.
It appears the gameobject I am instantiating, is not being sorted in the grid layout group I have. The grid layout group is a child of a scroll rect in the canvas. Adding objects manually before startup works just fine, but it does not work when instantiated.
Not only do these gameobjects not display anything (perhaps due to the content size fitter as they are outside of the scroll rect), but they are also way outside the scroll rect and changing their transform.position does not change that. Anyone know how I fix this?
Use the form of Instantiate that doesn't take position and rotation
Basically just remove that Vector3 and quaternion from the Instantiate call
Pass in the content.transform as a parameter instead
And get rid of the set parent call
Thanks that seemed to change their positions! Thanks for the quick response. However, both their text and their image is not being displayed.
Oh why should I change the set parent call? This code is on the GameManager gameobject. If it's not used, it just gets instantiated randomly in the scene
Because you need to pass the parent in as a parameter to Instantiate
As I said
It will be parented automatically
That does make sense, thanks
Instantiate(prefab, parent)
Yup, that worked. Thanks! Still I am having the issue of the text and image not appearing under the gameobjects, but that may be because I deleted the original gameobject before instantiating. Will try to find a fix
hey i really need help. even though it all seems good in my inspector, my button that appears to play againg doesnt respond at all. i've been trying to debug this for like 4 hours using chatgpt and deepseek but no result. thanks!
Doesn’t work how?
like when i press the button it does nothing, it doesnt even show up in the logs i set up
Do you have an event system in your scene? Is raycasting and button interactability enabled?
there is an eventsystem and i think rycasting is enabled but i cant find it again so im not sure
and interactibilty is enabled
Should be on the image component on your button. Ensure it’s checked. If it is, then you probably didn’t set your onclickevent correctly
got the graphics raycaster on ur canvas?
are you talking about raycast target?
i figured that'd also be one the the first things chatgpt mentioned too tho
just checking
no no other canva's are blocking?
Your script is on an active object and the raycasting isn’t being disabled at runtime right?
where could i check that?
have u checked out the EventSystem info
Same way you checked during edit time, but when the game is running. Also, if your script is on an inactive object, the object in the hierarchy would be darkened
the only place that manages the click is in the inspector
i could share my code if it helps
or my settings or whatever
tag me if you have any ideas to fix my problem thanks
the best i can do is look at ur inspectors..
probably start a thread and share a screenshot of ur canvas selected and its inspector,
the root of the button and its inspector, the part that has the event on it.. all that stuff
if ur not using scripts then it has to be a set-up issue.. the question is where
may be beneficial to just restart on a new canvas..
do just a single button.. and get that working first
then moving on -> https://discord.com/channels/489222168727519232/1350959268131639326 thread
https://www.youtube.com/playlist?list=PLFt_AvWsXl0fnA91TcmkRyhhixX9CO3Lw this was my fav while learning
check the pins as well
Yes but they don’t reccomend youtubers
b/c thats not the best way to learn
Why?
does someone know a good video for Inventory System with hotbar for 3d ?
cuz its typically "follow me and now you have this" .. and most people learn nothing more than that
if they want to modify it.. they can't
and then they're looking for an even more specific tutorial.. which wont exist
There is a video of CocoCode. Its for 2d but you can just adjust it.
https://github.com/SpawnCampGames/Resources/blob/main/101/readme.md i have a few youtuber scattered thru my 101 github page i made a while back
maybe look thru it
Yeah true, and then they want sell his courses
Thank you so much, I’m using unity learn but when I’m not at PC I want see videos
im working on collecting good yotube tutorials.. after i do im going to create my own playlist w/ them all included.. i'll add it as a note on that page..
Thank you for doing this, have a good continue
no problem.. hope u have a great journey! 🍀
LLiamAcademy is a another good all around youtuber
watch then do best advice i ever herd
https://www.youtube.com/@BMoDev/videos and this guy brings the optimizations
my first 2 months was, pause video -> open unity
re-open video -> rewind -> find the thing i was originally looking for..
-> go back to video -> unpause -> rinse and repeat lol
ive since learned better practices.. and have filled up countless of notebooks
I've been working on this snippet of code for about 3/4 hours and it STILL DOESN'T WORK... The camera is the problem, when I get in the car the camera is VERY far away from the car... Full code: https://paste.ofcode.org/7jBXkk4MUQfkCbdQURwRWi
Hello. I'm following this tutorial (https://www.youtube.com/watch?v=-Iwsz4gdgyQ) and have received this error.
""SetDestination" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:SetDestination (UnityEngine.Vector3)
wonderCamp:Patrol () (at Assets/Scripts/wonderCamp.cs:32)
wonderCamp:Update () (at Assets/Scripts/wonderCamp.cs:27)"
"Camper1" is a human character/object that has the script and Nav Mesh Agent. "Terrain" is the painted landscape with the Nav Mesh Surface. To me, the error sounds like I didn't apply the Nav Mesh Agent to the Camper, but as you'll see in pics, I did and adjusted the layers as shown in video.
Today we're starting off a small mini series in which we make an enemy A.I. This first part focuses on making it patrol around, something that you'll want to re-use for a lot of different NPCs in most of the games you'll end up making!
get the Project here : https://www.patreon.com/posts/unity-3d-75458669
Join the discord for any help you nee...
You should make sure the agent is positioned correctly on the navmesh. Use the navmesh API to sample point on the navmesh, closest to your character position and move it there.
hey does someone understand why I cant pick up my item (sword) im trying to do an inventory system
https://pastecord.com/ilinujetuz.cs
I'm trying to be more cognizant of how often I put methods in update or fixed update. Is using Invoke Repeating a good way to help with performance if I want to, say, only check an enemy's line of sight a few times a second as opposed to every frame?
It seems like this is the direction I should go, but I want to make sure I'm not missing something in my ignorance.
how did you make a game with html exactly?
Hacked NSA with CSS files
Then ripped apart the mainframe from the fancy terminal. True story.
yeah not sure if anyone can help you with that ....
Lol I'll stop trolling.
Chat is dead rn though.
this isn't a chit chat server, support only. have a look at the #📖┃code-of-conduct
Yep.
I literally just asked a question and you pushed it up away from the beautiful eyes of those that might offer help.

This isn't a chat room this is a help channel
It's not something for you to try to "liven up"
Bumping this question
InvokeRepeating is going to be worse for performance than setting a value to itself in Update a few times
As long as what you're doing is itself not heavy, you can do it in Update fine. If you end up hitting performance problems you cna use the profiler to try to find which specific things are causing the problems
This function specifically checks distance, angle between player, and then raycasts (one raycast for now, potentially more towards other player body parts in the future if I choose to) to see if there is a line of sight.
I would imagine this would appropriate to put in invokerepeating?
Thank you for the response. If you have a good rule of thumb on when it would be more performant I'd appreciate that.
hey guys quick question, I have a tracker for my camera for a screen effect to go from 0 to 100 based on my roation(0 to 180 on y axis) from startYRotation to 180. My goal is to have the effect really start at 20 degrees going to 180 so theres a gap from 0 to 20 on y axis where nothing happens.
float angleY = Quaternion.Angle(startYRotation, currentYRotation);
float lerpedDither = Mathf.Lerp(DITHERSPREAD_START_AMOUNT, ditherSpreadChange, (angleY / 4f / 180f));
If it's just math, and it doesn't involve any loops, reflection, or certain Unity methods (mostly Find and it's ilk), you're probably fine.
I see. I guess that's ultimately where using the profiler comes in, then, too.
Thanks again for the help.
If you want literally nothing to happen from 0 to 20 you could just use an if statement and pass 0 to the lerp percentage
You can also clamp your value to start at 20 I think.
er
Wait I'm dumb scratch what I just said.
would this mess up the fade in? I want to avoid the effect just popping to like 30%. trying to keep it smooth
I figured the "pop in" was what you were going for. Otherwise, just set your start point at 20 and lerp from there
Although it's sounding like the interpolation you do want is anything but linear, so maybe lerp isn't what you should be using at all
Maybe an AnimationCurve? Despite the name, they can be useful for more than just animating
thats where im kinda stuck on since im keeping the start point on where the camera starts when I click play since I might decide to move the cam later
if I'm understanding correctly, would this work?
float lerpedDither = Mathf.Lerp(DITHERSPREAD_START_AMOUNT, ditherSpreadChange, (Mathf.Clamp(angleY - 20, 0, 160) / 4f / 160f));
This is the third blog post by Christo Nobbs in his series for game designers. The series expands on his contributions to The Unity game designer playbook, a 100+ page in-depth guide that instructs game designers how to prototype, craft, and test gameplay in Unity. Links to Christo’s previous blog posts are included at the end of this piece.
Then your anglyY would show up as 0 until after 20 degrees
then go from 0 to 160 instead
da friken goat
I try; hopefully I didn't misunderstand and make it worse for you
does anybody know the equivalent to on trigger entered in 2d to 3d
i see, this is what I was trying to do thank you
Yes. It’s OnTriggerEnter2D
OnTriggerEnter
2D in unity is 3D taking off an axis
i figured out my issue
i just spelled "collectible" in the tags menu wrong
works now
i thought it was the detection itself
intellisense cant help string typo tho 💩
and this is why you should be using the CompareTag method rather than string equality to check an object's tag
Hello, I'm making a 2D game and I want to put a bunch of trees around the border of the environment and throughout it to make a maze-like forest. However, it seems inefficient to create a game object for every tree so I was wondering if there's a way to do this within the script. I came across the terrain system but it looks like that's for 3D only
Inefficient in what way? Performance? Or too much handiwork?
Performance, but maybe I'm wrong. Is it normal to create a game object for every tree?
You should avoid worrying about performance until there's an actual issue. Test it with gameObjects and see if there's a considerable performance drop. Use the profiler if needed.
That being said, In 3d, you'd usually use the terrain system. In 2d tilemaps or something.
But big number of objects in 2d is not as critical as in 3d as most of them would be frustum culled.
Using tilemaps is a solid approach if you are worried.
Ah, a tilemap makes sense. Thanks, I know what I need to do now
Would an OnSceneLoaded trigger AFTER all the awakes of the scene?
how should i go about pathfinding for a 3d tower defense game?
Yeah afaik
Unity's nav agents and navmesh works fine
Usually tower defence games have a set path. I'd probably not go with navmesh if you were looking to do have a lot of objects, which naturally tower defence games have.
so how should i do it then
i mean i have a small test set up with a navmesh that seems to be working ok
A path can simply just be a list of positions. When I think of tower defence I think of like the bloons tower defence games. If you want enemies to move along the exact same path I'd just define it with a list
If you want it to be more random, I guess kinda like zombies then navmesh can work
Depends on what kind of game you want
public class pathFinding : MonoBehaviour
{
public List<Transform> navPoints;
public float speed;
private int currentPoint = 0;
void Update()
{
Vector3 toNextPoint = Vector3.MoveTowards(transform.position, navPoints[currentPoint + 1].position, speed);
}
}
is this a good starting point? i know i need more for this to work but is this the right general idea?
This would probably be a pain in the ass to setup, unless you want each enemy to take unique paths in which case it'll be a pain no matter what.
I'd try to separate the logic so you have some other one place you can define where a path in the scene
ok
And you'd need some logic to actually increment current point but yea
so this is good i should just define the list somewhere else like in an SO?
Scriptable objects cant reference transforms in your scene so this will likely just be a monobehaviour
If it were one of those defense games where you're creating a maze with your defenses it would be the go-to.
I'd say just use it for the local avoidance, but it's pretty bad
If it's tile based you can use layers or modifiers on the tile prefab/s to restrict the navmesh really nicely
eg. this thing i made in december that just bakes for the enemies on these track prefabs
you can def. do with points and depending on the game might be better but your placing the path like this anyway you may-aswell use those paths directly
(and in this case you can use it in the opposite way where we sample navmesh position to prevent placing turrets on the track)
using UnityEngine;
public class pathFinding : MonoBehaviour
{
private navPointsList navList;
public float speed;
private int currentPoint = 0;
void Start()
{
navList = GameObject.FindGameObjectWithTag("navPointsList").GetComponent<navPointsList>();
}
void Update()
{
if (navList.navPoints.Count > currentPoint + 1)
{
Vector3 targetPosition = navList.navPoints[currentPoint + 1].position;
Vector3 currentPosFlat = new Vector3(transform.position.x, 0, transform.position.z);
Vector3 targetPosFlat = new Vector3(targetPosition.x, 0, targetPosition.z);
float step = speed * Time.deltaTime;
float distance = Vector3.Distance(currentPosFlat, targetPosFlat);
if (step >= distance)
{
transform.position = new Vector3(targetPosition.x, transform.position.y, targetPosition.z);
currentPoint++;
}
else
{
Vector3 direction = (targetPosFlat - currentPosFlat).normalized;
transform.position += direction * step;
}
}
}
Vector3 dirToPoint(Vector3 point)
{
Vector3 dir = (point - transform.position).normalized;
dir.y = 0;
return dir;
}
}
i got something working @eternal needle
(you can just do Object.FindFirstObjectOfType<NavPointsList> btw)
kinda nitpicking dw 😄
you should just use a singleton instead of either of those
whats that
(i have like 1 week of game dev experience)
it is a pattern to access a component when there should only be one,
to find implemenations in unity
its not specific to game dev
No idea where to put this issue so putting it here, having issues with unity editor not following my mouse while in edit mode it works fine if I hold down right click or go into play mode its 1000% not a code issue its some sort of setting in unity anyone know how to fix?
fixed it had to make my own script lol
void GetRandomPos()
{
var pair1 = GaussianRandom(0, 1);
var randomX = pair1.x;
var randomY = pair1.y;
var randomZ = GaussianRandom(0, 1).x;
randomX = randomX * 1 / Mathf.Sqrt(Mathf.Pow(randomX,2)+Mathf.Pow(randomY,2)+Mathf.Pow(randomZ,2));
randomY = randomY * 1 / Mathf.Sqrt(Mathf.Pow(randomX,2)+Mathf.Pow(randomY,2)+Mathf.Pow(randomZ,2));
randomZ = randomZ * 1 / Mathf.Sqrt(Mathf.Pow(randomX,2)+Mathf.Pow(randomY,2)+Mathf.Pow(randomZ,2));
newPos = new Vector3(randomX* moveRadius, randomY* moveRadius, randomZ* moveRadius);
}
Vector2 GaussianRandom(float mean, float standardDeviation)
{
float randomX = Random.Range(0f, 1f);
float randomY = Random.Range(0f, 1f);
var scale = standardDeviation * Mathf.Sqrt(-2 * Mathf.Log(randomX, 10));
var theta = 2 * Mathf.PI * randomY;
var randomPos = new Vector2(mean+scale * Mathf.Cos(theta), mean+scale * Mathf.Sin(theta));
return randomPos;
}
If someone knows math better than me: this is some box-muller algorithm that produces a pair of random values, I use it to move an object randomly within a certain radius.
I roughly understand how it works, but why is it producing points exactly on the sphere radius? I wanted an even distribution.
Any reason not to use this?
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Random-insideUnitSphere.html
Uh oh, I re-invented the wheel
Many such cases 😆
Hey! I have a question about how to code a trail that the player leaves underthemselves in my small project. So, my player has a limited resource that they collect at certain checkpoints, the amount of that resource determines how much the player can move. If the player runs out of said resources, they die. I want the player to leave a path behind them out of said resource (visually) every time they move. The path they "paint" stays on the map until they die or get to the end. Where would I start? Can't find any similar guides online other than trails (bullet trails, FPS dash trails, etc etc)
Trail or line renderer. But it really depends on what kind of visual effects you're expecting.
Basically something that acts like blood: the player takes a couple steps theres a path of blood that follows them. Over time the path turns a darker color but stays on the map. Nothing too visually intense like UE5 niagara (I don't know what to compare it to in unity lol)
Not sure how Niagara is related to anything, but line renderer should be enough.
Got it. I'll check it out. Thanks!
hey so im making a multiplayer game but for some reason when 2 players are connected i am controlling both of them at the same time and i tried turning off the main camera and the player movement script like it said in the video i was following but it dosent seem to be working
A tool for sharing your source code with the world!
so I am shifting from godot to unity and had a question regarding the physics bodies
In godot its largely preferred to use character bodies for custom controllers since rigidbodies could work unexpectedly whenever we set physics values directly
So most of the time we see people using character bodies in godot while most of the time whenever I look up tutorials in Unity I only see them using rigidbodies and implementing it like they are characterbodies instead
Is that safe and is it recommended? Should I just stick to characterbodies if I don't want physics? I wanna know. Thanks in advance
Also what problems could arise when using rigidbodies like characterbodies i.e, directly setting their values frequently
Hi, I would like to add a property to the UnityEngine.Timeline.TrackAsset but I can't figure out how.
According to Rider, it's not defined as partial, however, if I go to it's code on gh it's partial.
I am using Unity 6 with the latest version of the Timeline package.
What am I supposed to do?
uh, unity doesn't have anything called "character body" built-in
unity's rigidbody is the thing that interacts with the built-in physics system, anything else would have to do physics on its own, for example the charactercontroller, or implemented yourself
rigidbodies also have 2 modes, dynamic and kinematic, where dynamic receives forces while kinematic does not. perhaps that's the distinction you're thinking of?
partial classes can only be added on to within the same namespace. it's effectively not partial for you
i would heavily recommend against modifying built-ins, that could cause confusion if you ever ask about it here, or if you use it in the future having forgotten you made it, or if you implement it with a mistake
what are you trying to achieve with adding a property? https://xyproblem.info
My team decided to go with the approach of adding a property to the TrackAsset class as it'd be the least messy in the long run.
As for the namespace, I am pretty sure I am already in the right one, am I doing something wrong?
I don't know what I'm doing wrong. Movement works. Cursor toggle also works but my look action doesn't work I don't even get log in the console
public void OnLook(InputAction.CallbackContext context)
{
if (third_Person_Camera != null)
{
Debug.Log("Rotate Camera");
third_Person_Camera.OnLook(context);
}
}
public void OnZoom(InputAction.CallbackContext context)
{
if (third_Person_Camera != null)
{
Debug.Log("Zoom in or Out");
third_Person_Camera.OnZoom(context);
}
}
public void OnToggleCursor(InputAction.CallbackContext context)
{
if (third_Person_Camera != null)
{
Debug.Log("Toggle Cursor");
third_Person_Camera.OnToggleCursor(context);
}
}
well, what do the errors/warnings say?
#🖱️┃input-system actually wait
have you tried logging before the if?
yes
....and?
the same ^^
ok, let's go to #🖱️┃input-system then
Only look doesn't work all the others already
okay tahnks
thanks
so it should probably be public, but it might have to also be in the same assembly
so you might just be fucked
anyhow this is definitely not a beginner topic, so if you still have issues and you're determined to go this route, try #archived-code-general
Anyone able to help me? My camera keeps seemingly teleporting away from my character object when I press play
I have a weird issue with animator, so I want to achieve some kind of my own root motion, by modifying transforms to match the animation movement, and it works perfectly fine BUT only after i turn off and on the animator in the inspector. If I don't do that, then my character just goes crazy and bugs out and goes forward instantly. If i turn off and turn on the animator and then play the animation, everything works fine, why is that lol
void LateUpdate()
{
if (animator == null || agent == null) return;
var stateInfo = animator.GetCurrentAnimatorStateInfo(0);
bool isCurrentlyAttacking = stateInfo.IsName("Attack") && stateInfo.normalizedTime < 1f;
if (isCurrentlyAttacking)
{
agent.updatePosition = false;
enemy.position = defCharRoot.position;
agent.nextPosition = enemy.position;
}
else
{
agent.updatePosition = true;
}
rigParentHolder.localPosition = -defCharRoot.localPosition;
}
Don't post code in videos, it's too small to read anyway
See !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/, https://scriptbin.xyz/
📃 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.
Alr gimme a sec
I do recognize this part though... 😥
Oh Jesus I didn’t realize it got that compressed mb
I mean the * Time.deltaTime part, it's a common mistake, see this:
https://unity.huh.how/mouse-input-and-deltatime
using UnityEngine;
public class PlayerCamera : MonoBehaviour
{
public float sensX;
public float sensY;
public Transform orientation;
float xRotation;
float yRotation;
private void Start(){
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update(){
float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90, 90f);
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
}
using UnityEngine;
public class MoveCamera : MonoBehaviour
{
public Transform cameraPosition;
// Update is called once per frame
void Update()
{
transform.position = cameraPosition.position;
}
}
There's a space between cs and newline
Anyway, start with fixing the mouse, it will otherwise get jittery
Alr
Should it be a first person camera?
It is supposed to be a first person camera
My problem is that it keeps teleporting away from where it’s set
Its local position doesn't seem to be changing when you press play
So it's the parent (cameraholder?) that is being moved
Is this script on the parent of the camera?
yes
What transform is assigned to cameraPosition ?
the camera position object i have in my player object
anyone pls
What is the local position of CameraPos inside the player?
Im guessing it's not centered properly
this is where its at in the player
Then it is PlayerCam that is not centered
Set its localpos to zero
fixed thanks
now i just need to figure out why the camera starts by looking at the ground
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
yes it does
Your IDE is unconfigured, it's a guide on configuring it.
That's exactly what you asked for.
check if you have the Visual Studio Editor package installed in your project
that tells me only how to install it
Actually that's the one step it doesn't cover.
So, maybe actually read it before deciding it isn't what you want
look what worked for me last time involved the solutions for VS
which one is not the impostor?
wdym "not impostor" lol, they're both what they say they are
if you want coroutines, you'll want the non-generic one
ok
Hello guys ! I'm trying to make something really simple :
Have a VideoPlayer that takes an URL to my remote server that hosts a video
Play the video
But I'm getting this error :
WindowsVideoMedia error 0x80004004 while reading <myURL>
Context: IMFSourceReader::WaitForSample in StepAllStreams
Error details: Op볡tion abandonn맍
The video file seems fine since it works if I put it directly in Unity.
The weird thing is that it sometimes work, sometimes doesn't...
Any ideas what could be the root cause ? Or how to solve this ?
If someone worked with remote mp4 files before, is there a better option than then native videoPlayer ?
alright
I tried regenerate project files in the external tools preferences and it doesnt work
how can I compare layer (int) to ground (LayerMask)
it shows 64
yes, that's how bitfields work
A bitmask is a representation of many states as a single value.
Yes, that's what the mask representing layer 6 is when cast to an int
A layer mask is essentially an array of booleans stored in a number. You want a mask that can let through layers 3 and 4 but no others?
0000 1100
It's got a 1 in the third and fourth position, so it's got a value of 12
So, to check if your layer is in the mask, you need to do some bit shifting. Your layer is index 6, so you need a 1 in the sixth position. You can do this with the "Shift left" operator <<.
1 << n will produce a binary value of a 1 in the nth digit and 0s everywhere else. Then you can use & to compare it with the mask.
This'll give you a value that has 1 in every spot present in both the mask and the shifted layer. Since there's only a single 1 in the shifted layer, any int with a value larger than 0, means the mask contains that layer
It's not going to equal 6, it's going to equal 64
It'll have a 1 in the sixth digit, which is 2^6 which is 64
As I said, check if it's larger than zero not equal to zero
that's all you need to do
but really you shouldn't care about what position is there, you just care if there's overlap
check if it's not equal to 0, like the link boxfriend sent says. it's an int, not a uint
Oh, right, I don't know why I thought it was uint.
i mean, reasonable assumption, tbh.
I feel like it should be, since it's a mask. We don't need to bring twos complement into this
to be pedantic; bitwise stuff usually treats the lowest position as bit 0, not bit 1
bit n has a value of 2^n
Yeah, I knew that one but omitted it for clarity. That one was an intentional one, I tried to word things in a way that doesn't specify whether you're looking for layer number or layer index
I probably wasn't fully clear on that though
i assumed that was what you were going for, just felt like adding that footnote 👍
Hey all. I have a question... I am doing a pause game feature in my game. I have lots of coroutines that yield WaitForSeconds. And setting Time.timeScale to 0 makes my coroutines act weird. I have done some research but want to know what exactly is happening. When I pause the game on WaitForSeconds, unity does not keep track of where it was and skips counting and to the next line of code?
WaitForSeconds relies on the Timescale. If you set it to 0 its going to stop and not go anywhere
if you don't want that then you would use WaitForSecondRealtime
When I unpause the game then? It skips waiting completely?
I am using a time that I increment with Time.DeltaTime now to solve that. And it works.
yea deltaTime is just the amount between frames
not related to timescale nvm you need unscaledDeltaTime
Yeah I see. I am just confused what happens when I unpause inside the WaitForSeconds.
by setting Time.timeScale to 1 i mean by unpause
You mean you're expecting to resume ?
Well I expected it to resume from where it left off yeah
afaik just the way IEnumerator work, pretty sure it completely stops at the yield
So what is even the point of using WaitForSeconds?
doesn't it though?
Time between frames? why would it
Time.unscaledDeltaTime
Unlike deltaTime this value is not affected by timeScale.
ahh
deltaTime is multiplied by the timeScale
im wrong then
It will be at 0 when the game pauses though and start counting again then?
that is, in fact, all that TimeScale does
if something has a speed using deltaTime, timeScale should affect the perceived speed, so deltaTime must be scaled
for stuff that should be affected by timescale?
Well all right. I need to know about all the time stuff. Thanks for the answers.
oh so animations also use deltaTime ?
makes sense now idk why i found out this many years later 🥵
Yes, and the physics calculations. Tons of deltaTimes under the hood
wouldn't physics stuff use fixedDeltaTime
damn this is hard...
but that would also be scaled, because this exists
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Time-fixedUnscaledDeltaTime.html
Oh, right, I guess TimeScale affects deltaTime and fixedDeltaTime then
That's configurable
I think I pushed gpt a bit too far...
"push gpt a bit too far" happens the instant you trust it
oof that makes a lot of sense now lol I never touched those but I do remember timescale was affecteing it but just now realized it was just using deltaTime
its true though
I never use yield classes for time anymore
just creating an extra allocation object for no reason
(no big deal creating it once, but in a while loop?)
You might want to for example keep animating your UI at normal rate even if the game is paused or you are in a slow mo sequence
This would've been quite handy when doing black screen fade outs and timescale was 0 😭 ended up doing some hacky shit
duration = 3f;
t = 0f
while(t < duration){
t += Time.deltaTime;
yield return null;
}
// done
or ig now Time.unscaledDeltaTime for your timescale being 0 😄
Yeah I did something similar to this. Its okay now. I was just confused about the execution when used waitforseconds and like pause and unpause my game
coroutines are funny
I figured that much now hahaha.
hey, im about to create an idle 2d text/graphic game
Now i need to create a level counter for my character that is displayed and goes up when earning xp
Im also willing to put in the learning to do this by myself instead of using chatgpt. Where can i learn the specific programming that i need for this for example?
check C# courses in this channel pinned
!learn and the pinned C# courses
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
and yes stay away from GPT while you're learning
but this is then a lot hours of learning stuff i dont need/want for this specific game
I would just need to know how to get a placeholder/number for "level" and how i can increase it
You dont need to learn things for a specific game, the point is to learn the essentials that you can apply to any game/genre of project
eg counting numbers, doing arithmetic in code, something that benefits any game you make
There is nothing unique to an idle 2d text/graphic game that could not be used in any other game. You won't find specifics to learn.
No, you need to learn how to translate your ideas into code
Break down the aspects of your game, and look those up with a general statement. "How do I make a button".
damn i thought i could avoid all the hundreds of hours coding :/
You won't make a game by just "what's the code for this specific thing" over and over
you need to get to the point where you can take an idea you've never seen before and then implement it
otherwise, your game will, by definition, never be unique in any way
if it's all just re-used code, it can never be better than the tutorials you copy from
You're not learning the "specific code" per se, you learn how to think in engineering
yea i need to overthink this as an idea then maybe
Cuz doing this on the side while my main job is not coding/computer/Tech at all lol
hmm
thats why those LLMS memorize all the code that exists but its useless because the machine cannot think and reason as we do
you can know the whole documentation, code syntax, in and out, without reasoning and logic its useless
had an insane idea for a nice idle game in melvor style with shakes and fidget elements and revolutional idle, but yea rip
thoughts are bigger than possibilitys, rip
Or you could actually try to learn
there is a saying
"eyes bigger than one's stomach"
Again, don't try to code for a specific end product. Just get what you currently have one step closer to what you want, and eventually it'll reach somewhere. That somewhere could be drastically different than where you originally started
but if you just keep walking, every now and then you find yourself in a different place
honestly the intention was "lets learn only what i need for this game, finish it and thats it"
sadly not the ambition to really learn how to code fully D:
atleast im honest
xD
and a lazy dog
I mean you can focus your scope of learning but its one of those things where most things are connected, to know this you have to know this already etc.
I think that's a leapard actually. Maybe a lynx?
i was just bored that i couldnt find a game to play that offers a lot content/playhours and survival/automation
so i thought that ill give it a try, but nahh
ill go look for a game or just quit for now gaming lol
thats crazy the market is oversaturdated with idle games
how can you not find one that similiar
ya thats fairly complicated even for those that are pretty used to unity developement
yea but 90% of those are boring or offer short playhours
didnt like factorio as the ressources are drying up and i dont like moving my machines every 2 minutes
Just let the robots do it
look i am just gonna be honest with you
anything that you build yourself ... unless its fairly complicated and has very niche game mechanics... your not gonna like playing ... its just how it is
people don't like playing their own games
yea, guess i have to try to find a game that i can play :/
try some classic indie games like rainworld or hollow knight
all i wanted is something factorio/palworld like
idle game is fine, but a real survival game is better
i mean even minecraft has survival + automation via redstone somehow xD
i would really suggest you to check out rainworld if you want survival
or else just play terraria ig
terraria is great
Factorio, palword, minecraft, all pretty damn complex games under the hood
played all of these + terraria and calamity mod
damn im old
I wasn't suggesting games, just listing the ones you just mentioned lol
I mean, you can still make a game. You can just do the learning
If you're looking for stuff to spend time on, you could use it developing a skill
i mean if your bar is as high as palword and minecraft ...... thats gonna take you ages to learn to build a game that complex
not sure if the frustration from not finding a game gets better while learning programming and doing my own game, which i then probably wont even play since i created it myself xD
i guess i just take a break and look for games on steam
maybe imma find something
someone link him the textmeshpro doc
btw i was working with override controller and was having some problems. When i try to override a loop animation with a no loop animation, the AnimatorStateInfo.loop still return true for some reason. It seem like AnimatorStateInfo.loop always base on the base animation clip and not the override clip
General Question: 2D Top Down Game / Player faces Up -> Now the player wants to go down. How hard it would be to make it so that the player can't go down instandly, he have to make a little turn, like in a 3d third person game.
I didnt find anythink on youtube
you could just use RotateTowards no?
okay i will try, would be nice if it's that easy
I'd just use Mathf.MoveTowardsAngle to change the Z angle of your transform
RotateTowards could mess with other axes than Z
okay thank you
i have a set number of character prefabs a player can switch between in a game and i need to save the character's currently-selected character to a file so it can be loaded when the game starts up. what would be best way to store a reference to the prefab? should i have a serialized list of each prefab and then just save the index of the active character or is there a better way of doing this?
Index is the simplest way, but it breaks if you ever insert/remove characters in the prefab list
So you could instead use some other identifier like a unique integer/enum or string for each character and use that for lookup instead of the index
Hi, I'm new.
In unity can someone help me how to make a save system in unity that saves the state of everything, because i just found a tutorial on the internet that saved a variable, but i need the details to have all game objects and all scripts inside them saved in js code
put them in a poco
wdym by " all game objects and all scripts inside them saved in js code"
js code?
If you know how to save a variable, then you know how to save everything. You just need to do that same process, but for everything you want to save
...json?
ahh, great idea. thanks
yes js code sorry
like javascript?
json is not js code
I meant json
JsonUtility takes care of the serializing to json
Okay then what is the solution.
As I said, if you can save one variable, then you already have the solution. Just save all of the things you want to save
an examplecs [Serializable] public struct SaveData{ public string CoolString; public int SomeNumber; //etc. }
SaveData saveData = new SaveData()
{
CoolString = "coolBeans",
SomeNumber = 66
};
var dataJson = JsonUtility.ToJson(saveData);
File.WriteAllText(path, dataJson);```
ok thanks but if I want to save the game objects and stuff
save the data to recreate them as they were
you dont typically save the entire gameobject
but its "state"
i think he wants to save everything automatically without making these extra classes and stuff
like an entire MB ?
idk but I dont see the point in that
you have a prefab with all the components then you just put the values as they were
there are also assets on the asset store that make saving easy but i think they cost money
you should typically just make a separate class declaring what exactly you want to save. saving a gameobject by itself doesn't make much sense.
there are tons of generic save system examples online and its really like 20 lines of code
yeah its good if you need a solution without caring about how it works but you should still learn how to put something like this together
So store that data in variables, and rebuild them
if you gameobject was SetActive(false)
You would store a bool
public bool IsActive or something
ideally this way everything is clear on where it goes
if you have items that you need to pickup that dont spawn after you already picked up then you start dealing with things like GUID etc
ok I will take your advice
so would each character object contain some kind of component with an enum, and then the script that loads the correct character would iterate through each character to get the component and compare the enum found with the enum loaded from file?
Yeah that would work
You can always generate a dictionary for faster lookups too, but it doesn't really matter if you only have a few characters and it doesn't happen often
Another option is to have a list of structs/classes that contain the ID and the prefab
ooo. yeah, that might be a better option
did you google it first?
button is vague
which button. UI ? Keyboard?
lookup how to tie methods to button onClick or GetKeyDown respectively
keyboard
i know how to programm button press event but not how to tie a sound to it
why in unity characterbody when I do
velocity.y += gravity
my obj flies upward even when gravity is +9.18 and even when its -9.18
but it works as expected when I do -= gravity
well sound plays from AudioSource
put the two together
I am so confused, does anybody know?
Show your !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/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
(I assume you mean rigidbody)
I am using characterController sorry not characterBody
# movement direction is velocity and gravity is 'gravity'
private Vector3 velocity;
public float gravity = 9.81f;
# Inside fixedUpdate
velocity.y += gravity * Time.fixedDeltaTime
characterController.move(velocity * Time.fixedDeltaTime);
here, since gravity is positive, its supposed to go upwards
but even when I change gravity to a negative value, it refuses to go down and instead chooses to fly up
I can only make it fall down by doing velocity.y -= gravity
and I don't understand why it does that
Then you're either changing it somewhere else, or you're not changing what you think you're changing
tf why the #?
Python comments
ohh
sorry I just shifted from godot
Which means this code isn't copied from the script
also isn't gravity meant to be a negative force?
So we still don't actually know what is happening
can anyone send a script for the audio button thing
You know how to detect a key press. I just sent you the code for playing an audio source. You're done
That's it that's all the code
So, do you know how to detect a button press?
yes
So, you'd just call Play on the audio source that has the sound you want
how do i transfer a video audio into a audio
I have no idea what this means
use an online converter
mp4 to mp3 im guessing
like slicing the audio out of a video
can someone explain again how a button press event with a if statement works i forgot it
i learned it yesterday and now i forgot it
So you don't know how to detect a key press
why did you keep saying you did
there are 3 input checkers
Input.GetKeyDown
Input.GetKey
Input.GetKeyUp
yes
i will try
you could use it for unity
GameObject.CompareTag("tagname")
i put the sound as a component on a empty game object
GameObject is just there to specify
and gave the game object a sound#
tag
im using a if statment for the key event
how do i let the sound play now
if you need help with codint later, posting the code you actually have a problem with helps
im very sorry i dont want to nerve you but yes
digiholic told u
if (Input.GetKeyDown(KeyCode.Space))}
Mehmet.
thats my code from now
in void update#
i dont understand the doc
thats not what sending code means
you should really take the advice that has been given to you a few times now and stop what you are doing and go through the unity !learn pathways to learn how to actually use the engine
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
what is the audio clip called like the file or what?
If you don't know that and yet are still trying to play a sound I would learn before taking the advice given above
Whatever name you gave it in your code
(guys be nice we dont want to create another "vibecoder" lmao)
Who’s vibecoder?
vibecoding is like a term for programming by only using AI
basically not giving a shit and just copy pasting
I should make a vibe code game to see if it’s possible then.
Ai generate the art too.
It’d probably be a pain trying to explain to the AI why the way it’s doing something is wrong.
exactly
Someone probably made a YouTube video of this already.
they say there are "ai debuggers" that just fix your code
but i think thats a bit too optimistic
I use Claude to help me find out where tough bugs are coming from though and it’s pretty good.
Like I’ll give it a script and it’ll give me a list of things that could be going wrong.
And then I look there.
It hasn’t really given me any problems.
I knew someone would have done it.
AI is excellent if you already know the basics of overall programming and how it works. You can’t expect to use AI if you don’t for example understand methods or datatypes. Aside from that, it’s very powerful
Yep.
If you wanted to store "components" as data, but keep them generic, what data type would you use? Monobehaviour?
Like if I wanted to make a FactoryObjectData scriptable object to hold components that a builder pattern would attach
@mystic ferry technically AI could be using copyrighted stuff to provide you code
so theres that risk
Component probably? but im not really sure how you would intend to hold these in a scriptable object to attach to objects. Referencing it through inspector would mean you're dragging it from a prefab already
altho how thatd work legally is beyond my scope
I highly doubt I’m getting copyrighted code when I fire up Claude to help fix a bug in my project.
Can you even copy right little bits of code?
Like obviously you can copyright a whole program.
But like can you claim a script and say only I can do this?
well, maybe not small bits, but vibecoding is different
I’d be surprised if AI could stay lucid long enough to copy a whole software not gonna lie.
this is a help channel for coding, not for off topic. @mystic ferry @quick pollen
idk which show/game got copyright striked because it had like an extremely low resolution image of a page from a manga that wasn't even visible unless you looked extremely hard
true, mb
Sorry.
Not necessarily, the MonoScript type allows for non-instantiated scripts to be assigned
Is Component a type tho? I didn't know that
Monoscript is a part of unity editor. You cant use it in a build
Oh had no idea, thanks
Yes, monobehaviours are components. Rigidbody iirc is also a component, not a monobehaviour
Monobehaviours have to live on a gameobject, so you'd need a prefab to hold them. Or somehow reference the type of the component
If i have a prefab then there is no point of making a scriptable object so ig my approach is flawed
There is also [SerializeReference] which would let you store non-monobehaviour objects that share a base class or implement an interface
Would that be used for a decorator class?
Could you give an example if you have one
It sounds like you want to serialize a type, which so happens to be a component
Havent really done it myself but you could probably get away with an enum, and map that to the actual Type in code
Ideally id like something where i could reference both my own classes and rigidbody etc interchangeably
If that exists
I'm asking out of pure curiosity though so don't waste too much time on me 😅
if you mean the rigidbody type and not an instance (which would be on a prefab) then what i said above applies
serializing the type means you want to choose the type in inspector. it's not something built in so you'd have to do some funky workaround like making an enum and mapping all the enums to the correct type in code.
At the same time, you might be overusing the inspector if you actually need to do this
Yeah its likely not needed
Ill have a play in a second and see what i could come up with
Chances are I'm overcomplicating
I know it’s a general and generic question but an example would help contextualise an answer since this kinda thing does pop up from time to time and runs up against the walls of what Unity provides and/or what c# is designed to ideally be used for
For one game I made i used a scriptableobject class per card game “card” and said class uses inheritance and inspector serialisation to handle the standard stuff (name, icon, cost etc). But to handle the logic of the card in code, defined in the class itself.
Then I made a little editor script where on assembly reload it checks if any types inheriting from by BaseCard exist in the project that don’t have an instanced scriptableobject created and then creates one for me which created a pretty nice workflow for creating these one off scripts that can be drag and droppable and whatnot
I wonder if something similar could be used for you but with a ScriptableObject<T> where T is your stored type
You can define custom script templates which can massively reduce the time needed to write out the boiler plate of defining the generic so https://www.youtube.com/watch?v=TYRhlOHO_Xk
// Update is called once per frame
I freaking get it, stop showing me!
Don’t put up with the standard Unity templates, make your own! Change the default content in created assets.
Go sub to Jason Storey: https://www.youtube.com/c/JasonStorey
❤️ Become a Tarobro on Patreon: https://www.patreon.com/tarodev
=========
🔔 SUBSCRIBE: https://bit.l...
Slightly more engineered than something like an enum but might feel abit nicer in terms of managing it and inherently associating your data to class connections rather than explicitly in some dictionary or such
That doesn't really sound the same as to what they were asking. Theirs was more just serializing a type. What you're describing is reflection to create instances of objects
Doing that in this case would be very questionable. It's really better to just define it manually through an enum if needed or just use deriving classes.
Im not really sure what the suggestion of generics even helps at there
I might be mistaken but I assumed them asking for a way to have a scritpableobject define types that a builder pattern could “attach” would require creating instances of those types so I figured using generic scriptableobjects would allow a nice way to serializable a “type” (just being able to drag and drop the so around), define the type it would create via the generic and allow the scriptableobject to potentially handle the process of creating, initialising and attaching the given type if necessary
the generic part does nothing there unless you're actually making a deriving class. What you're suggesting would be making an asset AND class for each type. sure it can be done through code, but there are a shitton of components. If the person whitelists/blacklists components, then might as well just have an enum and define it through code anyways
Unity provides little for serialization as far as c# goes. But by the sound of it youd probably would like serialized references if you wanted more defined types insertable into the editor, but that requires some loops to jump through too.
So I realized that the terrain had a Nav Mesh Agent component. I deleted that which removed the error, but now I get this warning.
"Failed to create agent because it is not close enough to the NavMesh"
I'm confused as to how the agent is not close enough.
how would i calculate it so it would messure how far right/left an object is from another object, and display that on a text object?
how can i know how many lines the "AAA" text is? since we need to take in mind that characters can be longer than normal, and its a different font, and there is a boundary for it, and its a specific size?
I itred doing textinfo.linecount but that would get me 1 everytime
depends on what you mean by left/right (global left,right or relative to the player forward vector etc..) you can always just get the transform.position for both objects and subtract them. Will give the vector difference between them. if you only care about absolute distance you can also use Vector3.Distance
"SetDestination" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:SetDestination (UnityEngine.Vector3)
wonderCamp:Patrol () (at Assets/Scripts/wonderCamp.cs:39)
wonderCamp:Update () (at Assets/Scripts/wonderCamp.cs:34)"
Cylinder is assign the same script and IS doing what I want the Camper to do
Is the scene view showing Pivot or Center? cus if its pivot then you can see clearly its NOT close enough
what could be causing this movement script to be so jittery?
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Even small floating point difference would make it not close enough. That's why I suggested what I suggested previously. Don't just ignore people's advices.
And navmesh would often be a bit different than the surface, so if you snap the agent to the surface, it's gonna be out of the navmesh.
Is the rb using interpolation?
oh wow i have no idea how i missed that... 😅 thanks!
Something along these lines? Hasn't worked, but right direction?
Yea, assuming there's nothing else that might move the object. Also, the agent doesn't have to be added later than that. It could be on the GameObject from the start.
I do have it in Void Start, but unsure what to make the Vectors. I tried float values based on the terrain's location (this has the Nav Mesh Surface)
Charactr location obviously
And by "from the start", I meant it could be assigned at editing time.
hi, i want to ask Can I use RX 9070 XT for Unity development ? Will the card work ?
I mean the card is so cheap compare to nvidia alternative ? Will I get into trouble ? Will the card work with Maya and Substance Painter, Zbrush as well ?
Of course, why would you get in trouble?
No, it's illegal. Congress wrote a law that the 9070 specifically can only be used with Unreal
i see, the more vram the better right ? RX 7900 XT got 20 gb of vram but same price with 9070 XT at here. Which one should i pick ?
hey guys, for example I have a script that has a float = 7. I have two scenes and on scene one, I want that float to be 7, but on scene two I want that float to be another number like 9. is there i can do this without creating another script?
I made the float a [SerializeField]
Assign a different value in the inspector
Is the object the script is on a DontDestroyOnLoad object?
i don't see any one using it for maya on youtube so I want to ask
You could run Unity on an intel integrated graphics card
You just need a GPU powerful enough to run the thing you want to make
A script is just a template designed so that you can make any amount of instances of it. Why don’t you don’t want two of them?
I did but when I switch scenes, the float is the same as the other scene
Is the script on a DDOL object
You did it wrong then
(I think some HDRP stuff outright doesn’t work with older iGPU’s but nitpicking)
Show what you tried
Then don't use those
My float is move speed for an object. Each level will have a different move and since Ill have 20+ levels, I dont want 20+ scripts
One script.
Different value in the inspector in each scene
I’m being specific with my wording here, One script, multiple instances of it
The script is a blueprint of a house and the actual houses on your street are the instances
i feel like im making a simple mistake. This is where im changing the number, when I switch to scene two. It goes to the number I set in scene one
That isn't how it works so there' s more to the story you're not telling us
Is this script on an object set to DontDestroyOnLoad
Show the code, for example
You still haven't answered me
Also explain what you mean by "when i switch to scene two"? Do you just mean in the editor? Or during gameplay? or what?
sorry, no
Then you would do the following:
- Load the first scene
- Set the variable you want for scene 1 in the inspector to the value you want.
- Load the second scene
- Set the variable you want for scene 2 in the inspector to the value you want.
so my buttons are appearing outside of the canvas and I'm wondering how to move UI elements with a script
using UnityEngine;
public class Actions : MonoBehaviour
{
public GameObject actionButton;
public GameObject canvasHierarchy;
public GameObject actionHierarchy;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
AddActionButton(4);
}
// Update is called once per frame
void Update()
{
}
public void AddActionButton(int numberOfButtons)
{
if (numberOfButtons > 4)
{
numberOfButtons = 4;
}
int buttonY = -194;
int[] buttonX = new int[4];
buttonX[0] = -664;
buttonX[1] = -218;
buttonX[2] = 218;
buttonX[3] = 664;
for (int i = 0; i < numberOfButtons; i++)
{
GameObject newActionButton = Instantiate(actionButton);
newActionButton.transform.position = new Vector2(buttonX[i], buttonY);
newActionButton.transform.SetParent(actionHierarchy.transform, true);
}
}
}
i appreciate this but looking through options. I ended up using scriptable object
There's zero reason that changing it in the inspector wouldn't work.
Unless you had code that actually changed it after the program runs, in which case, why expose it in the inspector at all
try something like this instead of using absolute numbers:
float lossyX = (Screen.width - _rectTransform.rect.width * _rectTransform.lossyScale.x) / 2;
float lossyY = (Screen.height - _rectTransform.rect.height * _rectTransform.lossyScale.y) / 2;
ok I'll try it tomorrow when I have time
gn
thanks though
Quick question, does anyone know where or how I can do a VN dialogue system with stuff like choices (that can do things like call scripts), in a way that doesn't rely on C# code for the actual dialogue itself?
Trying to figure out how to approach RPG dialogue text that can do that kind of stuff, but I don't want to hardcode stuff.
Sweet, will have to check it out.
how do you give a game object a custom bounds size so when you hit F on the keyboard it will focus to that bounds? I use a lot of graphics api stuff so the game objects has no true bounds other than its actual world position, so focussing on them is a pain
perhaps make your own MenuItem with a hotkey that focuses the scene camera based on whatever custom framing you want.
The built in F functionality relies on Renderers afaik
is there no way to push some bounds in an editor script some how to capture the focus?
this is all we get
nothing about bounds
all the implementation is internal and relies on there being a Renderer or a Collider afaik
You could temporarily add a renderer to the object
or add one in the editor only
and set its bounds
ok ill try it, thanks
what is @versed light doing in #💻┃code-beginner 🤣
@versed light could also do some
// custom renderer.cs
#if UNITY_EDITOR
void Update() {
this.bounds = ...;
}
#endif
// editor script.cs
editorUpdate += (e) => {
var go = this.GetSelectedGameObject();
if (!go.TryGetComponent<CustomRenderer>(out var customRenderer)) { return; }
if (e.type == KeyDown && e.key == KeyCode.F) {
var cam = SceneView.lastActiveSceneView.camera;
cam.transform.position = this.BringBoundsToView(customRenderer.bounds, out var size);
cam.orthographicSize = size; // adjust for non-orthographic
}
};
!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/, https://scriptbin.xyz/
📃 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.
soundcontroller has two methods with same name?
What ISN'T wrong with your code?
oops
What is even going on here
