#๐ปโcode-beginner
1 messages ยท Page 650 of 1
Hey everyone, I know this isnt exactly coding but I cant possibly begin to think where else to try and find an answer to this so I defaulted to here.
Im using CodeAcademy to try and learn C#, and literallt the 3rd thing it asks me to do I dont even know what It wasnts from me. What the hell is a CS and why am I typing it? What does it do and do I even have it? Im so bafflingly confused as to whats going on.
you mean cd?
cd stands for "__c__hange __d__irectory", it's used to navigate the file system
i'd recommend googling that sort of thing in the future
but uh, you sure it doesn't want you to actually open the project in vscode?
this thing
{
public Transform player;
public Vector3 offset;
public float smoothSpeed = 0.005f;
// Update is called once per frame
void LateUpdate()
{
if (player == null) return;
Vector3 desiredPosition = player.position + offset;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;
}
}```
Trying to make a script to make the camera follow the player smoothly but it ends up looking really jittery
also @maiden estuary if you're asking about just c# stuff unrelated to unity (project setup is kinda handled by unity) then maybe ask in the csharp server
https://discord.gg/csharp
Applying lerp so that it produces smooth, imperfect movement towards a target value.
sorry i misremembered the url
yeah i posted that above
i edited my message to point to the right place
Im just following the learning on code academy, it goes download VSC, download an SDk, then to this. Theres nothing that says anything about making a project, making a folder, nothing.
im not sure it's the source of the jittering issue, though; just something to be aware of
I didnt google it because I didnt even know if it was a term, it couldve been like, a file name they made or something
create a new console app project using the terminal
How
I dont like
Am I just fucking dense what
generally the first step is to google stuff
"console cd", "terminal cd" both get you results about what it is
the video you sent includes creating a plain c# project in that 2nd step
i don't know how, i don't do plain c#, only unity lol
unity handles this section for you
could be this one
I tried typing "CD Desktop" and while it produced a different result, it said it doesnt exist?
not sure why you'd go there, "desktop" seems pretty unrelated to this whole thing
Cause I made the folder on my desktop, I figured it out and I was on the right track
Oh god dammit I need to move my unity from MSV to VSC fuck
...huh?
no clue what msv is here, but you definitely don't need to move unity into vsc
they work alongside each other
I have it so it runs on Mocrosoft Visual Studio, but now because of this code academy I moved over what I'm coding in to Visual Studio Code, so now I would have to change what it's recieving from to VSC would I not?
unity doesn't have to "move" anywhere
Poor word choice
also visual studio is just known as vs
are you talking about the "external editor" configuration in unity? if so then yeah you would have to change that
btw though; if you're just planning on learning c# for unity, maybe just skip the project setup stuff and get to the actual language, since that'd be what you'd be using
Yeah that's what I'm doing now. I started off just trying to figure out how the engine itself worked, foolishly thinking that made more sense
I don't even remember how to do this god dammit
!vscode
Is there a better shape/size of hitbox to use for this or nah
This is when the player is falling
Depends on the context, for humanoids, usually capsules are the best way to go surrounding the head, body, and legs in a standing state
Boxes are fine, capsules just work better for humanoids at least in my experience
Good stuff thank you very much
Also your question isn't really code related, so you would be better off asking in #๐ปโunity-talk considering the question
ty mb
give it a sec to add the file to the project
may someone please help me with my code?
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #๐โfind-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
can't help if we don't know what to help with, so don't ask to ask
okay
so im following the Brackeys youtube channel cube guide thing (i can send link if needed) and the code wont work
found it
it was a typo
Hello guys, I'm not sure why my Coin object isn't appearing. I initially thought it was because the BulletController script Iโm using to instantiate the coin gets destroyed when my bullet collides with an enemy. However, Iโm dropping the coin before deleting anything, and I also have the reference to the coin prefab correctly assigned. I've tried debugging, but all I get is that the bulletPrefab is null.
It should drop when I kill an enemy, heres the code:
https://pastecode.io/s/dw8fgv47
can you explain this part?
Invoke("EnableCollision", delayBeforeDestroy);
private void EnableCollision()
{
GetComponent<Collider2D>().enabled = true;
}
Hello, can anyone tell me why the resolution is weird when I export my game, even though I've selected the resolution by hand?
The game view resolution in the editor doesn't affect the build in any way
also i guess you want to use random value instead random range here :
float chance = Random.Range(0f, 1f); // Generate a random chance
// 50% chance to drop a coin
if (chance <= 0.5f)
{
GameObject newCoin = Instantiate(coinPrefab, position, Quaternion.identity); // Instantiate coin
}
It's a delay that I have set to 0 in the inspector, so it shouldn't affect anything. I had it to disable the bullet collider
ok, change the random.range part please and see if it is what you want
i'll try now thanks mate โค๏ธ
it's exactly the same thing
oh he is converting it into float
use some Debug.Logs, make sure the collision is really taking place etc.
hey, just a seemingly simple question. why does it feel like intelisense is getting trashier and trashier? it keeps suggesting to add whole blocks of code, instead of autocompleting simple lines like myBool = true;
im on vscode btw. and no copilot. but it feels like it is copilot thats doing these suggestions from how bad they are
like, every time i make any brackets, it tries to tell me what script im trying to make while it has no idea what im actually doing
it sounds like you're talking about intellicode, not intellisense
could you show an example of what you're talking about?
Hey i have a script here in a 3D game where it's meant to detect a collision and send a debug.log, then run a coroutine but nothing is happening when the gameobjects touch. Can someone please help?
public float UnitClass;
public GameObject Ore, Ingot;
void Start()
{
if (this.CompareTag("Drill"))
{
UnitClass = 1;
}
}
void OnTriggerStay(Collider other)
{
if (other.CompareTag("Mineable"))
{
if (UnitClass == 1)
{
Debug.Log("Mineable Found");
StartCoroutine(DrillMineOre());
}
}
}
IEnumerator DrillMineOre()
{
yield return new WaitForSecondsRealtime(3);
Instantiate(Ore);
yield return new WaitForSecondsRealtime(1);
}```
don't directly compare floats
holdon let me se if i can get it to do it with a good example
where
UnitClass
ints or other values
you should debug log in the compare tag and in the ontriggerstay aswell
figure out where specifically thing isnt happening
alright
should UnitClass even be a float
here i just made an if, and thats it. nothing of what its suggesting here would be desired as its essentially copying previous code but badly
also becarefull , you would be starting a ton of Coroutines if the OnCollisionStay takes place
Darkovic
yeah im gonna fix tha
yeah that seems like intellicode. more AI garbage
didnt mention that because i figured it would mention itself when it happens ๐
i changed to int and added more debug.logs and still nothing
is there anything i can do about it?
search in settings for "intellicode"
cool, ill try that
is the situation matching the conditions for OnTriggerStay to be triggered?
https://unity.huh.how/physics-messages/trigger-matrix-3d
forgot you need rb's for trigger stuff
its been a while alright
what does kinematic do again
makes the rb do less (doesn't respond to collision or forces) so it can be moved manually
wdym? everything here looks just fine to me
would making the coroutine restart itself at the end of the cycle be bad?
e.g:
{
yield return new WaitForSeconds(4);
StartCoroutine(Coroutine())
}
Just use a while(true) loop instead
With the yield inside the loop
Otherwise you are creating new coroutines which creates garbage
(Which isnt a huge concern every 4 seconds but might as well do it the better way)
would you be able to provide a quick example please
never done whiletrue in unity
IEnumerator MyCoroutine() {
while (true) {
// do thing every n seconds
yield return new WaitForSeconds(n);
}
}
naturally, id be able to swap out "true" with any bool, yes?
also
wouldi have to manually start the first coroutine or will it happen automatically when (true)
Also note that this setup won't be accurate over time, if that matters to you you'll need to yield per-frame and track time manually
thats alright
You'd start this once and it will run forever unless you change true to some condition or break out of the loop
And as long as the owning object is active
so hypothetically if i had:
public int MyInt;
void Start()
{
StartCoroutine(Coroutine());
}
IEnumerator Coroutine()
while (MyInt == 3) {
yield return new WaitForSeconds(n);
}
}
would that work
Sure
It would work
alright
Although, if MyInt is not 3 when you first start the coroutine, it doesn't get a chance to check it again
ah ok
would it still do this if i put the startcoroutine part in update
you should probably just start it in OnTriggerEnter and end it in OnTriggerExit or something
yeah but ive already come all this way and id like to look at this whiletrue thing
If you want to use coroutines here, maybe you want something like cs IEnumerator Coroutine() { yield return new WaitForSeconds(4); if(MyInt == 3) StartCoroutine(Coroutine()); }
(I didn't read all the previous messages yet)
i asked about doing that and somebody else said it wasnt a great idea
Wait that was me
Do you need something to repeat?
I think Chris' suggestion is the best here #๐ปโcode-beginner message
If you want to use the while loop for learning purposes you can do something like this
OnTriggerEnter -> set a bool to true and start coroutine
OnTriggerExit -> set the bool to false
Coroutine -> while(thatBool) { ... }
simple structure ^
could also use while (true) and a StopCoroutine
oh thats what its called
both objects have collider component and one rigidbody I guessing and is trigger on one, OnCollisionEnter for physical and onTriggerEnter ( for trigger) , also make sure the layers can collide with each other in the matrix
hope that helps
i took the message too literaly and tried to write EndCoroutine()
no worries ur in good company
cachedCoroutine = StartCoroutine(myCoroutine());
StopCoroutine(cachedCoroutine);
{
private Coroutine myCoroutine;
public int MyInt = 0;
void OnCollisionEnter(Collision collision)
{
myCoroutine = StartCoroutine(MyCoroutine());
}
void OnTriggerEnter(Collider other)
{
myCoroutine = StartCoroutine(MyCoroutine());
}
void OnTriggerExit(Collider other)
{
if (myCoroutine != null)
{
StopCoroutine(myCoroutine);
myCoroutine = null;
}
}
IEnumerator MyCoroutine()
{
yield return new WaitForSeconds(4);
if (MyInt == 3)
{
myCoroutine = StartCoroutine(MyCoroutine());
}
}
} ```
does this work
sorry I just got here bad formatting
''' "" ?
nope.. `
I'm using a 75% keyboard so having to use US a lot to acess hash
backticks.. not quotes
``````````` `*
might be easier for u to use a paste-bin then !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.
You'd want to check that a myCoroutine is not already running (not null) before starting one
the real MVP
thanks, fixed it with Darkoviks post
took me a while to get it
i win yet again
rackin up dubz
myCoroutine = StartCoroutine(MyCoroutine());
}
else
{
myCoroutine = null;
}
It's good to keep in mind that you can be inside two triggers or touch two colliders simultaneously
and for trigger / collision enter if (myCoroutine == null)
yeah been doing that between typing
what
it has very clearly worked very well with no issues and not at all fked up
does the fox say ๐ฆ
totally hasnt gotten worse
be bap badee badee ho
sometimes it has to be worse b4 it gets better
true
I put a short clip of what I'm working on in #archived-game-design if anyone has a second for some feedback ๐ โค๏ธ
hope is right place
gotta hit rock bottom before the only way is up
well it was
I need help with the red moving platform
i've tried so many things and it always looks juddery
You should use #1180170818983051344 for showcasing and asking for feedback
you can only build a solid foundation atop bedrock ๐
(Also I don't think people like it when you advertise on other channels)
ah right i'll put it in there instead thanks
oh mate its 15 seconds of a prototype I did today not an advert
builds solid foundation midair just to spite you
this aint minecraft
fark
nobody said it was an advert?
osmal did
oh
he said advertise on other channels but I need help with the problem in the clip, misunderstnading lads (: !
I don't mind that much, just pointing it out
also osmal means advertising your question
Didn't mean it's a literal advertisement lol
stick to one channel; if it doesn't fit, move the question, don't just copy it over
sp(delta)wnc(delta)mp is a sick user btw
sure thing, it's no biggie, just working out how people operate in here and already came in to contribute (: !
no need to argue โค๏ธ
gotta respect the difference ๐
delta's signify my journy or learning.. what i did know vs what i do know.. vs what i thinki know.
oi sick
something something Dunning-Kruger effect
so does anybody else have any ideas?
(full code for reference): https://paste.mod.gg/yxphbgmjikri/0
A tool for sharing your source code with the world!
what ideas u lookin for?
fixes
i bet that frame-rate is wicked
a goo and solid 12 spf
๐ค i agree
better than modded minecraft
Enter -> Exit the way to go. to avoid Spam
oh yeah forgot
Stay go brrrrrr
yeah and check I-enum is null in else statement on each
what
Nothing here stops it from starting a coroutine every physics frame in ontriggerstay
uhhh the enumerator?
i don't think anyone abbreviates it like that lol
IEnumerator i think they meant
yeah
if you're gonna shorten it just drop the I lol
i thought they were saying enum in french
like this
le enum
l'enum
lol
(i don't know french)
no sleep its 2:27pm over here in England, cut me some slack ;;D
I would add to the coroutinecs if(MyInt == 3) { ... } else myCoroutine = null;
people that develop at all hours of the night.. i just have so much concern for their code-base..
Because it doesn't get set to null automatically
what if it ends?
yield return null;
The reference stays
ohh interesting
Only unity objects can magically become "null" even though you still hold a reference to them
yeah in uni they insisted for good reason to always clear states and ints that will be potentially used in memory or active, even when 'le compiler didint care' lol
the left side is a function.. in ur screenshot
You need to store a reference to the coroutine. This part of the example: cs private Coroutine myCoroutine; ... myCoroutine = StartCoroutine(MyCoroutine());
Coroutine mineCoroutine;
void StartMining()
{
if (mineCoroutine == null)
mineCoroutine = StartCoroutine(DrilleMineOre());
}```
```cs
void StopMining()
{
if (mineCoroutine != null)
{
StopCoroutine(mineCoroutine);
mineCoroutine = null;
}
}```
this is how i would start it out if i were doing something like that..
firstly just get my coroutine being cached.. and reset to null.. and having methods to start and stop the coroutine
{
public int UnitClass;
public bool ShouldDrill;
public GameObject Ore, Ingot, BeltItem;
private Coroutine drillCoroutine;
void Start()
{
if (this.CompareTag("Drill"))
UnitClass = 1;
else if (this.CompareTag("Furnace"))
UnitClass = 2;
else if (this.CompareTag("Belt"))
UnitClass = 3;
}
void OnTriggerStay(Collider other)
{
if (other.CompareTag("Mineable") && UnitClass == 1)
{
Debug.Log("Mineable Found");
Debug.Log("Drilling");
if (!ShouldDrill)
{
ShouldDrill = true;
if (drillCoroutine == null)
drillCoroutine = StartCoroutine(DrillMineOre());
}
}
else if (UnitClass == 2 && other.CompareTag("Ore"))
{
other.gameObject.SetActive(false);
Instantiate(Ingot, transform.position + new Vector3(0, 1, 0), Quaternion.identity);
}
else if (UnitClass == 3)
{
if (other.CompareTag("Ore"))
BeltItem = other.gameObject;
if (BeltItem != null)
BeltItem.transform.Translate(0.25f, 0, 0);
}
}
void OnTriggerExit(Collider other)
{
if (other.CompareTag("Mineable") && UnitClass == 1)
{
ShouldDrill = false;
}
}
IEnumerator DrillMineOre()
{
while (ShouldDrill)
{
yield return new WaitForSecondsRealtime(3);
Instantiate(Ore, transform.position + new Vector3(0, 1, 0), Quaternion.identity);
yield return new WaitForSecondsRealtime(1);
}
drillCoroutine = null;
}
}
try this
then i'd just iterate and refactor
and if not its still the IEnumerator needing to be nulled on the collosions
else derp im ded
Oh crap i think i just put your code
just to double check put again
void StartMining()
{
if (mineCoroutine != null) StopCoroutine(mineCoroutine);
mineCoroutine = StartCoroutine(DrilleMineOre());
}
// to start mining we stop the old mining first (if there is one)
// then we cache the *new* one
void StopMining()
{
if (mineCoroutine != null) StopCoroutine(mineCoroutine);
mineCoroutine = null;
}
// to stop mining we check if we *are* already mining.. and if we are.. we stop it and clear the reference
huh the what now
I think the update() is a bad place to have the coroutine called
because its making it every frame
we noted that
fr.. wouldnt the OnTriggerEnter -> be the one in charge of calling or starting the coroutine
welp, id much rather wake up to discussions of coroutines..
yesterday it was Quaternions ๐
hol up i think i did it
yeah but ive done handles for ontriggerexit and null checks in that code snippet it should work
nevermind
soup bowl goes hard
i gotta hop off a sec.. just wanted to post up my example if need be.. ๐
oof apparently i can't spell Drill either..
ok so we are a step closer
hecks ya
aww man see ya
so this was wishful thinking?
pree much
see ya, i'll be around most of the day... just gotta get my day started first b4 i settle back down ๐
fair
holy ||shit|| your thing worked tysm
i frankensteined it into my code and it works
I'd still add a mineCoroutine = null; at the end of the coroutine
(almost)
just working on the instantiate now but the hard parts over for all i care
lol u had a 70-80 percent chance it would or wouldn't...
actually its 100 percent it works as it is. but its only debugging.. the part where it normally breaks is implementing it wth ur own custom logic
there i did it
but sounds to me like uv gotten on the right path
i am king of unity
wanna finish my game for me then?
(false news)
ye alr what is it
open world skyrim clone
done
lol j/k its just a simple lowpoly first person shooter
Release it in steam for him
workin on projectiles at the moment
gotta tell em about a thing called "gravity"
and they should be fine
so can u confirm? did you fix ur issue?
btw heres a list if anybody wants:
- GunKill 1 (7 versions)
- GunKIll 2: Ultimate Demise (3 versions)
- GunKill Online ( 2 - 4 versions i forgot)
bruhh alright let me convert
there we go
pov religion in 1500:
nah not really but thanks
np.. converting mkv's are fun too
hi y'all, question on wireframe objects. When I create a wireframe object, the color of the wires are a function of how far away I am from the object (for example if I have a wireframe plane, some elements are red, others are green, yellow, etc, all as a function of the radius between me and that particular point. Can we have just a single color for the wireframe object?
What component is that? I don't remember there being something like that in unity by default
yeah me neither i think its a custom script
bro im so used to being in vs that i just tried to press control s before sending that message
That sounds like one of the XR (?) debugging shaders
Spatial mapping wireframe shader or something like that
Is that it?
Hey, can I not Invoke an Event from outside it's script?
yes, correct. I have the same effect
and you can have other layers beyond just red and green
Like, this but without the wrapping method. I want to call it from another script
@spark sinew I guess you can try editing the shader (a copy of it) and removing the color gradient functionality
But if you need help with that then #archived-shaders
Or just look for a similiar shader online
im pretty sure you have to wrap it
Remove the event keyword from it
AFAIK all it does is prevent it from being invoked from the outside
Mmmm, so I would have no real reason to make it an event to begin with then
you have to have the VR stuff installed to use that shader?
if you want it to be invoked from outside of the containing object then it does not need the event keyword
Let me see where it came from
I don't have any VR packages in the project
I think it just came with HDRP, not sure
thanks.. i'll look into it
been wanting a generic one to use
I have a manager that takes care of when some children are enable or dissabled and notifies that to the UI to update accordingly, but it may happen too that the children become inactive from outside the manager influence, I think I do need it to be called from outside, but maybe I am just making a mess lol
The entire point of the "event" keyword is to prevent this
If you want to do it from outside remove the "event" keyword
I would just recommend the wrapper method anyway though
why are the children becoming inactive outside the managers influence
Cause they attach to other objects and I am reseting from their own script when the object is destroyed instead of calling the manager, since that would require some unneeded list iterations
is it fine to getLoclizedString in update ?
depends on ur definition of "Fine" lol
myself i'd only get it when and if it changes
could use a flag to mark it as dirty when it needs updated
a couple of strings aren't gonna make a noticeable difference tho
What's the usecase?
i want to update some descriptions in which some numbers and multipliers changes with some player actions quickly and some score and stats display ?
Doesn't sound like it needs to be in Update, it'd be better to change only when something changes
I think i have a little messed up code with so many events and stuff that i myself am not sure when those values changes as there were many modifier so i just put in the ui stuff in update but now that i am localizing my game its becoming a pain :<
Sometimes it's good to take a bit of time to refactor things into something that's easier to work with
yes thats what i am thinking
yo does anyone want to check my code cuz im running my game but i cant seem to move even with the code i implemented if anyone has a solution plz dm me
we don't do DM support here, just ask
oh mb
if you think the code is the issue, show !code as per below:
๐ 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 thx
!vscode
love how my game is so well optimised it cant handle more than 13 conveyer belts
beautiful work on my part, really
however, hundreds of loose, physics-based items is alright
honestly i dont think i couldve done better
maybe they dont all need to be physics objects? or atleast not all the time..
maybe theres some optimizations to be had
if 100s of physics objects is just part of the gameloop then you'll probably want to find some optimizations somewhere somehow
How can I order the children of a gameObject? I have a button that adds a prefab UI element to the hierarchy and I want it to be exactly on top of the button and after everything else
hint: look at the docs for the Transform class
Mmmm.... I was thinking more of GetSiblingIndex (of the buttom) and then SetSiblingIndex (of the instantiated prefab) to that one
Ohh cool. I thought you meant "on top" in UI . gotcha..
I want it to be the last one of children, but always before the buttom (which would remain)
makes sense.. I literally just learned about SetIndex myself now lol I havent played around hierarchy too much via code
100s of physics objects is fine tho
ive fixed it
hold on
depends on the code tbh.. im almost positive i could get 100 physics objects to crash out ๐
ok i havent quite got it but its close enough for me to focus on other tasks
ill dm you a build of the game if'n ya'd liek
whyd i tirn texan
just create u a #1180170818983051344
whyd i go buster scruggs mode
๐จ๏ธ "if'n" pretty cool word
alright im done
thats what im sayin
How should i start about learning code plz i am so lost rn
Make a console application and learn the basics before jumping into 3D applications
make an RPG in console you will be a c# expert in no time xD
did you actually read it ?
cause it tells you why exactly you are getting it
yes but i dont know what to change in player settings
do you want to use the old or new system
...how you use them
i want the new system ig
cool, then uh, stop using the old one?
right now you have it set to use the new system, but you have code using the old system
then you can't use anything in the Input. class
oh
what do i use instead?
the many ways New Input system supports
Event , Messages or Polling
imo if you're new to unity you should probably learn the old inputs first
so tutorials dont look confusing
alr
you find it here..
You can use either the Old the New or Both
i currently have it set to Both.. b/c im learning the new system.. but alot of my legacy code uses teh old
hi guys im new to unity and coding but i realised codes in tutorials i watch dont work in unity 6.1. So do i do something wrong or is it actually not working? cuz i tried the same codes on an older version of unity it worked but in unity 6.1 it doesnt work. So my question is should i stick with unity 6.1 or i use the older version 2022?
which code exactly?
for example this one whatever i do i couldnt make my character move
are you getting an error ?
the only thing changed here is Input system is now considered legacy
you are trying to read input using the unityengine.input class this error
yes this has been defaulted in unity 6 to new input system.. You can do this #๐ปโcode-beginner message switch it to Both so you can continue with tutorials
also that tutorial is really bad..
remove all the Time.deltaTime from the calculation (in fixed update its fixedDeltaTime so you'll applying it twice)
rigidbodies already has a fixed time , adding that is whats making those forces such high numbers and probably cause jank issues in lower frames
i mean i tried without time delata and it still didnt do anything and about force numbers, wiht lower numbers my cube didnt move when i higher the numbers it started to move that was so stupid
if its gonna be that hard to learn on 6.1 i should go to 2022 version or 6.0
idk
what I said had nothing to do with it not moving.. its not moving because the old input system was disabled
ig ill try out
yeah but it was moving at somepoint
when ? because if you have this error it never moved.. #๐ปโcode-beginner message
if it moved its probably because the line BEFORE the inputs
oh wait mb sry
Time.deltaTime(in this case fixedDeltaTime cause its in fixed update) isn't 0 so forwardForce * small number it wouldve moved a little sure
None of this has anything to do with the different versions of Unity.
Game-dev and coding is hard.. regardless of what version u use... for example ^ dealing with time.. and deltaTime is exactly the same.. the only things that have really changed are just a few menu items..
and ofc some methods that have been deprecated and/or replaced with alternative versions..
for example rb.velocity became rb.linearVelocity
but all of that can be googled super easily.. IDE makes squiggly underlines.. hmm that should be right tho,
googled-> ohhh its linearVelocity now
everything works exactly the same as it would in 2022.. Unity just decided to default the new input system as inputs..that can be easily changed, everything else is the same.. besides that one change to velocity ^
and a few of the Find methods
thats teh only two i've encountered so far
but yeah as spawn said 100% get yourself a configured IDE and it will tell you the replacements in the code editor
hopefully its the only two i will encounter.. lol.. I finally remember teh alternatives! haha
on related note..I always wondered if there was come type of List of all the api changes through the years? I know its probably mentioned in docs or change logs but those you actively need to look
oh, ive noticed too the actual Unity console log is pretty good at telling u the alternatives as well
even if it makes it thru the ide
true
i'll keep this in mind.. if i can find something i'll be sure to let u know ๐
well ty ill stay on 6.1 then ty again
just take it slow.. dont get discouraged
this ^ also you should do the tutorials from here first !learn ๐ pathways
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
facts
random youtube tutorials in the beginning will teach you bad habits, esp the brackys ones are not the best code
this guys slaps Time.deltaTime on everything ๐
Hello guys, just staring with C# and got some mistakes that struggling to fix in my code, if someone can help me with ill be thankful
show !code and tell about whats broken..
๐ 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.
yes PlayerInput should not contain those.. Did you create / generate a C# class from inputs with same name?
just following the guide at YT currently
well then you should show that
what is this? where is the video
this has nothing to do with what i asked
The first video in a series where we are creating a First Person game!
In this video we look at setting up our characters movement.
I've setup a Discord!!! and I would love to have you help me start up a friendly community where we can all help each other grow as game developers!
Discord invite link:
https://discord.gg/xgKpxhEyzZ
Can't wait t...
9 30 is timecode
yeah this is trash..
anyway you should refrain from using the same Class name as the Unity Component
for exactly this reason
the ones from the unity learn site
its not even a tutorial thing, its just a common thing in scripting
don't use the same names for classes unless they are separated with namespaces
PlayerInput is already a component https://docs.unity3d.com/Packages/com.unity.inputsystem@1.5/manual/PlayerInput.html
the computer is confused to which one you're using, well here its directly trying to use the Component rather than your generated class
alright man, ill try to solve it
ok..the solution is just to rename the generated class from PlayerInput to something else
PlayerInputActions or something
whats the difference between the old and the new input systems? the new one is just breaking every tutorial i try to follow
'new' input is event driven, while the older input system is based on polling input in your update loop
if you don't mind checking for input in the update, then don't worry too much about the newer input system
hm, alright, shouldn't be that big of a deal to keep the old one
though the movement script from the tutorial i followed is not working, maybe i messed up somewhere
What have I done wrong here? Im seeing zero errors or anything, but "Hello World" isnt appearing like it does in the course I'm following.
How is this related to unity?
i assume the old input system for the player controller assumes WASD as the default keys?
Oh my apologies, wrong server.
or do i have to declare these in the script?
You can check in the input manager.
No.
yup, WASD or arrow keys are set as alternative and default respectively, so why is the capsule movement not working?
You'll need to share some code and setup details. Or debug it.
its what im doing, just installing C$ on VSCodium
C#*
ah, so i forgot to include some functions in the update cycle, and the capsule is moving! on the wrong axis but its moving
Hello, I just started the universal 2D for the first time and my camera is a circle, is there a way to make it rectangular?
I just see this atm
your camera is not a circle
Thx!
I am trying to draw a ray that shoots straight down a small distance forward from the center of my player object. This code seems logical but it is drawing a ray in the center of the map every time...
Debug.DrawRay(new Vector3(playerObject.transform.localPosition.x + 0.25f, playerObject.transform.localPosition.y, playerObject.transform.localPosition.z), Vector3.down, Color.red, 1f);
I'm not quite sure why.
DrawRay takes a world space position and you're passing it a local space position
If the player has a parent object, those won't necessarily be the same
Use .position not .localPosition
I assumed localposition would take rotation into account but i now see it doesnt work that way
The draw ray is working somewhat but is there a way so that the starting position of the ray rotates with the character?
the position doesn't need to rotate
you mean you want the direction to rotate
I don't think I do.
you should use basically:
DrawRay(playerTransform.position, -playerTransform.up, Color.red, 1);```
I think you do
perhaps draw a picture of what you want if you think it's not being understood
So I'm using a sphere check to check groundedness. I want a separate raycast a bit ahead of the center of the player to check if theyre close to an edge
idk if im wording it right but thats what i mean by the starting position should be a bit in front
so an offset
Ok so the question is what does the "rotated" version look like? Are you just meaning to do it to the left if the player is facing left?
and to the right if they're facing right?
yeah
then that would be:
transform.position + transform.right * 0.25f```
assuming you actually rotate 180 degrees on the y axis or invert the scale of the player when they face left
if you rotate the player some other way then you'll have to explain that for us to get to an appropriate answer here
this worked. I used transform.forward instead though
thanks for the help
I assumed you were in 2d yeah
based on your sketch
I need to read up on transforms some I'm still confused on using the different transform directions
ah fair enough lol
pret straightforward
forward is the blue arrow you see
when you select an object in the scene view with the position tool selected
right is the red arrow
up is the green one
that's all
ah that makes sense
whats throwing me off i guess is the addition part. does transform.right/forward/up represent an actual set of numbers?
it's a direction vector
you can add vectors to each other
this is pretty much basic vector arithmetic
and yes vectors are "sets of numbers"
basically this is all we're doing: https://www.youtube.com/shorts/6zVOlT_PmwM
i mean i get that (1,1,1) + (1,1,1) is (2,2,2)
the position is a vector, then we offset it by the offset vector we want, by adding them
yes the video I shared shows a visual representation of this and is all we're doing in 3d space
transform.up though, doesn't actually represent a number until we multiply it by something right?
what do you mean by "actually represent a number"?
It's a vector, which is a set of 3 numbers
it is an actual real set of 3 numbers
regardless of what you do with it
so up would be (0,1,0)?
if your object is not rotated at all, yes
i might be overthinking things here lol
you are
when you rotate the object on the x or z axis it will change
so in theory, transform.forward * 2 would give us the position of a point 2 units away in whatever direction the object is facing
well - not quite
not until you add it to transform.position
transform.forward * 2 will give you a vector in the direction the player is facing, with a length of 2
another way to think of it is that it's a position 2 units away from the origin (0, 0, 0), in whatever direction the object is facing
it... kinda makes sense but now i have even more questions
eh maybe i should watch a video on vector3 math
actually ok i think i got it lol
https://paste.mod.gg/qfkgdjonwwfl/0 I have this simple script, when I press one in the game, it doesn't switch to the desired meshfilter but to a cube. I know this is not code related much but I don't know where to put this. (Should be head in image)
A tool for sharing your source code with the world!
can you post a screenshot of both meshfilters in question?
Also out of curiousity any reason your referencing a meshfilter and not a mesh specifically?
oof, didn't know you could do that. Just placed the meshfilter and saw a cube.
Im super new to Unity and coding in general and couldn't find anything with some googling about my specific issue.
I have a button that when clicked, needs to rotate the camera 60 degrees, i have a function created to rotate the camera at a set speed, i just cant figure out how to make the button linked to it, or how to set it to do so for a set amount of time
Would need some kind of timer in update and setting the timer time or some bool from your button.
Could also use a coroutine.
This and more is covered in beginner pathways on unity !learn
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
thanks, honestly im struggling a lot but its pretty fun
think i might be in a bit over my head
its hard at first but once u get used to it its still hard but also easier somehow
Good morning, what is the best place to ask about package composition and similar topics?
How to remove baked lighting when playing the scene in editor, or when running the build? Directional Light is off, Cleared Baked Data in the editor, but they returned when running the scene.
Do you have auto bake on? Or check in your scene folder, if there is lightmap data still there from previous bake
yep that seems to do the trick, thanks!
I think #โ๏ธโeditor-extensions is best for asking this, you'd get an answer by somebody who knows about them, as this channel is runtime code usually, editor extensions would be best to be asked in the specific channel for it.
this.tag returns the tag that the current gameobject has right?
Yeah, it should, also just a side note, you can just put "tag"
thanks!
and
if I use this function
Spawn Bullet
on a different gameobject
(by refering to this gameobject)
Btw, please delete this since you reposted in another channel, just to avoid confusion
would it show the tag of the gameobject that called the function
or the tag of the one where it was created
It would use the tag of the source object, so the GO with the script attached
To achieve it not doing that, pass in a tag instead
So calling scripts would pass in their tags and the script would use them instead of its own tag
So like this script where it is written is attached to a gameobject called "gun" which is the parent to player gameobject, i'd like to call this bullet in the player script rather than the script i made for the gun
and what method should i use to do that? (i am really new with unity :/)
All functions work where they are, if you called from a player script to a gun object with that script, it would use the gun objects tag since you are accessing the current tag (that's why this.tag works)
function(string callingTag)
Something along those lines
so i have to create another function which calls the tag?
No?
I'm not entirely sure what you mean
You can add it into your current method unless you want to use tag for calling on itself
sorry, english is not my first language, it gets kinda confusing T-T
If you are very new with unity you can !learn here
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
thanks i'll look into it!
If you want to call another script, you need to have a reference to it. Either by script or inspector reference
yeah i know that
Ah okay, just wanted to clarify and be on the same page
but I want the createdBullet.sourceTag = this.tag to store the tag of the gameobject that calls the SpawnBullet() function and not the script itself
You can use 2 functions, one would be
function()
{
// This will call the other function with (tag)
}
The other would be:
function(string callingTag)
{
// This will have your code
}
yeh you just have to pass the tag with it if you calling the function on another script/gameobject as Dark suggested in the second method example
wait, i think i understand
waiiitttt
Didnt know u could do this, learn sth new every day
oh i think i understood
and when I call this function in my player script, i can pass in the player tag
right?
i feel so dumb, this was so obvious
Happens to all of us at some points
for sure ๐
What are some practical applications for this as compared to using something like
public void myMethod()
{}
void is a function in the end
Is it just another way to make it?
function() doesn't actually work
I think
I was just using it as a placeholder
Oh i see
What I was showing is you can have 2 functions with different variables
thanks ya all!
I really gotta get better at spotting the difference
I was typing the equivalent of Instantiate(instantiate parameters myGameobject) the other day
Hard to tell sometimes what it's asking for so makes sense
so now that I am calling this function from my player script, would the bullet instantiate from the gameobject that has the original script or from the gameobject where the function is called?
Simply put to answer any further questions: Functions call from inside the GOs they are linked with (if they are instance functions), so anything you put inside a function will be called from wherever it is located, so anything in the function will call from the object it's on, not the calling object
If you do gameObject inside a function, it will return the GO it is attached to, not the calling GO
Same for transform and everything else, but those are just 2 examples
so since the function is linked with the gun object and not the player object, it will instantiate from the gun object even tho player object is calling it anyways?
Yes
Yes, but you can pass in a Vector3 for the position it spawns, and a Quaternion for the rotation
So where transform.position is, would be a variable inside the function, same as the callingTag variable in the function, you would use Vector3 position
Then replace transform.position with position (Or whatever the variable you call with is named)
Just think of your scripts as people talking to each other. If I tell you, to water a plant, you will water it even if I told you to, right? So you are the script having the water, having the bucket, having a knowledge about the plant OR I give you the information about what plant to water. But I am just giving the "order", you are executing it.
i think i am getting it but the editor is a bit angry...
You didnt assign the gameobject
i have T_T
let me recheck the script
maybe i messed something there
Huh thats interesting
Well there's an error here
Did you fix that?
that wasnt an error actually, because i want the bullet to spawn from the gun (where the script is attached) and not the player (where the function is getting called)
Are you referencing the gameobject or a script?
Looks like you are referencing the script file from project view
Seems to be the object, but it's the class on the object
yeah, i think i figureed it out
i was referencing the script
rather than the object
changed that and its fixed
is there a way to detect if the input is being hold? Like currently I have to press left click each time i want to fire, which is good enough for basic shooting, but if i want to add variations by adding something like assualt rifle type of gun, i'll have to make it so that the gun fires a barrage of bullet when left click is hold
Input.GetKey()
Instead of .GetKeyDown
i am using the other input system
is it not good?
Its great
I don't really know, just confuses me
stick to the new input system for sure
Ok!
so is there a way to detect if an input is being held?
Its not that its not good its that the old one is easier to start with + people have been using it longer
One simple solution is to check when it started and when it was cancelled instead of performed
i find the other one easier imo, its more intuitive and better for crossplatform (not that it matters to me lol)
context.started and context.cancelled right?
and then i can add a bit of delay between each bullet spawn
from docs
action.started += ctx => /* Action was started */;
action.performed += ctx => /* Action was performed */;
action.canceled += ctx => /* Action was canceled */;
something for you to read along and learn ๐ https://docs.unity3d.com/Packages/com.unity.inputsystem@1.14/manual/Actions.html
i was actually openign that doc lol
Btw u should read #854851968446365696
The first code is part of a health script which is attached to my enemy, the seecond code is from a script attached to my Bullet, the sourceTag is basically tag from where the bullet is originating from (and it is working) but the bullet is not able to identify the enemy? I think the enemy has necessary components which is required for collision checks (attached a screenshot just in case), I think its a problem with the logic itself as console isnt giving any errors as well
I think i am really stupid (its working now)
What is the best multyplayer method for a 2d platformer? Where can I follow through the process of making my game multyplayer (tutorial, website)?
I want to learn unity by doing projects to projects while learning about coding and concepts on the way, can anyone recommend a good tutorial on youtube ? I tried Unity Learn but it doesn't suit me
It's also would be nice if someone can give me a list about what I should learn in each level , from beginner to intermediate to a job-ready unity developer
Thank you
Things to learn:
- learn to research and learn things in your own.
If following structures learning paths is not your thing, you've gonna learn to find answers to your own questions.
im looking at a tutorial in yt rn and after they save the changes to their code and go back to unity theres no reloading domain popup that shows in theirs, hows that possible?
You probably have autorefresh disabled. Hit Ctrl + R and see if it is triggered.
Depends on your goals. Local Multiplayer with split screen? There are some Tutorials out there. Otherwise you can look into different multiplayer libaries like Mirror, FishNet or paid ones
Hey all! If I know that the only three kinds of interactions i can have is Pickup, Grab and Inspect, is it reasonable to create an abstract 'InteractableObject` class, and have that three kind inherit from that?
I've heard interfaces are neat for interactables, but i found that it becomes a bunch of if statements if I need multiple kinds of interactables
you're using inheritance wrong if you're adding a bunch of if statements to deal with interfaces. the classes implementing the interface should mostly be the ones implementing the logic specific to that class
what's the difference between Pickup and Grab?
id go with an abstract class if you wanted to implement default functionality per item, or had values that had to exist on every item. either way you shouldnt have so many if statements to handle different logic here
Won't the workflow be to pick up and object and while it's being held, you can inspect the item?
Pickup would destroy the object and fire an event, hold is like how you hold the chairs in Amnesia, inspect just brings up some text
What you can do is have them all inherit the abstract class you brought up, and have an abstract function OnInteract().
You shouldn't be comparing the types of the classes
I know, that's why I'm asking about the thing being abstract. I had a script like so (for handling interaction with interfaces)
private void FixedUpdate() {
if (Physics.Raycast(_ray, out RaycastHit hit, rayDistance) {
if (hit.collider.TryGetComponent(out IInteractable component)) {
_interactableObject = component;
} else {
_interactableObject = null;
}
} else {
_interactableObject = null;
}
}
and you can't do things like _interactableObject.GetComponent<SomeClass> to figure out what kind of interactable it is to handle its specific case
figure out what kind of interactable it is to handle its specific case
you shouldnt need to. thats the whole point of interfaces
abstract classes dont really change that either. you shouldnt often be in a case where you need to figure out what the deriving class is
if you want an abstract class, it'd be because you want the child classes to
derive from monobehaviour
all have some default values
or all have some default functionality
the interface vs abstract class part here doesnt change how you call methods
well, I can't really do things like _interactableObject.gameObject if I'm using interfaces (from the example above)
or is there a way to do that?
Cause I'd much prefer to have an interface
yeah because you wouldn't have a guarantee of the thing actually being on a component
you can cast it to a component if you're sure its going to be one always. or use a property on the interface to store/do this for you
if you want that guarantee, then extend MonoBehaviour
it does seem odd to actually need to get the gameObject still
hm, I'll fiddle around a bit, to see if that's really necessary
Hi. I'm trying to get NetCode for GameObjects to work for a Multiplayer MVP Game.
For some reason, when I click "Start Host", a Player Prefab is loaded for the host and a camera is there, I can move around. When I click "Start Client" with a cloned project (ParrelSync), it just says "No cameras rendering" and doesn't work
any idea why?
I have added the Player Prefab to the DefaultNetworkPrefabs List, but didn't set it as the Default Player Prefab
Is this correct?
how to check if its enabled?
it is enabled
hello. i was trying to make it where the cube goes Right and Left by pressing A and D, but the unity system keeps giving me errors. if anyone could help me that would be great
did you read the error?
Either use the new input system (Input class is the old one), or change the input handling to Both or the old one
where is the new input system
It's a package, not sure if it's installed by default
Most tutorials use the old system though so might be easier to stick to that for now
does it depend on the version of unity i installed?
Unity 6 uses the new input system by default. You need to switch the input settings to Both in order to use the old and the new input system together . . .
how do i access the input settings
Read the error...
i find myself that trying to implement an AI framework for my NPCs is not the hardest, the hardest thing is trying to figure out what damn lines do what in unity.
like what does this even mean:
private static readonly Bounds Bounds = new(vector3.zero, new vector3);
It declares a new bounds variable. Have you done any C# courses?
That wouldn't compile?
Yep, couple of mistakes in there
yes, years ago. C# C++ C, Java. Can barely remember stuff outside inheritance
and uhh *
Check the pins of this channel for C# beginner courses
right, checking the playlist, i should be here. this is new to me
bout to crashout and just do spaghetti
I'm trying to use composition over inheritance in my latest project, I'm trying to get the hang of things but have got stuck on how I want to handle camera shake (using cinemachine), it feels like I'd need a singleton for a CameraShakeManager to handle update code so multiple shakes don't overlap and then to get a reference to the cinemachine noise component instead of dragging the reference in the inspector for every component, is this setup fine or should I be doing something different?
I usually make a Singleton for camera management
No reason to destroy main camera anyway with cinemachine
Adding shake requests to a centralised component is how we do it as well.
It feels okay but Singletons have blown up a previous project and I live in fear now
Hold on there was a great gdc video on shake
Singletons are great if used properly
I know but I'll need more experience using them right
In this 2016 GDC session, SMU Guildhall's Squirrel Eiserloh explores the math behind a variety of camera behaviors including framing techniques, types and characteristics of smoothed motion, camera shake, and dynamic split-screen.
Register for GDC: http://ubm.io/2gk5KTU
Join the GDC mailing list: http://www.gdconf.com/subscribe
Follow GDC on ...
I basically took the idea of adding trauma to the camera shake
So there is inly one shake and multiple sources add trauma
I mean you'll know the problems of singletons the more you use them, but until that point I'd just continue on with what you're doing
Sounds interesting...a little intense though
but cool, appreciate the info! I'll check out the vid
intense ?
without the context of what trauma means here it sounds odd lol
Sounds just about right. Something that start intense and then heals slowly over time
Watch the video itโs great
ohhhh, that is actually a smart term
Also this video is a must watch for extra juicy actions https://youtu.be/mr5xkf6zSzk?si=B7EP6lKkoXWIcuLb
In this 2015 GDC tutorial, SMU Guildhall's Squirrel Eiserloh takes a dive into the world of 1D nonlinear transformations to help game programmers make better games.
Register for GDC: http://ubm.io/2gk5KTU
Join the GDC mailing list: http://www.gdconf.com/subscribe
Follow GDC on Twitter: https://twitter.com/Official_GDC
GDC talks cover a ran...
i dont see anything called player settings
Google "unity player settings" and you should see an answer without even opening a link
oke
This should be the first thing you do anyway instead of relying on this discord server
okay but what do i do to fix the error?

Why is my SerialiseField Array variable not showing up in the inspector?
[SerializeField] List<Direction> links;
public List<Direction> connected;```
The other two show just fine.
Cant serialize interfaces
How do I work around that, then?
Depends, it's not that you can't serialize interfaces, but it requires some research. Or, there's a plugin for it if you want to look more into it:
https://github.com/mackysoft/Unity-SerializeReferenceExtensions?tab=readme-ov-file
If that's too much for you then I suggest just not using interfaces for serialization purposes unfortunately
Odin Inspector I believe has serialization for them
At least for this small thing I'm doing rn, this is a bit much, I'll just go without the Interface, then. I take it I just wanna have all the classes that implemented the Interface inherit from a (relatively sparse) Monobehaviour instead?
You can declare abstracted monos just fine, it's just that interfaces are a little too ambiguous to serialize
meaning you can insert different derived monos if you do declare as the abstractions
I see. I think I get it, thanks.
else if (!moving && turning)
{
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(randomDir, Vector3.up), Time.deltaTime * 0.25f);
}
This is in my Update(). How could I make this as such that the rotation time was fixed, so it could adapt to the random direction value?
first off, https://unity.huh.how/lerp/wrong-lerp
Applying lerp so that it produces smooth, imperfect movement towards a target value.
secondly, sounds like you'd want to use the right lerp for this
or perhaps compute an angular velocity and use RotateTowards
ah wait that changes the smoothing though
to have both smoothing and a fixed time... 
I know there's like DOTween but figured I could do this myself
i think you'd just have to do math if you want the exponential decay (similar behaviour to what you have now)
!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.
Interesting read, in my case I don't need anything accurate so the "wrong lerp" works fine here
sounds like you do want accuracy with regards to the fixed time though?
Hi, I was running this guys' project in Unity and it actually ran without doing any "Domain Compile" BS
https://www.youtube.com/watch?v=I1dAZuWurw4&t=219s
https://github.com/mixandjam/balatro-feel
How were they able to do this
hi im a beginner and i don't know which tutorial should i watch, which one do you recommend?
i'd just like to be able to make a simple first person system
pathways on !learn ๐
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
thanks!
once you learn the basic moving parts, any genre or gamestyle is irrelevant its all the same base knowledge
when you learn Lego you don't immediately try to make a replica of empire state building, you start with basic houses / structure
yeah, i'm just gonna make basic games then try to make it a bit harder
and i'll repeat until i get some knowledge
sounds good..yup.. just keep practicing what you learn and repetition makes knowledge build up.
in the beginning when learning don't know how many times i had to copy something like Physics.Raycast , from the docs / google until I kept writing it on my own eventually "it sticks"
ty
Please help, 'i' is class object with field material
what's the issue
looks like they're expecting the material supplied by i to be assigned to materials[0], but the name being printed to console is (presumably) the previous (but still current) material
this is the one function i still have to go and look at the overloads for
Note that like all arrays returned by Unity, this returns a copy of materials array. If you want to change some materials in it, get the value, change an entry and set materials back.
https://docs.unity3d.com/ScriptReference/Renderer-materials.html
wouldnt be so bad if there wasnt like 14 of em
thank you!
VisualStudio do this to anyone else?
When i create a new script I don't even have time to double click it or anything b/c Studio pops open..
that wouldn't be soo bad, but its always either showing the last script i was working on, or the Missing File page..
I can't even swap over to it in the Solution explorer..
i then need to click back into Unity.. let it Recompile.. and then finally can i double click it to open the desired file..
how do i mark it as legacy
not only that.. but its the (1) program that likes to tack its Tooltips on the screen
A quick tutorial on how to mark an animation as legacy
thanks
i did that but my animation still doesn't work
i had visual studio spam pop ups like those but it would say "Restore Up"... Could not find a fix online
Probably better to just not use the legacy Animation component and use the Animator instead
Because Blender and Unity have different coordinate systems
Unity does not use -X Forward
its z
still doesnt work
Unless you apply transforms none of them will even do anything
hello, i am having a problem in detecting a collision in my game, i have a waypoint with a void OnTriggerEnter2D(Collider2D other) function, it checks for the other objects tag to be PlayerCar "which it is" and it should output something in the console but it doesnt happen
doesnt work
Show code
show the code
do i just paste it as text here? or i need to write something
!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.
// This method is called when any car passes through a waypoint
void OnTriggerEnter2D(Collider2D other)
{
Debug.Log("Triggered by: " + other.tag); // Log the tag of the object that triggered the waypoint
if (other.CompareTag("PlayerCar")) // Ensure this matches the tag exactly
{
UnityEngine.Debug.Log("Car passed through waypoint");
GameObject Car = other.gameObject;
int currentWaypointIndex = carProgress.ContainsKey(Car) ? carProgress[Car] : 0;
// Check if car passed the current checkpoint (waypoint)
if (Vector2.Distance(Car.transform.position, waypoints[currentWaypointIndex].position) < 1f)
{
// Car passed the current waypoint, move to the next one
currentWaypointIndex++;
// If car completes the lap, reset to first waypoint
if (currentWaypointIndex >= waypoints.Length)
{
currentWaypointIndex = 0; // Reset to first waypoint
lapCount++;
Debug.Log("Lap " + lapCount + " complete!");
}
carProgress[Car] = currentWaypointIndex; // Update car progress
if (other.CompareTag("PlayerCar"))
{
Debug.Log("Car passed through waypoint");
// Change the car's color to green when it passes through a waypoint
SpriteRenderer carRenderer = other.GetComponent<SpriteRenderer>();
if (carRenderer != null)
{
carRenderer.color = Color.green;
}
// Reset the color after a short delay (optional)
StartCoroutine(ResetCarColor(other));
}
}
}
}
this is the waypoint, please dont hate the code :)
Do you get the "Triggered by" log?
i dont get anything in the console
Then this object never collides with anything
or its not set to be a trigger
i have a box collider on the waypoint and one on the car, the waypoints collider is set as trigger
The Three Commandments of OnTriggerEnter2D:
- Thou Shalt have a 2D Collider on each object
- Thou Shalt tick
isTriggeron at least one of them - Thou Shalt be moving via a 2D Rigidbody on at least one of them
both have a collider, trigger is right also and the car has a rigidbody which im steering it with
Still no clue why we use -z as the forward in the export
im very new still maybe i got something wrong
It's so Y can be Up in both 3D and 2D
Show the inspectors of both objects
Show the waypoint
Elaborating: Unity wants to work with the usual 2D plane of "X sideways, Y up", and it wants to maintain the same direction for gravity in both 2D and 3D. This means that Unity doesn't use Z-up like most 3D programs do. In an effort to make X "forward" in 2D and the same direction in 3D, it ends up making Z forward
Does the waypoint have the script that has OnTriggerEnter?
its the track manager which has the script
So what is the TrackManager's collider set to?
I don't think that trigger messages propagate upwards from child to parent except when the parent has a rigidbody maybe
So then the object with OnTriggerEnter2D on it does not have a collider and thus fails commandment one
okay thanks a lot, can i target the collider from the child somehow? i wanted to have a list where i put the waypoints and they are "scanned"
You would put the script with the OnTriggerEnter2D function on the object with the collider
Then have those waypoints report back to the parent object that they've been hit
thanks a lot :D
Why does the build fail even though there aren't any compile errors before hand? Errors flash in the console for a second or so and then disappear. One of the errors is to do with a certain script. I go to check that script and my VS Code shows no errors. Anyone have any idea how I can fix this?
The video didn't embed, but my guess is editor namespaces in the build. In your console, disable clear on build and recompile, then build it again and your errors should stick around
Thanks. It was a little error in my code that I wouldn't have noticed without seeing the errors lol
are events the most common way to communicate between different systems?
thatโs not answerable. They are certainly a popular way.
what are some alternatives
Method calls
would that involve passing around references to other systems throughout each system?
im trying to avoid that
you always need a reference, also for events
and an event should usually pass a reference to the event source along
Events are a pattern for decoupling code. If that is your goal, use them.
but events often make it more difficult to understand code flow and thus debugging will be more tedious
If you imagine a "system" as a heirarchy of classes or composition, is it a common approach to keep intersystem communication kind of at the top of the hierarchy, and then have all children within the heirarchy just interact with their respective root for any intersystem stuff?
Yes, that is a common architecture when things get complex. Communication through a โ-systemโ or โ-aggregatorโ or โ-mediatorโ of a subset/group of components
Sounds about right? I tend to write code similar to a supermarket or such, where thereโs different departments and a manager in each one
Beans manager ๐ซ
๐ตโ๐ซ
its tough, because what I need is essentially a singleton manager class for each system, but since Im doing multiplayer i cant have a singleton. Although i guess I could kinda have a singleton store where you input an id and it uses specific reference
Dont forget about interfaces as another way to "decouple" without using events
Use a service locator
Why canโt you have a singleton in multiplayer
One of the scripts for my previous game was actually named that
ill look that up, thanks
guys i have a problem with this thing i should be able to take the box from ground again but i can't any idea why?
this is the script
also the inspectors if needed
you cant use a singleton for any class in multiplayer that the server will need multiple instances of, even if it only needs one instance per player
Did you add a system to detect when you drop the box
i followed some tutorial from unity and got help from gpt so i dont know...
Then donโt give the server multiple instances? Might be my lack of server based multiplayer programming but the concept of singletons in p2p based ngo for example is nothing problematic
!learn
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
Start with the basics
its all fun and games until ai has no fucking idea how to fix some weird ass error ๐
learning yourself gives you the tools to fix problems
i did start with the basics actually
Then you should know what part of the script does what
well i mean theres nothing inherently wrong with singleton in multiplayer, it just that when your thinking about desiging from a players perspective, you might have a class that seemingly only needs to be made once, but from the servers perspective it needs to be made once for each player. Like a movement manager class is better designed per player
so i should watch all of these?
although i dont wanna make mobile and vr games?
Are you going to do VR or mobile AR development?
So yeah you wouldn't need to watch those
Do whatever is relevant to you
u should show the box Before you first pick it up and after u drop it..
you've only given us like half the puzzle pieces
!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.
sorry just wanted the pastebin website
how should i go along to fix this bug?
https://paste.mod.gg/cfbrqsjtrlfg/0
A tool for sharing your source code with the world!
I already know where the bug is located. just dont know how i could fix the scaling issue with the Canvas
its because i am calculationg based on Screen, i have no idea if this will bring issues but i think i need to fix it...
i recall doing something similar in 3D space.. but i was also relying on mouse position.. when i needed to use local UI position instead
pass ur MousePosition thru this method and see if it helps
ah i would need to use world space canvas then i guess?
cause i tried passing it and it just wont work?
u just need the Rect of the Canvas ur trying to map the mousePosition to
yeah thats how i was doing it
i will check tommorow
i have to go right now
thanks for help
Right so i've got a question, are there any circumstances where you can use the "new" keyword in a monobehaviour?
Because, in one unity project i have a script that does use the "new" keyword ( MyList.Add(new whatever(1, 2)) and unity gives me the "you are trying to create a monobehaviour using the "new" keyword. this is not allowed" message in the console. okay.. makes sense i guess.
But why does the exact same script (unless i'm missing something) Work in a different project with no errors? I'm so, so confused lol
Like, i've been messing with the first project using "new" in a monobehaviour script for a couple days now, and i've never seen that message until i created a new project and tried the same thing
No, you cannot create a MonoBehaviour with new
The different project either:
A) Isn't actually working
or B) Isn't a MonoBehaviour
you use new whenever you want to invoke the constructor of a C# object. You wouldn't use it to create the MonoBehaviour itself but you can and should use it in your code whenever you need to create a C# object via the constructor.
It works when whenever is NOT a MonoBehaviour
it doesn't work when whatever IS a MonoBehaviour
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Assets
{
[DefaultExecutionOrder(-700)]
public class PlayerData : MonoBehaviour
{
public int SkillPoints = 0;
public List<Skill> SkillsList = new List<Skill>();
private void Start()
{
SkillsList.Add(new Skill("Brewer", 1));
SkillsList.Add(new Skill("Drunkard", 9));
}
}
}
(hope that works)
Okay, show code for Skill
The issue is how is Skill defined?
Is Skill a MonoBehaviour or not
if it is, you shouldn't be doing this
if not, then it's fine
that's it
oooh, skill is not a monobehaviour
Which means it's fine to be created with new
๐คฏ sweet, thanks folks. This was frusterating XD
I would highly recommend creating these objects in the inspector instead of in your code.
Which you can do as long as Skill is marked with [Serializable]
And as long as its fields are public or have[SerializeField]
Trying to figure out why this doesn't work, feel like I'm at least close
// Start at 180 degree angle
private Vector3 toAngle = new Vector3(0f,180f,0f);
void ChangeSpawnerAngle()
{
// Once above 225 degrees, reverse rotation direction
if (transform.eulerAngles.y >= 225)
{
toAngle.y = 135f;
transform.eulerAngles = Vector3.Lerp(transform.rotation.eulerAngles, toAngle, Time.deltaTime);
}
// Once below 135 degrees, reverse rotation direction
else if (transform.eulerAngles.y <= 135)
{
toAngle.y = 225f;
transform.eulerAngles = Vector3.Lerp(transform.rotation.eulerAngles, toAngle, Time.deltaTime);
}
}
What are you trying to do
Make an object rotate back and forth
Is this called in Update or something?
Yes
There are several issues here
One - you're using Lerp completely incorrectly
Two - Using Euler Angles here is going to be a complete nightmare
What isn't working about it
Those are the main two issues
Currently it doesn't rotate at all

