#💻┃code-beginner
1 messages · Page 363 of 1
You spawn the prefab, not a scene instance
Prefabs do not exist in the scene
im spawning the prefab
Then it cannot disappear
Have you attatched any scripts in the prefabs that makes them disappear?
Again, prefabs are NOT IN THE SCENE
the error i get is: the object of type 'GameObject' has been destroyed but you are still trying to access it.
They are not in the hierarchy
They are in the project window
Show the thing you are spawning with a screenshot
GameObject newBalloon = Instantiate(balloonPrefab, spawnPosition, Quaternion.identity); takes me to this line of code when i click the error
Yes. Show me the thing you dragged into balloonPrefab
You likely dragged a scene object, NOT the prefab
Ok, that IS the prefab. Well, then are you calling Destroy(balloonPrefab) anywhere?
Can you show the actual error as a screenshot
uhh, it randomly started working again?
Well alright then. Haha. Good luck then
appreaciate it
Some things work with restarts of the editor for some reason, might be one of those
Yeah. If something didn't compile, a restart would force that.
Ctrl+r also does a recompile too
very sorry lol, how would i make the balloons gravity increase over time, so it goes up faster
well, decrease actually
You simply apply a specific value multipled by Time.deltaTime in Update
is there any difference in coding with VS and VS code? like for a beginner which one would be easier to grasp? (i know its the same code, i mean maybe the themes and shit like that might help)
VS is more popular for coding in C# and C++
yea i saw thats a bit more popular
I suppose, the majority would consider it much more comfortable
Also VS Code is not an IDE
I don't use the vast majority of features in VS, but found it easy enough to pick up and work in, as the integration is very good and you don't need to do anything other than Save All and jump back to Unity to test 99% of the time
why is it saying hit is wrong in the getcomponet?
mouse over it to get the reason why, it's probably because hit is unassigned
What is hit
you're missing a method that populates hit with data
you never give it a value
You're missing a physics raycast that populates your hit struct with actual data
okay thanks
Yo, can anyone help me brainstorm this please, I am making a hide and seek game where you can choose to be the hider or the seeker, the seeker can only see other players if they are in his fov, I am doing this using the URD (universal renderer data) by modifying the opaque and transparent layers and using the stencil effect.
Now for the question, how can I switch to be a hider and remove all the effects (because these are specific to the seeker). As of right know when I choose hider, I cannot see myself nor other hiders
right.
A) This is a code channel and this does not sound like a code question
B) Read what you have written and think if you knew nothing about your situation. Would you understand one single word you have written?
hey guys, I need a little help.
How to draw a class diagram for my game ?
Define Class diagram?
Like the UML Class Diagram ?
There's a Class Designer tool in VS, but that's outside the scope of this channel, and I've never used it
I'm working on my Thesis, a game project.
Idk if I have to put the class diagrams in there
That's the only tool I know of that might generate them for you. Otherwise you'd have to manually make them with the graphical tool of your choice
hey is it possible to activate the method of another game object on collision?
Which aspect are you having difficulties with?
check the collision methods or trigger methods (if you're not using rigidbodies)
i get an error when i try
What does the error say?
it's not public
thank you
if(collision.gameObject.TryGetComponent(out PlayerHealth playerHealth))
{
playerHealth.TakeDamage(1);
}```
I'm quite confused, what shoul i do?
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
Yes configure your ide. After that - read your error messages, you're not even looking at the right script.
Then click the link for "Installed via Unity Hub" and follow the rest of the instructions
I found a bug, where, when i click out of the screen, the game pauses, and it makes it much easier for the player to win this way as they can easily keep pausing the clicking on the balloon, how can i make it so that the game carries on no matter what
Problem: My Player is moving with the same Speed when i press "W" or "W" and "D" when i am touching a wall and pressing "W" and "D" at the same time i am moving to the right but with a slower speed (can someone help) ?
there's a checkbox in the project settings for this
let me find it
so in conclusion, player movement is fine unless you are touching a wall?
what is your desired behavior
not sure about getting errors while setting it up
I believe you want to turn on "Run in Background"
ah appreciate it
and pressing W and D or W and A
ah yes it works
i want to move the player with the same speed and not slower
when hitting a wall?
when hitting a wall and pressing both keys at the same time
well, its going to be slower, if youre moving diagonally to a wall
You'd have to project your motion vector on the surface normal of the wall, subtract that projection from your motion, calculate the magnitude of the removed bit and add it back to the projected vector
So you want to move at full speed, even though your movement vector is pointing into a wall?
yep, bingo
but how can i make it moving the same speed?
ur answer
i don't get it
Well yeah it's not beginner stuff.
anyone know how i can decrease gravity as time goes on for my sprite?
RIgidbody2D has a gravity scale property you can change
how would i implement that into the game though
You would write code that decreases the gravity scale as time goes on
The exact nature of that code depends heavily on how you want that to work
need to take track of the time thats been played and when it reaches a certain time the gravity decreases. Thats what i want it to do
or just gradually decreases
Tracking time is simple. Just use Time.time or make a timer yourself with float and Time.deltaTime
could you tell me how it would look correctly (you can see the code in the first message) ?
you are splitting your velocity into two parts:
- the part going straight into the wall
- the rest of it
you get rid of the first part
then you increase the length of the second part to compensate
If you were moving at 2m/s into the wall and 4m/s along the wall, you want to throw out the first half
and then move 6m/s along the wall instead
can anyone help me with the grid thing in unity please?
i was just wondering since the channel name is code beginner not engine beginner 😅
if your problem isn't a code problem, then ask it in another channel
like #💻┃unity-talk
ok
is there a way i could make it so its like when im holding a button down something is consinstently happening
GetButton
Wait then what’s the difference between Time.time and Time.realTimeSinceStart
read the documentation to find out!
Fair
For some reason this won't work, any idea?
worldSpaceCanvas.worldCamera = Camera.main;
what isn't working about that? is the worldCamera property still null after that line runs?
yes, the canvas won't take the camera, I also place it in Update but still won't work
Unity 2022.3.30
are you certain that code is running? do you have a camera in your scene tagged as the MainCamera?
This code is running on the same gameobject of the Canvas
{
private Canvas worldSpaceCanvas;
// Start is called before the first frame update
void Start()
{
worldSpaceCanvas = GetComponent<Canvas>();
if (worldSpaceCanvas = null )
{
Debug.LogError("AssignMainCameraToCanvasWS component on " + gameObject.transform.root.name + " requires a Canvas on the same object!");
}
worldSpaceCanvas.renderMode = RenderMode.WorldSpace;
worldSpaceCanvas.worldCamera = Camera.main;
}
}```
the fact that you have this line GameObject.FindGameObjectWithTag("GuiCamera") and are (allegedly) not receiving an exception that would prevent the latter lines from running indicates that your camera is not tagged as MainCamera
Thank you 🍻
so is it possible i could make it so inside an if statement when on collision with a specific object it stops being held
The answer to every "is it possible to" question is "yes, technically"
okay so how i would do that
inside an if statement apparently
You'd have to more clearly explain what you want to do. There's a lot of pronouns with no context. What is "it" and what do you mean by "stop being held"?
try to be more descriptive, and show relevant code with code questions. This is so vague it cannot be answered. What does it mean to be "held" in your game?
📃 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.
if (holding)
{
Rigidbody2D rb2d = heldObject.transform.GetComponent<Rigidbody2D>();
if (Input.GetMouseButton(0))
{
if (rb2d != null) heldObject.transform.position = mousePos;
if (rb2d != null) rb2d.AddForce((mousePos - heldObject.position) * 6f);
if (rb2d != null) rb2d.velocity = ((mousePos - heldObject.position) * heldObject.transform.GetComponent<Rigidbody2D>().mass);
}
you know you can put more than one statement inside an if statement, right? you don't need to check the same condition three times in a row
this is truly some code
yeah ima quickly do that
Your getmouse condition has all that inside, so you clearly know you can do multiple statements.
Oh, and the if (holding) condition
you've already cached the rb2d, you dont need to GetComponent it again at the end there too.
But also for your problem, you still need to describe more. "collision with a specific object", what is colliding with what? The only thing i can suggest from this is using OnCollisionEnter2D and then possibly checking a layer, tag, or if some script is on the other object collided with
no idea why, but since migrating to a new kinematic system my scientist character remains suspended in the air when everyone else experiences gravity normally. combed through the entire class and was unsure about what caused this, as the scientist inherits the character class
you will need to review what is different about the scientist compared to your other characters. that information is not enough for anyone not intimately familiar with your project to have any idea what could have caused it
yeah i understand that, i've been trying to dismantle everything lmao but dismantling the components either disables movement completely or changes nothing so its been tough 😅
i tried adding a debug log to print the value of my movement vector every time its set, but the stack trace just shows things working as intended
Can someone help me understand why this code isnt working?
using UnityEngine;
public class Handle : MonoBehaviour
{
[SerializeField] private Collider triggerCollider;
[SerializeField] private GameObject guardToUnhide;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Guard"))
{
guardToUnhide.SetActive(true);
}
}
}
when a gameobject with the guard tag enters the trigger colider nothing happens
ohh thankss
Hi I wanted to make a game where normal game objects shoot bullets that are entities, is that possible?
sure, why not?
Doesn’t it use two different physics systems?
whats "it"? you havent specified anything
if its 2d use a Rigidbody2D, if 3d use a Rigidbody
i dont really understand?
3d uses PhysX, and 2d uses Box2D
but both are integrated into Unity.. just gotta select the appropriate components (3D) or (3D) and Physics. or Physics2D.
Assuming you're talking about ECS, yes, it's separate from the gameObjects physics. You'd need to decide which system to use for your physics.
oh yes..
Ecs has one physics system and normal game objects have another. Is there a way to translate them?
So either I do it with ecs or normal game objects?
The physics, yes. But that doesn't prevent you from mixing other systems, like rendering.
For example, if you decided to use the GameObject physics, you could have an rb + collider for your bullets and have an entity with rendering related components sync position with the rb.
Or the other way around, you could have all the physics handled by ECS and sync GameObjects with it for the rendering.
You could also handle only the bullets by ECS entirely and other stuff by gameObjects physics. You'd need to create ECS colliders for your other objects that you want the bullets to hit and sync them with the GameObject counterpart.
Ok I’ll look into that thanks!!
Vector2 keys
private void Update()
{
keys = new Vector2(Input.GetAxis("Horizontal"), rb.velocity.y);
}
private void FixedUpdate()
{
rb.MovePosition(rb.position + keys * Time.fixedDeltaTime);
}
does anybody know how to make the gravity now slow?
use .velocity or AddForce
MovePosition isnt good
any insight on why this NavMeshSurfaceEditor returns this error?
private void FixedUpdate()
{
rb.velocity = new Vector2(keys, rb.velocity.y);
}
yo im back
it works good but is there any way to make it where it doenst stick to walls?
method is null
it you walk in a wall you will just stick to it
i mean
what else do you want it to do?
frictionless physics material
are you, or someone, familiar with NavMeshPlus? This method legit doesn't exist, so not sure what to do
uh great advice sir, mb
maybe have a second parent with the same properties, scale the 2nd parent, and then move the children, then turn off the 1st parent. That's about all I can think of, I don't think there's a way to exclude children from scaling, I could be wrong tho
@tawdry arch
you could group those children, to make moving to the 2nd parent easier
I am having trouble linking up my UI components to this script, anyone know why?\
you're likely using the Text Mesh Pro UI objects rather than the legacy objects.
use TMP_Text and TMP_InputField for the variable types
in here right?
yes. you also need to get your !IDE configured
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
now im getting this error
genius! thank you

Still having trouble connecting the last element lol
Show the inspector for the object you are dragging in
again, get your !IDE configured because these issues can be solved using the quick actions
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
use TMP_Text for the Chat Log
Thanks everybody it looks like my WebSocket client is connecting!
hopefully you configured your IDE as well during this. its really the most important thing you can do to make your future coding easier
if he's knew, I doubt he knows what IDE even means
the Bot message kinda makes it obvious
doesnt matter, its a rule to have it configured for help here. they can ask or google what an IDE is
I know what IDE means lol, I am using Visual Studio, but I don't know how to configure it
^ i was gonna say, if u dont wanna get tired of hearing it everytime u post a question you'll just get'r done regardless ;D
I think it is configured now?
if you wanna verify, comment out "using.TMPro", and if your visual studio yells at you and makes a suggestion for "TMP_Text", it's working fine
Yes it does lol
im setting up running and jumping animations for my character on 2d unity, and when i call the methods that run the animation within my player mvmnt script, it just breaks and says "object reference not set to an instance of an object."
Next time provide the code that throws the error and the error details.
Do you need to enable rich text for TMP_TEXT?
Is that a quiz?
You enable it if you need rich text features. I don't get the question
no, you dont.. that just enables rich text
allowing u to use tags.. like <b> For Bold </b>
etc
so this is running in my player movement script:
_playerAnim.Jump(true);
and the class looks like this:
public void Jump(bool jumping)
{
_anim.SetBool("Jumping", jumping);
}
this is my error 🥲 :
NullReferenceException: Object reference not set to an instance of an object
PlayerMovement.FixedUpdate () (at Assets/Scripts/PlayerMovement.cs:56)
!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.
ur animator is not assigned correctly
wel actually... ur using _playerAnim and _anim
which one is it?
Looks like by default it is enabled, thanks bros
playerAnim is reassigned as the PlayerAnimation script at the top of my movement script.
player animation is where the second chunk of code is from
Try following the link that boxfriend shared first. There are followup links there as well. Show us that you put some effort into debugging.
thats syntax for the Animator component.. not a script.. 🤔
ohh i see.. well anyway.. NullReferenceException.. just means its trying to access something that's not assigned.. or is null.. (doesn't exist)
by the second bit of code i meant the jump method
i can declare an AudioSource called aSrc.. and can call aSrc.Play(); but if its not assigned toa particular audiosource it isnt gonna do anything
the two pieces of code i sent are from two different files
yeah i get what you mean
Either _playerAnim or _anim are not referenced properly. And thus null. What is line 56 of script PlayerMovement?
like 56 was my call, so _playerAnim.Move(1);
Then _playerAnim is null
@rocky canyon is right. its something with my method in the other file
Where do you assign the reference to it?
but im not rlly sure how to properly run the animation that i have set for "Jumping"
i was following a tutorial
This looks like the error is coming from the inspector, not necessarily the code it's self but we won't be able to be sure unless you share your code with us, but 1st check your inspector and just make sure everything is assigned properly.
also when I say inspector, I just mean, you're reference is not assigned
mb
sry i’m not disappeared im still looking for help just away from my pc
thank u everyone for helping sm 😓
You create animator with your clips
- then you create parameters you want to change to control the animator
- then you set up transitions.. -> those will have conditions that need to be met to transition from clip to clip
- then you reference the
animatorcomponent... and use functions likeanimReference.SetBool("isJumping", true);etc
how should i upload my code so it can be accessed easier
click on one of these links
someone posted a bot message right after you posted ur code..
// remove diagonal movement
if (input.x != 0)
input.y = 0;
if (input.y !=0)
input.x = 0;
How come for removing diagonal movement in my character it works great with input.x !=0 but not the other way around with input.y !=0
playermovement
player animation
Debug it.🤷♂️
Is PlayerAnimation on the same object as PlayerMovement?
b/c ur saying if input x is not 0 make input y 0.. then u ask if input y is ! =0.. (which it will never be zero.. if input x was not 0) because u just set it to 0
yeah okay i have all that set up
Generally/often the animation would be on the child, so just checking
Assuming you're following a tutorial, double check that your scene/inspector setup is exactly as in the tutorial.
This part is not relevant.
hold up i dont need to assign the player animation script to any object right
It is specifically _playerAnim in PlayerMovement, as the error said
What?
because im only using it to be accessed in my movement script that is assigned to my player
check with the tutorial
the tutorial was a randomly placed video in the middle of someones game with no extra background. thats why im looking for help here
You are calling GetComponent for it, which is why I asked this. Please answer
#💻┃code-beginner message
yes. sorry.
No, the object
im so confused
Is the component on the same object
Show the inspector for the object that PlayerMovement is on
when u use GetComponent its searching the same gameobject ur searching from..
okay yes
Don't crop it
so if the component is somewhere else.. it wont be found
i dont see the PlayerAnimation script on there anywhere tho...
So playerAnimation is NOT on the same object
this isnt gonna work.. b/c ur playeranimation script isn't on the same gameobject
What's causing my code to throw an Object reference not set to an instance of an object error?
void Update()
{
input.x = Input.GetAxisRaw("Horizontal");
input.y = Input.GetAxisRaw("Vertical");
// remove diagonal movement
if (input.x != 0)
input.y = 0;
if (input != Vector2.zero)
{
animator.SetFloat("moveX", input.x);
animator.SetFloat("moveY", input.y);
}
movement = new Vector2(input.x, input.y);
}
I have the animator attached to the player object and an animator controller set too. Am I missing something?
where do you assign the animator variable?
oh fuck
also i feel like we just went through this same thing with the rigidbody
so i need to assign the playeranimation script to the animator component on my player on the inspector thing right
We did lol
yeah so you should know what to do then
which line exactly? the error means a value is not assigned to a reference variable . . .
wait no
No
this is what happens when im jus trying to jump into it without knowing what half of this code means
The component needs to be actually attached to the same object as PlayerMovement
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
if ur using GetComponent.. it should be on the same gameobject... to find it..
if u have a public or a [SerializedField] private reference.. it could be anywhere.. as long as u drag in the reference..
Do this before doing anything on youtube
it just depends on ur setup
Got it working, thank you so much everyone
make sure your animator, movement script, and your playerAnimation script are on the same object
Spawn is right
okay so first thing is what do you mean by a component. because right now its in my code and i dont really know what it means
I've said several times already, but this issue is simply you not following the tutorial properly. Rewatch the tutorial from the start and make sure that everything in your project is exactly as in the tutorial.
^ this would be the easiest.. as a beginner.. to make sure everythings together.. would cause lot less headache's trying to reference different things all over the place
until you get a grasp on why things work the way they do.. don't put objects on different places, just follow the tutorial 1:1
you may have missed a step also, not sure entirely
so im not sure where i should put my playeranimation script then.
is there anywhere in the animator that i can assign it to
on the same object as your movement script
thats an Animator ^ its not the same thing as ur playerAnimation script
which is what confused me at first
yea lol confused both of us
thats this
https://youtu.be/qdnoOlTxhng?si=pvwjvjxbJaYeYG3Z
this is my yt tutorial and there is no background context on anything going on in anything else on this guys code other than just the two scripts he opens
Want to work in the Games Industry?:
https://tinyurl.com/corgames
Cor Games Instagram:
https://www.instagram.com/cor.games/
im trying
what u just screenshotted would be private/public Animator animatorName;
OHHH
https://gdl.space/enicariwel.cpp this script, put it onto your character next to this script https://gdl.space/oxeqotadit.cs
weird naming tbh
im genuinely an idiot im so sorry
PlayerAnimationController.cs woulda confused me alot less ;D
no, I've made that mistake also, same with many others, you're not an idiot, you're learning, there's a difference
i dont know why i was thinking i needed to drag the script into a little box thing. i forgot i can just add it as part of the object. thats why i didnt know what u guys meant
okay great so now player animation is assigned to my player object
AYEEE
okay that was a really stupid mistake by me thank u guys for being patient
I can't watch that video now, but if it doesn't show you what components go where, this is not a suitable tutorial for your level.
as long as ur Player Animation has the animator referenced correctly that should be good 👍 as long as ur playeranimation script is referenced correctly..
if its on the same gameobject now. the GetComponent should find it no problem
I do think you should stop that tutorial, and go do !learn btw
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
yeah i see what was going wrong now. i cant lie a lot of the terminology was kinda going over my head bcs this is all new to me as of the past two days.
you can always debug references too..
Debug.Log(theReference);
and it will spit out in the console.. what gameobject it has assigned
im done with that aspect of my code. im just gonna start trying to follow that then thank you
its not great trying to like cut and paste pieces of other ppls games and im seeing that now
nothing was integrated properly
and the guy was doing a bunch of stuff super weird
It's a natural thing to try, but skipping a strong foundation makes it a slow path
right now im just trying to get a basic layout down just to introduce myself for hs ISU
^ once u understand how things work.. its alot easier to copy and paste parts that you need but u have to know how to integrate them into your code..
and know what changes to make to make it work
just dipping my feet in. but i really should learn
b/c everyone copy and pastes..
no one types out a simple mechanic that has been documented/ and written 1000 times before
true true true
BUT.. gotta get that context 🙂
and right now the integration process is where im finding out which things i gotta learn i guess
debugging is a Valuable skill
i can't even stress how valueable it is
but it comes with experience
just keep trying and failing 👍
well big take-a-way from this one would be... the script name.. and the line-number..
if theres two numbers its the character number and then the line number
its the errors w/o any script name thats the hard ones lol
lol
yeah
see when i saw the error with that line
i thought that it wasnt working because when i called the method something inside the method was brekaing
you should be able to double-click most errors.. and it will open the script and go right to the line its on
just a tip
would that have shown me a different kind of error then
or would it have still kinda just been generic about it being that line of code
if u click the error on the bottom box theres a thing called a stack-trace
that will show u the order..
so if it calls another script.. it will show that too
ahhh
this script->
that script->
etc
okay interesting
thank you
and thats all just with the error tracking on unity?
or are u talking about vs
thats the console in Unity
neat
theres a different debugging process for inside the IDE
which is alot better.. but most people dont learn that until later on
cuz its a bit more involved
you can set break-points where the code i will stop.. and then it will wait for u to tell it to step-through it
and u can follow how the code is being called.. 1 step at a time (and it will tell u what values the functions are getting, and returning, and all that jazz)
ive seen that before
havent really made use of it much yet though
me neither..
only really was useful for me when i was trying to do an assignment in assembly
assembler...?
whatever its called
nah im talking about a whole other language
ohh assembly yea
oh i didnt see that
thats hella useful (eventually)
yeap!
seeing all the values and stuff is rlly nice i didnt know u could do that
@rocky canyon is there a way to speed up my jump animation depending on scale of my jump do you think
bcs right now the animation just runs through regardless of how high i jump... so i jump on the ground lol
Runtime debugging with the ide is good if you need to know the state of certain instances at specific moments. Logging to the console or a file is good if you don't have a specific instance (or know of the specific instance) that you're wanting to fixate on.
or should i separate my animations into an up animation and a down animation
and then base it off of my velocity
u'd probably control that in code.. or something
if you jump-> and you've reached so high off the ground -> then call the jump animation
theres also a thing called BlendTree's
im afraid of logging to a file 🥲
that does stuff for u automatically.. u give it abunch of clips.. and it'll transition between those clips depending on the values u pass..
is t.gameObject.GetComponent<TextMeshProUGUI>().text or t.GetComponent<TextMeshProUGUI>().text better? where t is a Transform in array of Transforms
oh wait nvm it doesnt work
i use firs one
No reason to add extra unnecessary steps
Second one is simpler and therefore better
thank
Also - cache your references if possible
can't use certain types as parameters for a button?
the type is a class it is asking for
you mean the type?
yea what are you trying to pass
with the inspector?
you need a custom unity event . . .
yes
alright
anyone know how i would change this to use a layermask
private void OnCollisionEnter2D(Collision2D collision)
{
if (isAttacking)
{
if (collision.gameObject.tag == "Enemy")
{
Debug.Log("Hit Enemy");
}
}
}
create a LayerMask variable to check against. access and convert the GameObject layer to check with . . .
yeah what code would i use to check if the gameobjects layer is in that layermask
oh, that part you can easily google . . .
if (collision.gameObject.layer == enemyLayer)
like this
this checks the actual GameObject layer (from Tags and Layers manager), not a layer mask . . .
im a little confused with all this
if ((mask & (1 << layer)) != 0)
{
// mask contains layer.
}
would that be the part that explains it
mask would be layer number and layer is your Layermask
no sorry other way around
and how would i find layer number
if ((enemyLayer & (1 << collision.gameObject.layer)) != 0)
{
// mask contains layer.
}
so this?
enemyLayer.value
layermasks and bitmasks 👀 gives mes anxiety just spectating 🤣
i mean, let's give it a go and find out . . .
as a enemeyLayer is not a int you get type conversion error
cool it works
thanks
also would there be a type of variable that holds 2 numbers?
or should i just make 2 floats
tuple
Vector2?
even better ^
Class or struct with two variables
Quite a few ways to do it
keep 'em coming . . .
the possibilities
I've noticed some rigidbody FPS character controller scripts update the camera's position in the update function, rather than just attaching the camera to the player or the player's head. Since the player's head is always a satisfactory position for the camera and they aren't doing any camera smoothing, I'm curious why they keep the camera separate and use a script to update its position instead of just attaching it. Is there a specific reason for this? If so, wouldn't it be better to use LateUpdate to update it's position?
rigidbody movement isn't always smooth if ur looking thru the FOV of the RB
it only updates 50 frames a second
depends on the usecase, both are valid
you would have to ask the authors of the scripts. I can imagine they do it for various different reasons. Maybe they want to move it elsewhere at other times, or maybe they want to do cemar shake or something
LateUpdate is most likely better, but it depends on how the player moves
whats the best way to do chances so like a 1 in 100 chance for x to happen is it just if random.range equals 1?
if (UnityEngine.Random.Range(whitefuryminimumchance, whitefurymaximumchance + 1) == 1)
{
}
so like this
or is there a better way of doing this
Random.value < 0.01f
fury?
It was simple scripts where the only camera movement function was void Update() { transform.position = cameraPosition.position; }, so i dont understand why not just have it attached?
how can you read those variable names? camelCase those . . .
Maybe whoever wrote it just wasn't very good at Unity
yeah i cant rn i just wrote them quickly im changing them in a second
so the 0.01f is the chance right
yes
cool thanks i no longer need 2 variables
if (Random.Range(0f, 1f) < 0.5f){ }``` is 50 precent chance
just a guess. sp,e smoothness to it probably instead of being instant glued on the player
its gonna be a move
Random.value does the same as that Range call
oof, i always forget about .value
.value 0-1
it will have like a 1 in 10000 chance of happening but will make you do insane damage and will have a really cool effect i hope
protip
easier to use Random.value < 0.5f . . .
yup yup.. im jotting that down in my notes rn
yeah didnt know random.value was a thing i always did the random.range
Hey all I am having a confusing issue I am making one gameobject the child of another. I then change the local position and rotation to 0 which in theory should match the parents. The parents position and rotation are all 0. however when I do this in code, the position of the gameobject is 0 however, the rotation is (x -180, y 180, z 180)
' _currentEquipped.Equip();
_currentEquipped.transform.SetParent(equipmentSlot);
_currentEquipped.transform.localPosition = Vector3.zero;
_currentEquipped.transform.localRotation = Quaternion.identity;
'
random class has a few interesting ones
the euler angles (x -180, y 180, z 180) are equivalent to (0, 0, 0)
that's the fun part about euler angles, they're not unique
yes it seems that way, why does it do this?
depends what you mean by "it"
where are you seeing that
sorry, why does it make it all 180 instead of 0?
Again, what do you mean by "it", and where are you seeing that?
the gameobject, which is referenced as _currentEquipped
where are you seeing that
the inspector?
In a log statement?
the answer to that is that as i was having so much issues with the rotation i seperated them to see what the issue was.
this is why quaternions are used..
euler angles can have some quirks about it
in the inspector
many different values can be the exact same rotation when using eulers
my guess is you have some weird scaling or rotation or something in your hierarchy
hmmm, I checked every parent and they all scale as 1
could a child have impact on it?
just euler angles being euler angles. This is why you don't rely on them
I used quaternion.identity to change it
(-180, 180, 180)
(180, 0, 180)
(0, -180, 180)
(360, 0, 0)```
yeah but you're reading euler angles
oh you mean in the inspector?
yes
while (true)
{
if (counter < 1)
{
float tempY = warpObject.transform.localPosition.y;
tempY = Mathf.Lerp(tempY, 0.5f, counter);
warpObject.transform.localPosition = new Vector3(warpObject.transform.localPosition.x, tempY, 0);
counter += 0.02f;
}```
im on my last step for optimizing certain animation, as u see its a lerp animation but its inside a coroutine
the only problem left is this lerping will finish in one frame, which its supposed to be at least 50 frames , and im trying to avoid doing it on updates/fixedupdates
aight looks like i gonna try fixedupdates first
I dont see a yield/wait here so yeah it will finish instantly
If you waited a frame in the while loop then it would happen over time
Yeah where's the yield??
IEnumerator test(GameObject warpObject){
while (true)
{
if (counter < 1)
{
float tempY = warpObject.transform.localPosition.y;
tempY = Mathf.Lerp(tempY, 0.5f, counter);
warpObject.transform.localPosition = new Vector3(warpObject.transform.localPosition.x, tempY, 0);
counter += 0.02f;
}
else
{
//commented stuffs
}
yield return null;
}
}```
this won't finish instantly unless counter starts out at 1 or close to it
and why are you specifically adding 0.02f to counter? if you're increasing the value realistically, you should use deltaTime . . .
Use Debug.Log to see what's going on
oh 💩 let me fix it ty 👍
If counter is a class variable then it probably is already at 1+ when you run this the second time
Unless you reset it to 0 somewhere
Yo does anybody know what the correct variable name for a cinemachine camera (2d)?
wdym by "cinemachine camera"?
You mean virtual camera?
yeah
CinemachineVirtualCamera
!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.
IEnumerator test(GameObject warpObject)
{
warpObject.transform.localPosition = new Vector3(warpObject.transform.localPosition.x, 0, 0);
warpObject.GetComponent<MegaBendWarp>().axis = MegaAxis.Z;
warpObject.GetComponent<MegaBendWarp>().from = -0.5f;
warpObject.GetComponent<MegaBendWarp>().to = 0;
float counter = 0;
while (true)
{
if (counter <= 1)
{
float tempY = warpObject.transform.localPosition.y;
tempY = Mathf.Lerp(tempY, 0.5f, counter);
warpObject.transform.localPosition = new Vector3(warpObject.transform.localPosition.x, tempY, 0);
counter += Time.deltaTime;
}
yield return null;
dw it does reset
@verbal dome
cache those references . . .
hello, I have a state machine built and i found that the PlantSeedState's UpdateState function is not getting called, I think the problem lies with going two levels deep into a substate. So the Superstate runs its Update function, the substate runs its update function, but its substate does not. Is there something im missing in this code? https://gdl.space/yutopidaka.cs
- What's a substate?
- Where does the machine ever get set up with a PlantSeedState as the substate?
The only time I see substates getting set is here:
public override void InitializeSubState()
{
if (Ctx.IsYoung)
{
SetSubState(Factory.Young());
}
else
{
SetSubState(Factory.Adult());
}
}```
so the super state, in this case the Alive state, will initialize the substate Young, and that should initialize another substate further called Seed. Everything works up until the update function in Seed
im able to get all the way into the Enter function in the Seed state.
but it works for young and alive, so its like i didnt reach far enough down lol
IEnumerator Test(MegaBendWarp warpObject)```
No it's because AliveState has this:
public override void UpdateState()
{
CheckSwitchStates();
Debug.Log("AliveState");
}```
iot's not updating its substate
young is its substate and its running okay, are u meaning the seed state?
public override void InitializeSubState()
{
if (Ctx.IsSeed)
{
SwitchState(Factory.Seed());
}
else if (Ctx.IsCutting)
{
SwitchState(Factory.Cutting());
}
else if (Ctx.IsSprout)
{
SwitchState(Factory.Sprout());
}
}```
Is this supposed to be calling `SetSubState()` instead of `SwitchState`?
This is in PlantYoungState
I just don't think you actually set the substate to Seed because of this^
😮 Ohh my goodness
let me test it before i hug you
hollyyy crap it workedd, i have been staring at it for about 2 days working around this problem. Thankyou goodsir
https://docs.unity3d.com/ScriptReference/Plane.Raycast.html
can someone help me explain a plane raycast a little more. I read it and tried the script, but im still not 100% on whats going on
also
what does the " float enter = 0.0f; " mean in this test script?
It finds the interesection of a ray and a plane
As per the docs you linked:
This function sets enter to the distance along the ray, where it intersects the plane.
now its not running through the Enter function of the Seed state lolll, its doing weird stuff now, its better tho XD
becasue you're never entering the seed state
i see it was orginally called in the switch state method, would i just need to add it to the intializeSubstatemethod too?
god dammit i figured out the problem
Why can I only move the object along the x and y axis?
float counter = 0;
while (true && counter <= 1)```
if 1 is an integer, will it pollute counter and turn it into int as well?
I have no idea what you mean by that
counter will always be float
you declared it as float
variables cannot change types in C#
ok then i must debug
because
while(true){
.....stuffs
yield return null;
}``` should make the coroutine having update like feature
https://docs.unity3d.com/ScriptReference/Plane.Raycast.html
im still testing this script, but it says " the plane is set to the Camera's x and y position ". Im guessing this is why I can only move the object along the x and y axis, but where in the script does it establish that
it establishes that here when it creates the Plane:
m_Plane = new Plane(Vector3.forward, m_DistanceFromCamera);```
Since it's using Vector3.forward as the Plane's normal vector, that's the X/Y plane.
If you look at this picture again, the thing in the top left is the normal vector for the plane. If you think about Vector3.forward being the normal vector, it's plain 😉 to see that the Plane will be the X/Y plane.
I got it working, i had to do the same thing with the update state to call EnterStates instead
Ok it's been a hot minute since I've touched an old project let alone use C# but I'm trying to make it so I deceleration slower if I'm above my top speed as to keep some of that momentum.
Feel like I'm missing a very obvious fix and syntax error.
you forgot the f in 0.2f
LMAO
also if (velocity.x) doesn't make sense 2 lines before that
also Your IDE is not configured
you need to configure it
!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
We don't know what line is 483 and 485
Definitely get it configured though to prevent minor errors.
483 is the velocity.x || velocity.y argument.
And could have sworn I got it configured but guess not? I'll get on that.
If you had, it would be underlining your errors in red
Nice.
Wow the whole time I thought I'd just have to figure it out and deal with it lmao.
another question, I have a script to shoot a raycast and hit a object. When it does, itll print the name of the object which works, but how would I acces the object, would I use " GetComponent<GameObject>(). "?
What would you be calling GetComponent on?
And GameObject is NOT a component
okay
Ok, remembered magnitude exists and is a far better arguement. It's configured for Unity now too.
coolio
ty!
It doesn't look like it is? 🤔
Took the screenshot like 5 minutes before and was testing if it works.
It's installed trust.
You don't need to reinstall Visual Studio but simply run and modify it. Make sure the workloads section is checked. External editor stuff, regenerate project and reboot the Unity Editor.
My goal is to disable the animation when the player collides with the wall to prevent the animation from continuously walking. Any thoughts on where I'm going wrong?
https://gdl.space/ahisawivus.cs
what's happening that differs from your expectaation?
The character is continuing to move
Do you have a Rigidbody? Your code is using Transform based motion
Yup I have a RigidBody2D
Well, lines 57 or 61 will overwrite whatever happens on lin 36
so line 36 is basically pointless as-is
Oh I see
In the original Pokemon is walking animation disabled when they hit a wall?
ok , the coroutine is good , the problem is a function call after the coroutine messed up the lerp animation💩
really sad
and it wasted 3 hrs
Hello, does StopAllCoroutines stop the coroutine immediately or after the next frame?
By the time you can run StopAllCoroutines, all of your running coroutines will be waiting at a yield statement. After calling it, they simply will not continue.
I understand that but what I mean is if I call StopAllCoroutines inside a coroutine, and call a function in the next line.
Will that function be called?
Yes it will
Oh that's neet
It simply won't continue after its next yield statement
I see, thanks!
The only things that can affect the actual line-by-line flow of C# code are C# control statements
i.e. return break yield if while etc...
Barring such things, code will run immediately, line by line, in order.
Ooo that's so good to know, thank you again!
PB is nearing 300k messages here now 

Hey, I had a quick question about Mathf.Lerp. If I have Mathf.Lerp(a,b,t) where t > 1, will it result in a number outside the bounds of a and b, or will it take a and b as min, max values?
Do they have the most messages on this server?
afaik
Thanks! And is there a way to linearly interpolate beyond a and b if t exceeds 0 or 1
Where it doesnt give a or b as min/max
Mathf.Lerp simply clamps the value between 0 and 1, so, I suppose, you'll have to implement your own version
by using an ease function for t . . .
Thanks!
hi guys im trying to move a prefab game object to another game objects transform. The script is attached to the prefab game object. What am I doing wrong here 
You're simply creating a new Vector2 struct
unfortunately, this doesn't assign a position to anything . . .
Moving a prefab to another GameObject's transform means assign the prefab's transform.position
So the created Vector2 has to be assigned to it
you need to assign the position of one GameObject to the position of another GameObject or Vector2/3 . . .
Also, make sure you don't Find the GameObject twice. The GameObject's position can also be assigned directly.
yourPrefab.transform.position = GameObject.Find("PlayerSlots").transform.position;
If the z axis is relevant, the (Vector2) cast should be used
yourPrefab.transform.position = (Vector2)GameObject
.Find("PlayerSlots").transform.position;
thank u guys for the info 
If z position isn't supposed to be 0, assign it this way
Vector2 newPos = GameObject.Find("PlayerSlots").transform.position
yourPrefab.transform.position = new(newPos.x, newPos.y, zPos);
Also make sure you know about the disadvantages of the GameObject.Find method
thank you, its in 2D so no z axis needed 
Regardless of it being 2D or not, the z axis always plays a huge role
i didnt know that o:
Well, do you know about the role of the z axis in 2D games?
no o:
The z position in 2D games plays a huge role when displaying the objects.
If the camera's z position is 0 and it's facing the direction forward, then the objects in a specific distance, which have a larger position e.g. 1, 10, 20 will be displayed correctly. The object, which is nearer to the camera will be displayed above the farther one. This way, if the camera's position is 0, the object with the position 1 is on top of the one with position 2, as 1 - 0 < 2 - 0.
If you have an object with the z position smaller than the camera's, and the camera is still facing the direction forward, the camera will simply not see this object, as it's not in its range of view.
oooh so it affects the layering
Yes
there really is no "2D"; as from the scene view, everything is in 3D. it's just the illusion of 2D. physics and movement are applied on a different axis. it's all a LIE!

the z-axis is used for layering . . .
alright i made this
test it out . . .
it works!!!!
Yeah, so you can see the 3D view when pressing the 2D button at the top-right corner of the Scene window
this. and gameObject. are both redundant and can be removed
now, you can simplify it. this is redundant. no need to access gameObject because you already have access to transform . . .
i would use GameObject.Find in a different method to store the PlayerSlots GameObject. this avoids using Find every time you want to move the card . . .
thisis just needed when referencing the global value instead of the local one, or when deriving from an overload- The
MonoBehavioursare derived fromComponent, and can thus access theComponent.transformproperty
For the game I'm making, the card is only moved between 2 positions
It doesn't matter, Find can still be quite costly
definitely not me googling everything you just wrote 
Either call it once, or assign the desired object in the Inspector
it's still best to store the reference and use the reference instead. Try to avoid using Find methods, if or as little as possible . . .
i tried assigning it in the inspector, but I can't assign a prefab to another prefab? it won't allow it..
public bool value = false;
public void MyMethod(bool value)
{
this.value = value;
}
In this case, this.value is the global one, and value is the method's 1st parameter
You can
Prefabs cannot just reference the objects from the scene
They can reference each other though
It's a good thing to google when you come across something new.

I'm assuming you've instead got something in the scene and a prefab not in the scene.
haha. they just mean that Monobehaviour derives from the Component class, which has the gameObject and transform property. you can access either of them straight from your MonoBehaviour script . . .
the game object in the hierarchy is also a prefab, but the thing im assigning it to is not a prefab in the hierarchy
I wonder whether it made it even more complicated for them
no, i understand now
Prefabs generally refer to things not in the scene (prefab assets).
https://docs.unity3d.com/Manual/Prefabs.html
basically, monobehaviour has already defined "gameObject" and "transform" for you, so you dont have to do that
is that right?
Component does
@unkempt carbon yeah, i hit enter before finishing the second part. if they need access to the position (or a member of the Transform class), it's better—and more efficient—to use transform instead of gameObject.transform . . .
MonoBehaviour : Behaviour
Behaviour : Component
Component : Object
Component.transform & Component.gameObject
As you can see, both properties from from Component
the same applies for gameObject if you need access to any of the GameObject members . . .
MonoBehaviour is derived from Component, so can access them both
how to make linear motion for the playable character like with out momentum and acceleration pressing the button moves the playable character from a to b linearly
Try the Character Controller or non physics Controller assets.
I would start a Coroutine when the button is pressed
Then simply make it return null and apply the constant value multipled by Time.deltaTime
thx it works
i will try that for other objects
Idk what im doing 
This is completely wrong

So you simply assign the position of playerSlot to... its position, assuming the object with the name PlayerSlots is the same one?
you had the right idea, but you accessed to the wrong value. you want to store the Transform itself, not its position . . .
And then, when the card is supposed to move, you simply assign it to the position of the playerSlot. So it just works once if the playerSlot's position isn't changed anywhere
then you can use playerSlot to get its position at any time . . .
Hello, i'm struggling with shaders, i'm tryna make theese dynamic patterns and put them on sprites, but i keep having issues
ok...
I have a new problem: I'm trying to limit the amount of child game objects to the parent object to 3. I tried to use bool in this way but its not working!
Is this the right way?
There is nothing about this that would be limiting anything to 3.
You simply have 3 bools that are false, they are then set to true while doing the same logic 3 times. Except for card 3 because you are checking if it's true instead of false
You should really look more into basics of c# first and just like really what classes are. Maybe do some basic problem solving using them
Theres a clear misunderstanding about what code does here

nope. you can access the childCount of a transform. just check if it's less than 3 when attempting to add a card . . .
your code checks a bool and adds a child if that bool is false. this will set all the bools to true when attempting to add a single card because it will run each if statement . . .
a collection would have been better here, but i would try to understand or work out the logic behind what you want to achieve first, then attempt to implement it one step at a time . . .
This is just the truth. You could keep going on with whatever solutions temporarily work, but eventually everything will be such a mess that you cant do anything new and debugging takes hours.
You will save a lot more time by learning simple stuff first. Even I could start trying to guide you towards the right code, but I've seen the messages above. You really shouldnt try struggling your way through a game. Especially if you think having 3 bools that do nothing will limit the child count of another object
no, you're right
im following a tutorial on procedural dongeon generation and i got error even when i import the code from the github of the tutorial, here are the errors in VS Code and the code
you have duplicate scripts in your project
thx
For your learning relevant to this problem, look into lists and arrays. A much better setup for this would be having your player slot have some script on it. On that script, you could store an array or list of all cards. You can add cards via some public method on the player slot script. This script already has the list so it knows if theres already 3 elements.
Does anyone use A* Pathfinding Project?
How to get the collider to work on 2 Ais?
while (true && counter <= 1)
{
//card rotation fix
float rotFixY = cardObject.transform.localEulerAngles.y;
rotFixY = Mathf.Lerp(rotFixY, 0, counter);
cardObject.transform.localEulerAngles= new Vector3(0, rotFixY, 0);
counter += Time.deltaTime;
yield return null;
}```
consider this lerping animation inside a coroutine , it does work, but the lerping seems a bit off
for example, when i stopped at -61 on y , this function executes , and then y will go from -61 -> -360( which is equal to 0)
why though? and how can i make it to -61 -> 0 instead of -360?
because if i ever moved from 61 to 360 it means the card will spin , which will be very bad
or if i try to do -61 -> -0.5f , it might work
your logic is flawed.
float rotFixY = cardObject.transform.localEulerAngles.y;
needs to outside of the while
sry im a little braindead rn, is cs cardObject.transform.localEulerAngles
behave 100% same as
localrotation = quaternion.euler();```?
yes. But bear in mind if you do
Euler A -> Quaternion -> Euler B.
A and B will almost certainly not be the same
rotFixY = Mathf.Lerp(rotFixY, 0, counter);```
the problem still exists, -61 -> -360 (0)
im now gonna do Mathf.Abs(0) and see if it works lol
Guys i want to collect a coin by dragging the mouse towards it how can i do that?
you should not be updating the value you are Lerping in the Lerp @nimble apex
Thank you for your help! I have finally completed the code 
how would I display the wave name on the HUD?
set the text to the variable called name
could i do it in the wave spawner script or should i make a new one?
sure you can do it in the same
i need to, this is not an update, it is inside a coroutine
so the only thing i can do is doing the whole thing in a while loop
not at all. your logic should be
EulerA = eulerAngles
while
EulerB = Lerp(EulerA)
rotation = Quaternion.Euler(EulerB)
yield
No need to modify EulerA nor read from a quaternion more than once
See Math.LerpAngle
It wraps around 360 degrees correctly, unlike Math.Lerp
!vs
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
Is there any way to set a Dictionary<> through the Unity Inspector? It just doesn't appear. I found you can create a Serializable class that constains the pair key-value and then use a list or array of this class. And finally on the awake or Start transform the list or array to an actual dictionary, but I think there should be a better way to do that, looks so complex for an easy problem. This is an example if I don't explain to good with words:
[System.Serializable]
public class IntPuzzleCanvasPair
{
public int key;
public PuzzleCanvas value;
}
public class PuzzleManager : MonoBehaviour
{
[SerializeField]
private List<IntPuzzleCanvasPair> puzzleCanvasList = new List<IntPuzzleCanvasPair>();
private Dictionary<int, PuzzleCanvas> puzzleCanvasDictionary;
void Awake()
{
puzzleCanvasDictionary = new Dictionary<int, PuzzleCanvas>();
foreach (var pair in puzzleCanvasList)
{
if (!puzzleCanvasDictionary.ContainsKey(pair.key))
{
puzzleCanvasDictionary.Add(pair.key, pair.value);
}
else
{
Debug.LogWarning("Duplicate key found: " + pair.key);
}
}
}
}
No clue what your actually trying to achieve, but name defaults to the name of the gameobject this script is on.
trying to show the wave name on the HUD
so where in that script does it reference the Waves array?
should be referencing this
You should get a reference to the Wave object and use something like wave.name to have it
something like waveSpawnerScript.GetActualWave().name;
if i comment out stuff like this, will the reference still be there when i uncomment it
I want to say yes.. but test it. Add a new var
i've got this issue where this guy will stay in the air. p1 is a duplicate that uses the base character class, and player 2 uses the scientist class player 2 doesnt seem to be getting affected by gravity at all and remains suspended in the air. I've commented out the entire scientist inherited class, and he is still having this issue. what steps can i take to try and debug this error?
What components does that character have?
And start debugging its movement variables
Does the character always float?
its not meant to float, no
lemme show u the components one sec
If you override some method like Start() you have to do on the child class protected override void Start() and inside this methos use base.Start() to call the parent method
Also make sure that all layers and layermasks are correctly set up
this character worked completely fine until i decided to move to the Kinematic Character Controller package. the other 3 i have work just fine
idk why this guy doesnt
offending character is on the left
on the right is the debugging one, which uses the base character class
I literally copy pasted the one on the right, removed the scientist class and added the character class, and changed nothing else
Does your animator have root motion enabled?
no
Does the left version work correctly?
left version works as intended, yes
gravity wise
you cant use the moves because thats the scientist class job
Maybe post the scripts. Character and scientist
Check out the asset store for free serialized dictionaries - they aren't visible in the Unity Editor by default.
can do, but the character one is very long
Thank you I will take a look, I think this should be something already in Unity that I was missing, haven't think to look on the assetStore
Character - https://gdl.space/urujisunor.cpp
Scientist - https://gdl.space/pumedoreha.cs
You can also override the struct's serialization
Your wave manager knows which wave is currently alive.
You can just give that a method that retrieves that name from the current Wave object in the list/array you have in the manager.
What you call all those things is up to you.
Did you say that if you comment out all of the contents of the Scientist script, the issue is still there?
If thats the case then the script cant be the issue
Try recreating the scientist from the normal character again. Make a prefab variant
I will suggest to Debugg the MoveVector after the base.Update() call and at the end of the scientist Update(), maybe is kind of overwritting it a way you don't want to
public Vector2 MoveVector
{
get => moveVector;
set
{
moveVector = value;
print("MoveVector changed! : " + value);
}
}
I've made this so that whenver MoveVector is changed, it logs it in the console. Similar thing surely?
will try this, thank you
I have managed to isolate the problem. It appears when I delete my animator component, gravity resumes as normal
So my root motion guess wasnt too far off 😁
haha, i guess its somehow like keeping the Y value in stasis somehow? any idea as to why that might be happening?
Maybe some animation has keyframes for y pos?
Not sure, I never control movement with anims
me neither 😭 idk where this is coming from
but i'll have a look, thank you
Figured it out 😄
everything works as normal again
Nice
such a stupid issue lmao i wish animator set values had callbacks 😭
Guys what is the difference of
public float hallucinations;
And
[SeralizseField] (i forgot the rest lol)
One you didn't forget, the other is complete nonsense ?
why would you ask a question and not even be bothered to ask a sensible one?
[SerializeField] only serializes the field, without making it public.
public makes it public, and Unity also serializes public fields.
you can access the public field from other script, but if you can make the serialized field private, protected or whatever you want
So serialize field is only a configurable setting by the user or the script, and public lets every script read and change it?
Oh
sorta... Seiralization is more than showing it in the inspector, but yes about the public thing, assuming they have a reference.
The serialized field is simply shown in the inspector. It could be a configurable setting, a changing variable or whatever you want.
(it's not just shown in the inspector, but let's say so to keep it simple)
The public, on the other hand, is also serialized, but yeah, any script could read and modify it
To serialize is to turn something into data.
Unity records the values of serialized fields.
Could you put Seiralization in a script? Like, inside the void update and void start scripts?
okay, several clarifications here
O ok 👍
[SerializeField] is an attribute. It can only be applied to fields.
Fields are variables you declare in a class.
Update and Start are methods: functions inside a class
I have no idea what that means
Both of them return void, which means they return nothing.
And what are classes?
They are not called "void start" or "void update", just "Start" or "Update"
i think he's asking if you can serialize a local variable
classes are collections of variables and functions (and other more niche things)
you have probably made several classes already
when you create a class that has MonoBehaviour as its parent, you're creating a new kind of component to use in Unity
So basically in these? { }
(and the answer to that is no, because local variables only exist while the function is running)
No, because you use curly braces for much more than just declaring stuff in a class
Oh
public class Foo {
public void Bar() {
if (true) {
Debug.Log("Baz");
}
}
}
this is a class called Foo
it contains a method called Bar
which contains an if statement
That’s in python
The premise holds.
The stuff inside those, if those things come after a class declaration. It literally has the word class in the code.
The concepts are the same
You asked what a class is
This covers it perfectly
Classes are basically the same thing in every programming language
Oh yeah could you put serialize in a class?
you keep asking "can you put serialize in a X"
this doesn't make any sense at all
the [SerializeField] attribute can only be added to a field.
I know but really I need help where you could put serialize fields in
You can put it in exactly one place. On a field declaration.
fields are declared inside of a class, I guess
OOP is an universal programming concept
But I literally just told you where you can put them
Oh thanks
The fact that you are asking this leads me to believe you still have no idea what a serialized field is
Not exactly but I think I know now
It allows you to edit a variable in the inspector, but not access it from another class. That's all.
I do
Ik
struggling to avoid hitting you with an "um, actually" here

today we will be writing a game entirely in Haskell
What about in… scratch? Lol
I've done that actually
No
Neither
get well soon
I made a text based dungeon crawler in Haskell as a final project at college
Yea classes don’t really exist in scratch
ooh, fun
I’m just starting code lol i started yesterday and still learning from a tutorial
Classes exist in Object-Oriented Programming languages, scratch isn't object oriented
Ima make it simple for me and replace OOP with text based
Scratch is block based 🤷
Unity uses C# which is object-oriented, so you'll have to learn other language
Fine, I didn't want to get too specific to avoid muddying the waters but allow me to amend my statement:
Classes are mostly the same thing in every programming language that has them
Yeah prob learning scratch first would be a good idea
I know, just making it simple for me to understand
What?
Used scratch for 2 years now ima try to use unity now
Scratch is object based, unity uses C# which is text based (simply)
Then you have to learn OPP because Unity uses an OPP language 🫠
That’s what I’m doing lol
What do you mean C# is text based?
I mean, what is text-based?
I mean like you type text so it works
Oh
Text based is a simple way for saying oop (for me)
OPP and text based arent the same thing
"object oriented" doesn't mean you're dragging stuff around on the screen
you're talking about the visual interface you use to write and modify code
I’m saying text based so it’s simple for me
"object oriented" means that you create objects: collections of code and data that you can pass around
But there are non object oriented programming languages that are still text based
This started as a question now like 25+ msg lol
I’m not talking about any other coding language just focusing on C#
You'll have to learn universal programming concepts which would probably be exampled with other languages
!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.
Those are not even remotely the same thing
hello, I have a problem with my camera. I want its to follow my character (for a 2d platformer). I succed when i had just one character, but now I introduce an other one to choose which one you would like to play. But now the camera is fix and I don't know why (I have already put a cinemachineVirtualCamera but it doesn't work)
I’m just saying it my way, I’m not using like idk rust or unreal engine
You should immediately take that mental shortcut you've hallucinated and throw it directly in the trash. It is not a useful hueristic and will only serve to confuse you and make it impossible to communicate with anyone who's touched code ever
Let's say you confuse yourself and also confuse us
I could say OOP and text based whenever I want, u know
How did you introduce the second character?
Yes, and you'll make things infinitely harder on yourself, learn nothing useful and immediately run into a wall as soon as you see that unity has a visual scripting package.
The first way you learn something is important and it's maddeningly difficult to un-learn something.
I use prefab for both character.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class PlayerManager : MonoBehaviour
{
public GameObject [] players;
public CinemachineVirtualCamera CVcam;
int characterIndex;
// Start is called before the first frame update
void Awake()
{
characterIndex = PlayerPrefs.GetInt("CharacterSelected", 1);
GameObject player = Instantiate(players[characterIndex], transform.position, Quaternion.identity);
CVcam.Follow = player.transform;
CVcam.LookAt = player.transform;
}
// Update is called once per frame
void Update()
{
}
}
Ok. I could detangle it from my mind when I need to choose one between one
Both characters use the same Player Controller?
Detangle it now. The fact that C# doesn't use Lego bricks has nothing to do with it being object oriented
yes I think
These are entirely unrelated subjects
I duplicate the first character and change the animation and the sprite
So the two characters are exactly the same but with a different sprite, right?
yes
Is ‘’’cs
Test
‘’’
Okay, then lemme recommend you something
Nvm
What if you use the GameObject for both characters, and change its animation and sprite depending on which character the user selected? @ionic plank
oh yeah may be
Let me try
You’re smart I think that’ll work for him
I mean it’s easy to think about but
Hard to think it if you get it
Actually I think that wouldnt be very clean (my mistake)
the code looks well done tho
Just do you know how to change the controller of the animator of a gameobject
animator.runtimeAnimatorController
Howerever I recommend you to keep your old code as it's more scalable, I'll help you find out what's your problem
So did you add the PlayerManager to any GameObject of the scene?
alright then start the game and select the Virtual Camera. Check in its inspector if follow and lookAt fields are actually set to your player
yes
oh that's weird
The script is disabled and the player is set to none (camera follow)
Is that supposed to be like that?
yes it was my first script but i don't need it
I found my mistake ...
Where is your other script
oh thats unexpected 😅
thanks you ❤️
to get instanced of a material , use .getComponent<Renderer>().material, right ?