#💻┃code-beginner
1 messages · Page 187 of 1
spend a month learning and make a game in 2 weeks or spend the next 6 weeks to produce nothing, your choice
what course should I take, i just need to make a few scripts like seven maybe
i do other subjects not just cs
you think a game is just scripts ?
no you need to understand basic coding concepts if you plan on doing scripts
script doesn't do much if you don't even know why a certain method belongs somewhere etc
any videos you would recommend watching, I know python already
I did say check the pins :https://learn.unity.com/project/beginner-gameplay-scripting
thanks, does it require me to make a new game though
no just open a project and start coding
okay thanks alot
just make sure you at least configure your IDE before doing any coding
depends on the editor
also my cs teacher said to use github for our project but he just is going to look at a word document so what is the point of github
making sure it can interact with unity and it's functions and other stuff
If you say extensions, I assume vs code
because its industry standard way to version projects and have them on the cloud
Probably also because he's had people lose their project in the past. Using a hosting site will prevent that from happening (as long as you commit your work of course)
^ or you lose access to your school account (if you use one, i lost a few projects and schoolwork once because i couldnt access my school email)
true he did say that
History
You can view each draft all at once if it's in git
portfolio after you graduate
Also it prevents someone from just pasting a ChatGPT essay into the submission box and calling it a day
(saying that because i wish i had one, i made some epic stuff eeeexcept it all saved to my old school email)
is this the right place to ask for help with coding problems?
yes
How can I know what part of the object is "the front" for stuff like lookAt()?
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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.
oh sorry
it's backticks, not apostrophes. but also use a bin site for large blocks of code like that
anyway, i cannot see the line numbers so i don't know which is line 32, but at a guess i'd say it's probably FixedJoint fj = grabbedObj.AddComponent<FixedJoint>(); and grabbedObj is null because you aren't null checking it there
yes that was line 32
That's usefull, not that easy with exports though, let's see if I can figure this up...
to send a hatebin i just send u the link?
not that easy with exports though
i have no idea what you mean by that. but when your tool handle is set to local rather than global for rotation then the blue arrow points along the selected object's forward direction
just paste the link here, yes
how to change color of sprite render?
I tried that
yeah so you need to null check grabbedObj before line 32 and the following lines
and what does the error say
yeah got it thank you
What's the error say
Renderer doesn't have anything named color. SpriteRenderer does.
and Renderer does not contain that property. that is on the SpriteRenderer class
For example I think that from Blender to Unity the axis change like that, so I am trying to export it changing the axis to compensate for it but I think I am doing it wrong and I no longer know which way is up
you can ask for help with your export settings in #🔀┃art-asset-workflow
Event takes place, no errors, no "The event has happened" in the console
- https://unity.huh.how/physics-messages
- use the CompareTag method to check a tag, don't use the
==operator for that
The Three Commandments of OnTriggerEnter:
- Thou Shalt have a 3D Collider on each object
- Thou Shalt tick
isTriggeron at least one of them - Thou Shalt have a 3D Rigidbody on at least one of them
How do you know it occurred if no logs were present?
So I was able to fix some of the issues on my script, but now I came across another problem where it shows this
I am using it for 2d
Then why are you using the 3D event
I didn't know it was for 3d
Do you have a script named CharacterController
I do
you probably have your own class called CharacterController so it's trying to use that instead of unity's CharacterController
Do you have an IDE that is configured...
Does it have anything named isGrounded
I did that already, and I am still getting the same error
Yes I do
Show !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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.
Is this something I have to do on my script or something that is shown on discord?
Intellisense should not have suggested the field/property and marked it as an error immediately in Visual Studios.
it is how to post code
give the link
Thank you so much. Im sorry for taking a while. I am new to code and I am not able to figure things out "right-a-way"
Is your IDE configured?
Because I can see something that would be underlined
and other things that should be correctly indented
Why do you have two variables who only exist to set each other
this would be a stack overflow as soon as you tried
actually that second one sets and gets the field from line 11. but that first property is very weird
It should be. I went trough IDE last night
The second actually refers to the camelcase field.
Oh, right
well, do you have error underlining and proper autocomplete then?
I got PlayerController blinded by how many were in one place
I do not. For some reason, have linked visual studio with unity for my project but I am not getting underlined issues.
The bottom one was suggusted to me when it showed me the tool
Did you setup your workloads? (a common missed item from the list of things to do from the configuration manual)
What do you mean set up workloads?
- Open the Visual Studio Installer.
- Select Modify
- Select Workloads
- Make sure the Game development with Unity workload is enabled
Running the installer again will allow you to modify Visual Studio
At the very least, the Unity workload must be checked.
It is not giving me that option to do that. I have already downloaded Visual Studios
Screenshot what you are doing
What's not giving you the option?
The workload tab
👆
Show us your workload tab or whatever it is that you're looking at.
- Select Modify
I think we'll have to explicitly go through each step with them.😅
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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.
making a game wont be any easier than configuring your code editor to write scripts efficiently..
Some users will not be able to see embedded text files.
jjooo I need help my Visual Studio is weird af 
I use 2022 and it doesnt really work together with Unity
Maybe tell people what is weird with it.
Hard to explain but I want to write code for my Vr hand. I creat a c# file and write code but it just doesnt appear in Unity
What do you mean by "it doesn't appear in Unity"?
I'm assuming "it" refers to your script not appearing in the Unity Editor
uuuh sorry I am new but when you creat a Script there should be variables that appear in Unity when you write it down in the code. wait let me make some screenshots
Maybe share your !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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.
have you actually saved your code? and made sure that there are no compile errors?
Please don't share using images unless asked for
config IDE first
start by configuring your !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
• Other/None
aahhhh thanks
then when you've done that fix your spelling
bro thank you very much for helping me but it is midnight on a school day for me plus I am not from a native english speaking country... or whatever you call it
the issue is literally caused by a spelling mistake too
A configured IDE is required to get code help on this server. Maybe wait till you've got more time to debug this if you're busy.
thanks mate your a real one
By a spelling mistake they referred to the error in your code. It wasn't an attack on your spelling in discord.
💀 yeah got it now. I used JetBrains for java before this, so I am not used to configurate stuff... found the two spelling mistakes too... thank you everyone you saved me
When an IDE is configured, the Intellisense will provide code suggestions that will prevent most (if not all) typos and minor syntax errors.
You'd not be able to continue to the next line without the whole script throwing red squiggly lines everywhere or having completely messed up indentations - as the statements are likely invalid.
You'll be able to focus more on designing and actual logical errors rather than syntax errors.
You'll also be more aware of the available members of a type without having to lookup the docs - you should read them anyways, at least for the specific tool you're using (nobody really remembers the docs in detail... they're just aware of the constraints and patterns for the tools they find themselves often working with).
A properly configured IDE makes a huge difference in productivity.
Hello, it's me again. I have finished flappy bird
I am having an issue with a code I am writing.
There 4 scenes
from 0 to 3
I know
I wrote so it would be chosen from scene 1-3 but it would never choose scene 3
so I wrote from 1-4
and now it works
isn't that weird?
or am I just unlucky
Random Range is exclusive of the max for integers
Hmm, so you add +1 for the max int?
Thanks for the help
Maybe limit it to https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager-sceneCount.html instead of hard coding a value.
thanks
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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.
When I run this code and the bullet gameobject collides with something it doesn't Log "yes" https://www.toptal.com/developers/hastebin
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Uh we can’t see your code
That’s a link to the paste site
But there’s no code in that link
@rotund hull
You have to click save before copying the url
Although, people have issues with hastebin sometimes. So maybe it was just a bug
what kind of capitalization should I use for c#? I saw a video where he said to make public variables LikeThis and private variables _likeThis. is that the right way to do it? Ive just been doing it likeThis
it doesnt say much about public variables, and im still not sure and kind of more confused now
general rule of thumb
public classes, variables and props are PascalCase
while
private are camelCase
Methods are same as properties so they are PascalCase
sure it does
okay, and do private variables get the '_' in front?
its choice at the end of the day
I used to but dont the point anymore
i also just do pascalCase
code with a lot of _ looks ugly to me now 🥹
Typically you shouldn't have public variables.
private static IWorkerQueue s_workerQueue;
its hard to understand what variable needs to be accessed outside the class, im still kinda new to it, so when i think it needs to im more generous with private until i hit error codes
string hello = "hello_world_I_like_to_code" <- seen someone do this recently
The C# naming conventions have been linked already, and are pinned to #archived-code-general
Ideally none.
i have just learned kind of what public type name {get; private set;} means, i tried using it a little and i got error codes
What errors?
What errors..?
uhmm i took it all out ill recreate the issue one sec
Cannot modify the return value of 'expression' because it is not a variable
compiler error CS1612
oh wait i havent made the class yet
what did you write exactly?
When you access a vector via property, it creates a copy of the original variable, so modifying it doesn't make sense, and this the error.
If you want to change a value type via a property, you need to cache the whole thing in a local variable, modify it however you like and reassign the whole thing back.
You can also skip the first step if you don't need the previous values.
In this case you'd need to create a new instance.
i feel like thats a bit too advanced for me atm
Not really. Knowing the difference between value and reference types is one of the basic things you need to know.
Everything else is a consequence of that
i meant learning how to do that and a state machine at the same time, i gottapick a lane and figure one out, if i am debuging both at the same time that would be horrible
my build for android is only getting this far. no errors during play in the editor, and it was building a few days ago. not much has changed that I can think of reverting. is there a way to debug the build process?
it just sits at this point, even overnight
Then pick knowing the difference between a value and reference first
It is absolutely crucial. A state machine is not
True. But I think language basics should come before state machines and other programming patterns.
dang and i was excited to get this done today
It's like saying "I don't know what a class is, I want to learn how to make an object pool first"
yea makes sense
delete library folder and try again maybe
also #📱┃mobile
ok, thanks
Hey, so, I been getting this message: Assets\Scripts\GameController.cs(39,9): error CS0120: An object reference is required for the non-static field, method, or property 'SavePoint.SavePosition
The line of the code is: SavePoint.SavePosition = Player.transform.position;
I am trying to refer to the Vector3 stored in the SavePoint script, called SavePosition, to teleport the player there. any idea of the problem?
which SavePoint instance, though?
SavePoint is a class. It's a kind of object.
SavePoint.SavePosition is trying to get SavePosition from the class itself
You haven't provided a specific save point to set SavePosition on here.
i think I get it
that's why it says you need an "object reference"
Transform.position = Vector3.zero is an error because you need to set the position of a specific Transform, not the Transform class itself
transform.position = Vector3.zero is fine because transform is a property on MonoBehaviour that gives you an instance of the Transform class
so I need to instantiate the SavePoint script?
If it's just a regular class (not a MonoBehaviour or ScriptableObject or something), you'll want to create an instance, store the data in it, and then hang on to the object
I don't know what SavePoint is so I can't say for sure.
got it
public class SavePoint : MonoBehaviour
you talking abt this, in the top part of the script?
SavePoint is a class that derives from MonoBehaviour
so SavePoint is a component that exists in your scene?
how is this meant to work?
do you want to remember the player's position after you reload the scene?
or is this just remembering where the player was so that you can respawn within the same scene
there is a scene. Within the scene, the Save GameObject exists, having the SavePoint script. When the player dies, I want them to respwan at the Save gameObject's position
Okay, that makes sense.
I think the Save Point should detect when the player touches it using a trigger.
i find this better in a long term than having set Vector positions, so the Save GameObject can be in different positions in different scenes
When that happens, it should do two things:
- Remember the player's exact position
- Tell the GameController that it should be the active save point
already have the second thing working
oh, did your Save Point class tell the Game Controller about the player hitting it?
tho the player position doesnt matter to me, the only position that matters is the Save position
respawning was working when I tested it, but now Im getting so confused in the code
void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.CompareTag("Player"))
{
GameController.instance.Save = currentSave;
}
}
where is this code from?
the SavePoint script
a string, containing the name of the scene the current save is on
just add another field to the game controller to store the position of the save point
GameController.instance.SavePosition = transform.position;
GameController not being destroyed on load wouldnt mess this up tho?
why would it?
true
it already remembers the Save string
Storing the SavePoint itself would be inappropriate
since the SavePoint would get destroyed on scene unload
so SavePosition would be a Vector3 on GameControlelr instead?
Right.
Just like Save is a string
I would rename that to saveScene
it's the scene you saved in
true! i hadnt thought abt that
and savePosition is where you were
My God, how didnt I think of this before
this is so much easier
it's easy to get stuck on the wrong idea :p
You could go a step further and make a serializable SaveData class
and then use JsonUtility to save that into JSON and also load it back into an object
then you could save the game between play sessions
between play sessions is a thing I really would have to learn, I dont want the game to reset every time it gets loaded
If your save data is simple, the built-in JsonUtility methods can easily handle serialization for you
for more complex things, Json.NET is popular (you might've seen the "Newtonsoft" name before)
I use it for saving.
huh. everything is working as it should, except the respawn point. the player is still not respawning on the Save .-.
did you update your code to actually use the savePosition value?
not just to write it
SavePosition = Player.transform.position;
SavePosition being a Vector3 in GameController
Okay, but where do you use that variable?
isnt it being used in SavePosition = Player.transform.position?
https://hastebin.com/share/ebohutusoz.cpp
I think maybe this is somehow overriding the "SavePosition = Player.transform.position;"
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
You have to actually use it to set the player’s position
Just remembering the value doesn’t do anything by itself
i thought that was setting, not remembering
That’s storing the player’s position into the savePosition variable
That’s good, but if you never actually read the value from savePosition, it’s kind of pointless…
Compare tag?
Yes, FindObjectWithTag is a method. Not great, but better than the base Find
because since the GameController doesnt originally exists in the same scene as the Save GameObject, I need to find a way to bring the GameObject into its script through the script, not assigning it in the inspector, so I can store its position
If it doesn't originally exist, then you instantiate it, right?
Instantiate returns the reference. Cache that and pass it where you need instead of using Find
there is also GameObject.FindGameObjectWithTag but no docs, just the GameObject.FindGameObjectsWithTag version.. weird unity
uhh how exactly?
GameObject newObject = Instantiate(prefab);
You can also store whatever the prefab type is, like:
public Player prefab;
Player newPlayer = Instantiate(prefab);
You rarely want a GameObject reference
Weird, yeah I was looking for docs for it.
I never use find ever, so I don't really keep track of the different variations haha
same now, it used to confuse the shite out of me.. it never came up on docs but it did on IDE weird stuff
Thanks yall
@north kiln would I do that whole line the same except for time.deltatime?
Yes, and fix the capitalisation mistake in the axis
where?
Just curious, I know when learning ChatGPT is normally not a good idea. Im just wondering if first I figure out a way to add something for example (Movement for 2 paddles in pong). Get it all working and whatnot, then asking ChatGPT to imrpove my code, then using that code.
I did all the "hard" work by adding the feature myself, but I have ChatGPT optimize it and help me to understand why its code is better than my code and what not.
I guess my question is just will it still be a good way to learn, or should I just stick to solely writing the code myself.
the y? that's from the video
and its still wrong 
Probably better to do it the other way around. Ask chat gpt to give you an overview of how to implement something and some barebone code and build upon it yourself with full understanding.
and I think getting it involved in any stage is a bad idea
I feel like that would defeat the point of learning to structure things yourself wouldn't it?
You can learn that by reading and understanding the code.
Isnt that what leads to people being stuck in tutorial hell? Just reading code
do I still * it be zoomSpeed?
Just remove the deltaTime multiplication
No. What leads them to tutorial hell is copying the code without understanding it.
got it just the deltaTime
And by understanding the code, I don't mean just functional understanding, but also intentional. You need to understand why it was done this way and not another and wether it would work in a different way and how.
That's just what I was gonna ask you, I feel like you can understand it but not understand it at the same time. How you put it seems to be exactly what I was trying to say, Thank you
Appreciate the advice
I have this IEnum that will move a transform, to another position, based on animation curves. one for the speed, and one for the height offset.
this is all running in a while loop, that will run as long as timer is < leg.travelTime.is there a way for me to remap timer from 0, leg.travelTime to 0,1 to use it for evaluating my animation curves? since my animation curves run from 0 to 1, and not from 0 to leg.travelTime.
In this case Timer/leg.travelTime usually would send value between 0-1 no?
You should not use WaitForEndOfFrame, it's not doing what you intend it to
you should just yield return null to wait a frame
float normalizedTime = timer / leg.travelTime;
huh, thanks.
how do I fix it?
read the error
your unity version is diffrent then the one you last saved your project on
you can continue but it might break some things
or download the original version of the editor.
I did you think I know what it means
I don't get it that's how I opened it the last time
make a backup of your project, then open it again and press continue
backup?
just in case something breaks
I've already closed it
dude. go into your project's folder, make a copy somewhere else. re open the project, then if this same message pops up press continue. its not that hard
I can put it anywehere?
yes.
now what?
wdym now what. did you open your project like i told you?
I already did this
this has nothing to do with your issue
read that thing. it says go to prefrances>external tools and then set VS as your external editor
press continue
Does it not say there’s no space left on your drive?
I should read what the errors say
I'll fix that tomorrow
can I save it to a different drive?
You should use version control (git or unity version control (i recommend git)), not make a copy of the folder. Just for the future
git?
what is it?
Google it...
It's version control
this?
If you ever see a word you don't recognize, you should immediately google it
In this case, something like "how to use git with unity"
it's a way to backup my projects?
I'll fix it tomorrow
How much does GetComponent effect performance? Been trying to not use it as much as possible. But is it like, using it like once when something specific happens is fine, it's more so when you're doing something every frame it becomes a problem?
Was wondering because in my ontriggerenter script for my character, everytime it enters a trigger; it'll be checking if that trigger object has a checkpoint script
Wondering if I should switch to just creating a tag for checkpoint objects so I can just check if there's a checkpoint tag, or if it doesn't matter too much.
Hi do I have to unsubscribe from an event where i delete the object that invokes the event?
private void OnEnemyDied(EnemyController enemy)
{
enemy.Died -= OnEnemyDied;
_spawnedEnemies.Remove(enemy);
Destroy(enemy.gameObject);
}
You could use TryGetComponent<T>(out someVar) or TryGetComponent(out T someVar): https://docs.unity3d.com/ScriptReference/Component.TryGetComponent.html - if the component does not exist, no extra memory will be allocated, if it does, then itll be stored in "someVar" - in general "GetComponent" isnt exactly bad, its just often times you can probably cache your reference, it does generate (a small amount of) garbage when called, and scans all components of a object, avoiding it in large loops and functions like Update can give micro optimization, but probably wont be the leading cause of major performance issues in your project (though for that, the Profiler is a good tool to confirm and find performance issues)
anyone know how I can fix the color?
{
StringBuilder builder = new StringBuilder();
<color=#").Append(Rarity.Color.ToHexString()).Append(">").Append(Rarity.Type.ToString()).Append(" ").Append(EquipmentType.ToString()).Append("</color>").AppendLine();
return builder.ToString();
}
}```
right now it just deletes the text
<color=#").Append(Rarity.Color.ToHexString()).Append(">").Append(Rarity.Type.ToString()).Append(" ").Append(EquipmentType.ToString()).Append("</color>").AppendLine();
```what is this? and did you log the builder.tostring
yes
the line doesn't show
Thanks!
Unsubscribing can always be a bit confusing, as a good rule of thumb I always try to unsubscribe anyway, though maybe this post can clarify: https://forum.unity.com/threads/unsubscribing-listener-in-c-object-instance-within-monobehavior.1252914/#post-7963866 - as I understand it, if the thing being destroyed has subscribed to something that wont be destroyed, then it should unsubscribe itself before getting destroyed
did you see anything in the tmp or what ever and its color?
nvm got it
string color = ColorUtility.ToHtmlStringRGB(Rarity.Color); have to use this
you should use string interpolation (or string.format) instead of append.append.append....
apparently string builder is way better with memory?
ah so use string.format but not concatonation
.append().append().append().... 7 appends vs
$"abcd {var0} efgh {var1} ijkl {var2}\n"
in string.format do i just use + in place of append?
string.format is
Format("abcd {0} abcd {1} abcd {2} ...",var0,var1,var2.....);
no idea what you mean by +
btw the number inside {} tell which argument it needs, so you can
Format("{0} abcd {0}",var0);
Is there a reason it doesn't work with the $ infront?
because my ide doesnt syntax highlight without it
if I put it it breaks
$ is needed only for string interpolation
with $ you dont need to maintain the order of arguments inside string.format, just
return $"abcd {var1} abcd";
ah okay
short hand of format
when I try to tab it down a line to make it more readable it adds a +
pretty annoying
Hi, I keep getting this error . I have tried the most basics of tech support advice of turning it off and on again. Please can someone advise me how to clear this error?
you dont need format any more, string interpolation already returned you a string
i know, but to make it more readable for me
can you still change a variable from another script if its private?
No, unless you use a public method/property which changes it
Or internal I guess
reflection /pointer (if unmanaged struct)
okay, i think im understanding getters and setters now
i thought private types werent able to be used if it was outside the class. I realize you can read the value but you cant change it if its setup with a get and private set, but its not readable or writable if its just private, am i right on this?
Private types surely aren't accessable from outside of the declaring scope.
You're talking about public properties with a public get and private set. And yeah, if it's purely private then you can't read or write
public x {get; private set}
is just shorthand for getters and setters, x is actually private
correct i keep forgetting its actually public
isnt it x is private when setting and public getting?
if you use properties the variable is private even though it technically says public
its just shorthand
properties being {get; set}
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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 i have this erroa Assets\Main\Scripts\InputManger.cs(24,49): error CS1061: 'PlayerMotor' does not contain a definition for 'Crouch' and no accessible extension method 'Crouch' accepting a first argument of type 'PlayerMotor' could be found (are you missing a using directive or an assembly reference?)
this my code https://gdl.space/raw/ugeriyedux
idk check ur PlayerMotor class
why are there red errors for ViewRotation.y and x? https://gdl.space/cogacewaqa.cs
`C# is case sensitive
i know 
crouch is not the same as Crouch
so what do i do
change crouch to Crouch ?
ok
if you really needed to be told that you need to follow some basic C# lessons
work ty and i only know pyhon
py is case sentitive
!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
• Other/None
screenshot inspector
ok, screenshot console
did you save your script?
So fix your errors
oh i see the problem lol
people call me blind for a reason
i wrote screenmanager instead of scenemanager
and just did it again, lol
you need to configure !ide, those errors should have shown up there
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
• Other/None
uhhh where exactly
let me check the bot rq
Here, this line should be red underlined
what should i do about it? (im a beginer tw lol)
which IDE are you using?
the program you use to type code into
that looks like VS Code not VS
no, not at all
uhhh is it an issue?
yes, without a configured IDE you cannot get help here
lmao i think i should install it then
yes, Visual Studio (Community) is best to use
yes
honestly so true
this is a genuine screenshot
Time to learn about Arrays @tepid summit
yes, yes
this was like 2 or 3 months ago
How would I do it for vscode?
Just download the c# and unity extensions?
!ide. Follow the link EXACTLY
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
• Other/None
You think throwing copilot in there would mess up my learning process like ChatGPT?
yes
Ikik
mess up what exactly?
Yk, like chatgpt gets you stuck in a tutorial hell sort of way? It just gives you a code and complicated explanation
well if you use to generate all code for you withtout bothering to undestand anything then yes
kinda, these are really not learning tools and should only be used by someone who already knows what they are doing
I would say they are learning tools depending on what language u want to learn and if you have any base or not
some not so known languages it hallucinates almost entire code
Tho copilot still needs you to know something, so I guess it isn't that bad?
I mean everything requires you to know what u are doing
it can give u legit looking code that is not what you need at all
One of the most difficult jobs in software development is debugging code that you didn't write, and code generated by CoPilot or GPT makes this doubly difficult
lets add when it gives you code that gives no eror messages when it fails 🙂
Im looking at you android
For coding in Unity, are you supposed to use Visual Studio or Visual Code?
I use Studio, I honestly dont know the difference between Code and Studio
it is called visual studio code or vsc not visual code
Visual Studio is a fully fledged IDE, VS Code is a jumped up text editor
Ah okay.
random question: why does the unity starter assets tpp example ThirdPerson controller example includes a spherecast for a groundcheck if the CharacterController already provides an isGrounded property?
The CC isGrounded check is known to be pretty weird. At least I've seen a lot of people complain about it or say theres been an issue. Implementing your own let's you define what grounded even means along with whatever other feature you want
Even unity admits that CC sucks.😬
It is pretty awkward when you are limited to its options, and requiring that you do 1 move per frame or it might be buggy.
how do you acces blend tree values?
as you normally access animator parameters
whoopsie, i had a sort of local float value going on in the blend tree, al fixed
can anyone tell me why im getting this error? the Agent of AI_Health is assigned in Ai_Agent script in awake. and i did check before Die was called, it was indeed assigned.
error :
NullReferenceException: Object reference not set to an instance of an object
DELTAV.AISys.AI_Health.Die () (at Assets/Scripts/AI_AgentSys/AI_Health.cs:41)
DELTAV.HaDSys.HaDSys_Damagable_Base.TakeDamage (DELTAV.HaDSys.HaDSys_DamageInfo damageInfo) (at Assets/Scripts/Health And Damage System/HaDSys_Damagable_Base.cs:20)
DELTAV.AISys.AI_Health.TakeDamage (DELTAV.HaDSys.HaDSys_DamageInfo damageInfo) (at Assets/Scripts/AI_AgentSys/AI_Health.cs:30)
AI_Health script : https://hastebin.skyra.pw/oriyorakap.csharp
the debug.log on line 37 outputs Agent is . and dosnt say the game object name
where it is assigned?
if Agent is not null then Agent.speaker must be null
Is it overkill to mark things like DeltaTime as [ReadOnly] when used in jobs, or is it a good practise?
what deltaTime?
nope its not. i moved Agent.InvokeTriggerTransition("Die"); up and i still got a null ref error, so Agent is null. but when i look in the inspector in debug mode it is assigned.
AI_Agent -> Awake() ->health.Agent = this;
try log with the gameobject to see which one gives you NRE
i am logging Agent on line 37, but it doesn't give me an error, it just doesn't say the name of the agent script in the log output
Agent is
UnityEngine.Debug:Log (object)
DELTAV.AISys.AI_Health:Die () (at Assets/Scripts/AI_AgentSys/AI_Health.cs:37)
DELTAV.HaDSys.HaDSys_Damagable_Base:TakeDamage (DELTAV.HaDSys.HaDSys_DamageInfo) (at Assets/Scripts/Health And Damage System/HaDSys_Damagable_Base.cs:20)
so Agent is null
agent is null so nothing got displayed
btw
Log("XXXX",gameobject);
debugging a null object does not throw an exception
but i can see it assigned in the inspector!
how? Agent is not serialized
also every other thing that AI_Agent assigns in Awake works fine
i can see it in debug mode
duplicate component
elaborate please
wait.
Agent is a property. How can it ever know what to get?
you probably have two components of this script
search the hierarchy or debug.log
no i only have one
even when i remove the getter and setter i still get a exception
you need a GetComponent before you access the property
you are not setting it to anything
or is this health.Agent refering to this script?
yes, on my ai_agent script, health is referencing the component that is giving me these errors
even when i assign Health's agent through its own inspector i get the error!
what is this bull shit
a question, how to make the game look sharp? I mean my game feels blurry for some reason 🤔
you prob have a low screen resolution in the play mode window
on the top it has an option for it
set it to free aspect or your own screen resolution
might be your bloom
is there a way to have a lot of bloom but without the blurriness or is it a lost cause in that case?
i really like the bloom haha xD
change the threshold
also #💥┃post-processing
ah shi sent in wrong again haha xD
show inspector of AI_Agent
yea so uhh i cant send pictures on discord cuz im in iran,
but i assure you it is correct
ok add logs to the Awake
also that cant be the issue beacuse /\
alr
Hey I'm working on a XR project and I'm trying to make teleporters you can step on and go to a certain other location. The problem is I don't think what ever collision box I'm using is colliding with the teleporter. Could someone help me? (my code is attached btw)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Teleport : MonoBehaviour
{
public Transform teleportTarget;
public GameObject thePlayer;
void OnTriggerEnter(Collider other)
{
thePlayer.transform.position = teleportTarget.transform.position;
}
}
that could exactly be the reason
make all texture filters point and change bilinear to none
oh gotta try that thanks 😄
all g
maybe change thePlayer.transform.position to other.transform.position
There's no need to declare public GameObject thePlayer you get this info from the OnTriggerEnter
other.transform.position =...
and use something like a tag comparison to filter it
That didn't work
wdym
I have a cylinder with capsule collider running that script and my XR camera isn't colliding ig
i logged both the health and health's agent after assigning it at the end of awake.
both were logged correctly:
UnityEngine.Debug:Log (object)```
```Strider (DELTAV.AISys.Strider.AI_Strider)
UnityEngine.Debug:Log (object)```
(btw `AI_Strider` in the log is of type `AI_Agent`)
does the teleport have a coll
just a thought.
You have Awake as Virtual, this suggests a inherited class somwhere that may not be executing this Awake
It should
check
it is. in AI_Strider which is of type AI_Agent, i have Base.Awake in awake
@static vigil been here and clicked through this?
working on it
post that code
also other things in AI_Agents awake get assigned sooo....
here is the awake of ai agent right now:
protected virtual void Awake()
{
aiTarget.faction = faction;
speaker.Agent = this;
targetingSystem.Agent = this;
targetingSystem.faction = faction;
targetingSystem.los = ai_Los;
health.Agent = this;
Debug.Log(health);
Debug.Log(health.Agent);
}```
this is AI_Strider :
```cs
protected override void Awake()
{
base.Awake();
-----other shit-----
}```
I will test it now
you need to be Adding GetInstanceID() to your logs so you can be sure you are refering to the correct objects
is the rest of the player childed under cam offet
also what are these center numbers
idk man they just happened
try setting them back to 0
or try using xr origin as thePlayer.gameObject
oh wait are they like offset by 5 or whatever
i logged health in Ai_Agent and this on AI_Health. both gave the same instance ID : -206766
really? ok
more like 5 trillion
e in a number means to move the decimal by the number after e iirc
yeah i know
but since it said zero i just thought it didnt move 😂
@languid spire isnt this unusueal? i also have another script called AI_Soldier of type AI_Agent and that works fine?
that one dosnt have any problems with its AIHealth
post the full AI_Strider code
so its just another way of saying it
i guess
its just what unity calls it
🤔
do you mind postiong the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Teleport : MonoBehaviour
{
public Transform teleportTarget;
void OnTriggerEnter(Collider collider)
{
collider.transform.position = teleportTarget.transform.position;
}
}
does your player have a rigidbody?
No
no
OnTrigger enter needs a rigidbody
breh
put a Kinematic rigidbody
nvm
on your player
i have a colider though
It's an industry term, XR doesn't just mean VR
needs to be rb
needs a rigidbody
it's a term for VR and AR
doesnt matter if kinematic or not
thanks for clearing that up
make sure to constrain rotation
im new to all this stuff lol
the link I gave you went through all this ..
since hes probably doing custom player movement i thought kinematic would be more... suitable
just ssaying
ok i gave it a rigidbody
did you constrain rotation
yes
didnt you originally need it for something else like.... not phasing through walls?
@vast vessel Can you show the sequence of the debug.logs you are getting
not yet
for the instance ids?
ok so i loaded in anddd then everything was just gone..
did i fall through the floor?
maybe. turn on kinematic if you dont really need physics cuz it might be messing your movement up
i just have teleport to move
All of them, the only thing I can think of is the Die is being called before the Agent Awake
like aim the controller click a button
its not the latter i assure you. i will try to find a way to post puctures but i cant promise
ok I set it to kinematic, ill see how it does
you are going to need to use the VS debugger and step through the code, this is all too complex to resolve just by looking at the code alone
how do i enable the debugger?
ayyyy lets goo it works
ayyyyyyyyyyyyyyyyyyy
theres just.. one more issue
._.
my aim click teleport thingy, its getting blocked by something now i guess and it only blocks it like 30deg in front of the player and the rest of the directions work fine
well guess i gotta fix my other erros cuz there is one happening on every frame that wont let me see whats up with AI_Health
you might have mentioned that earlier!!!!!!!!!!
they are not related at all
does not matter, not disclosing ALL information or drip feeding it does not make it easy to help you
oh wait. i think that error is beacuse i was already in playmode when i pressed attach to unity
beacuse it is not ususal
well.... after i pressed attach to unity i have 23, 250 stacked errors, going up on every frame. mostly null exceptions.
yea that happens when i compile code when my game is running
gimme a sec
tag the rb with ingore reaycast
lots of them, from lots of scripts
thats not an error
i said it was beacuse i attached to unity when i play mode. now they are gone
how would one go about that
mostly nre's i bet
it should already be a thing
air sorry
layer
not tag
put it on ignore raycasy layer
like exclude
oh wait
well what do i do now? how do i see the execution order @languid spire ?
you can t layer specific components
i am in play mode
alrighty tyyea you can i think
player settinga
oh there you go
you set breakpoints in your code and see which ones fire and in what sequence
yeah try that
but should it be on exclude or include
try one then both
ok
see what works
wait
i think thats just the layers the rb interaacts with
so it only will collide with things that ignore raycast
@vast vessel if you've never used the debugger before, read this https://unity.huh.how/debugging/debugger
wanna try setting the entire player to ignore rsycasts
uhhh sure
when i habe it paused, and i press the press over button it goes highlights lines of code in my project in the order they are executed, but it does not highlight base.Awake on my strider script. is that normal?
probably not
i also have this script, AI_Soldier :https://hastebin.skyra.pw/solavaroki.csharp
it is also of type AI_Agent, and also has the base.awake() thing, and i also get this same behavior there of code not being highlighted, but AI_Health dosnt have any errors on game objects with the AI_Soldier script
is it written exactly the same?
yes
at the start of Awake
look at the code
do you know how to read a stack trace?
i dont do ai
this is AI_Strider :https://hastebin.skyra.pw/abowinetiw.pgsql
not related to ai. its a null exception
it would be like sending acleaner to do brain surgery
but the code is
that thing that tells you the order of execution when you get an error, or log something in the console?
yes, but it also shows you that in VS
So if you put a breakpoint in AI_Agent.Awake you can look at the stack trace and see how it got there
first it traces back to health.Agent = this; in AI_Agent, then Base.Awake() in AI_Strider
damn, this is so difficult without screenshots, can you try to fix that?
it is indeed and I bet there is a real simple explanation for it
is it being overridden anywhere?
thats the point of using the debugger, to find out
fair enough
his code is pretty complex
pretty?
lots of inheritance
yes
bro imagine its something like a misplaced bracket or semicolon
Yes but the base is still being executed
which would be wierd to get an nre from but still
aha
with the project and the VS debugger I could solve this in 5 minutes, just based on the code is somewhat trickier
i believr i havr a lead
I wish you could just come over to my desk
Wait.... u got anydesk?
can you send your project via Google drive or something?
no way
11 gigabytes? Hell no
are we gonna IT team this
you can do an export you know, dont need the complete project folder
Guys i gtg. I will come back to makig you suffer in like 15-30 mins
I'm out for the rest of the day shortly, I'll tag you when I get back
you don't need to send Library folder
Dont you also need the scenes that have the components in them? And the models that code refrances? And animations? And.....?
ok and how is that related
to the Library folder
you can delete the Library folder and zip&send the project
then whoever opens it, it will build the llibrary for him
does anyone have any advice regarding how i can make a gameobject "split" into two? (destroyed and then instantiates 2 more in OnDestroy with a smaller scale), not only can i not do it correctly i also get the error "Some objects were not cleaned up when closing the scene."
should i instead spawn these gameobject in the OnCollisionEnter2D method? and then i call Destroy
or maybe if anyone has a good tutorial for this situation
I was going to tell you that alot of my projects weight comes from my assets
as i said
Library is not your assets folder
you can safely delete the Library folder
it says * cant be aplied
it's not a Vector3
👍
is this the same as this?
transform.rotation = Quaternion.Euler(Player.transform.eulerAngles * -1);
no that won't even compile
it doesnt. i tried
What if eulerAngles is (0, 0, 0)?
then it will be 0,0,0
which is the same, not opposite direction
but what would be the opposie direciton of 0,0,0
when the player has no rotation
Inverse() would also set it to 0,0,0
sprite rotation is not object rotation
if euler angle is 0,0,0 then both methods will be the same result
who talked anything about sprite rotation?
also make object with sprite child of object you are moving
otherwise moving it will be confusing
if eulerAngles is (0,0,0), then
Quaternion.Inverse(Player.transform.rotation) will return the same value as Quaternion.Euler(-Player.transform.rotation.eulerAngles); im pretty sure
Actually I just tested it; you're right 🥴
seems like a silly feature to have
ow nice, was about to test it myself
thanks for confirming it, I wasn't sure
the Inverse seems pretty useless then
See above; you could do transform.forward = -Player.transform.forward; instead
Hi guys, Im trying to make a rolling ball. I have it looking exactly as I want but when the ball rolls, it doesnt have any friction (stays in place)
heres the code
Im just rotating it, is that the issue?
yes
Thats fantastic, thanks mate.
rb.transform doesn't affect the rigidbody, it's exactly the same as just accessing transform directly
It does, but rb.transform is a reference to the object's transform. Rigidbody doesn't have its own transform
Okay so the rigidbody is just a component, the object has the tyransform?
right
transform?
...what?
It moves the player forwrd
What does?
transform.position = Player.transform.position+ offset;
this is for camera to follow player
And how is that related to anything?
Because that sets the transform's forward direction to the opposite of the player object's forward direction
I dont understand why I would do that
That's what you asked for?
this happens when i do that
Why tf would you replace the line that moves the transform instead of the one that rotates it?
🤦
Which is what you asked for
actually no
yes
i see
i asked the question poorly
your right
should have provided more details there
I was just trying to make cameras rotation in X axis the opposite
but i fixed it
what i was trying to do was basically: camera transform.rotation = players rotation (in x axis) * -1
you see how camera rotates to left when player rotates to left
i tried to do the opposite thats all
can you tell me why continousmovespeed works but continuousrotation doesnt?
Doesn't work in what way?
Well for one if you use a fixed vector value it should be rb.AddRelativeTorque
You can see the rotation values change
I know this was a while ago you said this but I've been trying to search for something to fix it myself 😭, you ever managed to figure this one out? Or what the thing causing the error was if you remember?
make the rotation force bigger
oo yes
i didnt pay attentiont to there
i set it to 6000 now it rotates a bit
in my mainship if it was like 20 it would go like spinning really fast
i didnt quite get why i have to set it to such high values here but nevermind. it works
I think it was the spaces that made it not work
I'll have a check ty, the video I'm finding is quite old since they were using WWW rather than UnityWebRequest and in php they were using mysqli rather than PDO
So just tryna figure out how to change it
{
RaycastHit Hit;
if (Physics.Raycast(camChild.position, camChild.forward, out Hit, 20f))
{
floorBuild.position = new Vector3(
Mathf.RoundToInt(Hit.point.x) != 0 ? Mathf.Round(Hit.point.x / 2) * 2 : 2,
Mathf.RoundToInt(Hit.point.y) != 0 ? Mathf.Round(Hit.point.y / 2) * 2 : 0,
Mathf.RoundToInt(Hit.point.z) != 0 ? Mathf.Round(Hit.point.z / 2) * 2 : 2);
if (Input.GetKey(KeyCode.B))
{
Instantiate(floorPrefab, floorBuild.position, Quaternion.identity);
}
}
}``` hi im trying to place objects at run time im using cinemachine. i can only place items in a circle around me rather then where my mouse is pointing. Or is my code wrong?
You're not using the mouse at all to get a position to place it. From the variable names, you're using the ... camera .. dun dun dun dunnnnn, shocked face
nothing related to your mouse position here
so why would it spawn where your mouse is?
Anyone knows any good tutorial for teleporters in metroidvania? E.g. the "horse" in hollow knight?
yh sorry i see what you mean. I had a child object under my main camera. an i thought that it was coming from that.
Theres also the mirrors in castlevania
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); cheers
Might be better to ask this on #💻┃unity-talk additionally, you have to say your setting since magic mirrors on a sci-fi setting will not sit well.
[Serializable]
public record InventorySlot(ItemSO Item, int Amount);
Are records not serialised in the inspector?
records aren't even fully supported in the engine
I was more worried abt the code, not the game design
https://docs.unity3d.com/Manual/CSharpCompiler.html
C# 9 init and record support comes with a few caveats.
this looks like what happens when the inspector GUI throws a fit. i'd try selecting something else and selecting your object again
ah, but
You shouldn’t use C# records in serialized types because Unity’s serialization system doesn’t support C# records.
that's more of a showstopper
teleporting is teleporting, how you visualise that makes no difference to the functionality of it
Yes I had to define IsExternalInit, but if I can't use them for serialisation I'll find a a way around this. Just wanted to know if they're not supported or if I'm doing something wrong. Thanks for the heads up 👍
Yeah I thought he was asking for ideas for instant travel in general.
Poorly asked question I guess, missing the spcifics of what they actually need!
This isn't really the kind of thing a tutorial would exist for. One, it's incredibly specific to your particular design, and two, it's incredibly simple. Whatever you are doing to load a new area, just... do that. It doesn't change anything just because the area isn't "adjacent"
That is a good point to make
It shouldn't be very special.
whether you're loading a saved game, going from room to room, or using a teleporter, it's all pretty much the same thing
The issue of records not being serialized is less about the records (which are just classes after all) and more about the fact that it's using properties, which Unity doesn't serialize.
This will serialize just fine:
[Serializable]
public record MyRecord
{
public string Field;
}
you change scenes if necessary, and then you position the player correctly
The one liner you're using:
[Serializable]
public record InventorySlot(ItemSO Item, int Amount);
generates (roughly) this class:
[Serializable]
public class InventorySlot
{
public ItemSO Item { get; init; }
public int Amount { get; init; }
}
Of course, Unity won't serialize this, because these are just auto-properties. You can add SerializeField to the backing field like this:
public record InventorySlot([field: SerializeField] ItemSO Item, [field: SerializeField] int Amount);
However, this won't work either, because the backing field generated from this will have the readonly keyword because there's no setter, so Unity will still not serialize it.
good insight (:
Indeed, thank you!
make sure that your !IDE is configured so it underlines errors for you. then stop trying to use a variable that does not exist
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
• Other/None
ops
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour
{
[SerializeField] GameObject exitPanel;
public void PlayGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
public void QuitGame()
{
Application.Quit();
}
public void Openurl()
{
Application.OpenURL("nuh uh");
}
public void AreYouSure()
{
QuitPanel.SetActive(true);
}
public void AreYouSureNo()
{
QuitPanel.SetActive(false);
}
}
here we go
guys what should i do
oh u meant me
yes
not sure what u mean.. but u can use just 1 method for both these cs AreYouSure(bool verdict) { QuitPanel.SetActive(verdict); }
but how
Tutorial on how to close and exit your Unity game either with just one click and one line or code, or with a pop up "Are you Sure?" confirmation box.
im trying to follow this video
follow the bot's instructions to get your code editor configured. that is step 1. it is a requirement to have configured tools to get help here
If only there was a bot that posted that told you how to configure your !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
• Other/None
did you follow all of the steps for the code editor you are using?
just follow it one step at a time.. its really not all that difficult
when its correct you'll see Assembly-CSharp at the top
done
yepi
Did you configure it. Do you have a red underline under your error
public event Action<Inventory.InventorySlot[]> OnInventoryLoaded;
How do I allow outside classes to Invoke the event without using a function?
there you go. now stop trying to use a variable that does not exist
you don't. that's literally the point of the event modifier
Okay good. Now you should be able to solve the problem. There's no such thing as QuitPanel
the video says ```quitPanel````
makes sense, but I must invoke it on start, but the class isn't a mono behaviour
that's cool. you do not have a variable with that name in your code. nor are you atttempting to use a variable with that name. you are trying to use QuitPanel which does not exist in your code
then you must create a method on that object that invokes the event and you can call that method from other objects