#๐ปโcode-beginner
1 messages ยท Page 585 of 1
sorry, im just trying to make it look "simpler?". Cuz i used the variables in an npc and made it glitch, so i thought using it directly would make it easier, cuz that fixed that npc
Genius
i think ur issue was exactly what i thought it was.. ur clip was starting over and over and over...
here in my animator u can see that the idle clip LOOPS but the transition only ever happens when we go from something else -> Idle
if my animator was doing the issue u were having the little arrow going from entry to idle would be flickering non-stop
my oncollisionenter isnt working
read the warning in your IDE and pay attention to your console in unity
and if that information is not sufficient, then go through this: https://unity.huh.how/physics-messages
What's the underline say
incorrect signature
That would indeed be why it's not working. You need to have the correct signature
it looks correct to me๐
then look at the docs
How about checking the documentation and seeing?
alr gimme like 2 mins
idk where to look in the documentation
Start by looking up the signature for that function
here i'll start ya out
find their Example compare it to urs..
๐ต one of these is not like the other... ๐ถ
i dont see anything useful
Tell me what the method signature is on the website
nvm i see it
What does it return? What parameters does it take?
its collision2d col is it
a debug log, and collision2d col
Collision2D vs Collider2D was the issue
Debug log is not part of the method signature
isnt that what it returns
You can see what type it returns from the method signature
it sounds like you need some c# basics
ik i literally started lerarning like 3 months ago
i strongly recommend sololearn.
i started doing that like 2 days ago
i gtg
Line 27 is causing a NullReferenceException, but.... it's intentional? Like you are not supposed to need target, it can just be null, what's causing that?
playerAggro is null
you have conveniently cropped the line numbers out
Oh, ya sorry
Is the marked one
It is, I thought that if the script is null any reference to it would be too
playerAgro?.target != null maybe works?
you cannot access target on a null playerAggro
do not use null conditional operators with objects deriving from UnityEngine
if playerAggro is null, then it's not a PlayerAggro, it's a null, and null doesn't have anything named .target
So this would work?
why is that?
It seems to work, ya
Just that it's not doing like anything at all lol
I will check it later I guess
Thank you
Unity has overridden == null for objects that have been destroyed, but not actually culled yet, that null coalescence doesn't include. So there are situations where someUnityObject == null would return true, but a null coalescence wouldn't think so
the null conditional operators do a pure null check that cannot be overridden. however UnityEngine.Objects can be a sort of fake null that happens when they are destroyed. using the == and != operators with UnityEngine.Object uses an overridden version of those operators to check for that fake null. if you don't do that proper check then something can be not null but still equate to null because it was destroyed but the variable was never set to null
You're 100% expecting a valid object (because you haven't got any null checks) but when accessing the member, you found that the member wasn't accessible because the referenced variable was null. Thus an null exception was thrown.
the reason u saw the error in the first plce was because it was null..
now that u fixed that issue... it works correctly and returns false now in ur conditional..
you'll still need to figure out why its null.. if u were expecting it not to be
i thought c# didnt let you override ==,!=.
why would you assume that?
oh nvm i guess it is there...
notice how == and != are not listed there
Yeah, == and != aren't in that list
Ok, so last one of the day. How come that the health is modified and the timeSinceLastAttack is reset, but the print nevers shows?
I mean, it's working, but, wtf? How?
double check your console to make sure that you don't have either collapse enabled (so that all logs with the same content from the same source only appear as one log) or that you are not hiding logs
Where is toggle for that?
in the console
Oh, ok, I did close it somehow. I remembered this just showed again whenever a new log was added
Thank you
using UnityEngine;
public class CamRotationController : NewMonoBehaviour {
[SerializeFiled]
private MyCameraController myCameraController;
[SerializeField]
private float speedX;
[SerializeField]
private float speedY;
private float x;
private float y;
void Update () {
x += speedX * Input.GetAxis("Mouse X") * Time.deltaTime;
y -= speedY * Input.GetAxis("Mouse Y") * Time.deltaTime;
myCameraController.activeCamTransf.eulerAngles = new Vector3(x, y, 0);
}
}
๐ 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.
guh, typo
send cam controller script
can someone change my script so it work ๐ญ๐ญ
MyCameraController myCameraController;
we dont know what this is
no
we don't do handouts here
pretty sure there's a rule (or just general warning) about it somewhere.
- you'll never learn to code if other people just do everything for you
i only know javascript thoooo
there are beginner c# courses pinned in this channel. start there
!learn
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
Hey, quick question. I'm attempting to just think through an animated counter for my game, labeled "Bet". Whenever it goes up, similar to a hand clicker (where you click the side and the dial moves to increase the number), the number will go down, and a new one will come down in it's place. My question is more in how I should set it up. I have my code to count the bet (in changing the text), just more confused on how to continue. How would yall think through this? If it helps, the bet can only go up to 7, down to 0. Please @ me if you respond, thanks!
extremely basic way of doing it but i'd think something like this would work (repeat for the rest of the numbers too
int int1;
int int2;
if(int1 < 0)
{
int1 = 7
int2--;
//rest of the stuff you want to happen
}
Are you asking about animated digits or something? Confused there
oh right yeah that too. if you're asking about animation then you should ask in #๐โanimation
Are you asking how to animate it? If so, check out #๐โanimation
I'm confused. Why is the script titled Checkpoint the one also tracking all the checkpoint transforms when the player collides with it, this doesn't make sense?
Okay, scrap it:
- Create a
CheckpointManagerwhich will have a new array ofCheckpointController[] Checkpointsandint CurrentCheckpointIndex - Create a checkpoint object and give it the script
CheckpointController - Give this checkpoint object its collider that the player has to hit to trigger the checkpoint save
- Give this checkpoint a child object which is the spawn position transform and cache it as the
Transform SpawnPositionin theCheckpointController - Drag each of your checkpoints into the
Checkpointsarray on yourCheckpointManagerin the order the player must hit them (assuming they can't skip one) - Do an
OnTriggerEnterdetection on yourCheckpointControllerfor the player hitting it. When it does, notify theCheckpointManager.CheckpointHit (this)function - In that
CheckpointHit (CheckpointController checkpoint)function on yourCheckpointManager, you can check if it's the same as the next element in the array - If it is, then you increment
CurrentCheckpointIndex + 1and when the player has to spawn, you can get theCheckpoints[CurrentCheckpointIndex].SpawnPosition.position
You have to make your own custom drawer. Or you can use an asset like Odin Inspector which has built in [TabGroup] attributes
how do i make a loop that loops every five seconds
Coroutines
you can also use update
float time;
float maxTime = 5;
void Update(){
if (time > 0){
time -= Time.deltaTime;
}
else if (time <= 0){
time = maxTime;
DoSomething();
}
}```
what about async
float _duration = 5;
float _nextTime = 0;
void Update()
{
while (Time.time >= _nextTime)
{
_nextTime += _duration;
DoSomething();
}
}
I also like this method
there's lots of ways to do it and lots of caveats for each one. Async is also a method; be it Awaitable or UniTask
you could just put a while loop in async task / awaitable to Task.Delay
asyncs work with tasks and threads while coroutines yield execution of code at specific points
async isn't on a thread unless you use APIs that do that
both are just state machines, async is just much more flexible (and has more caveats)
I don't see why he would use asyncs in this scenario though unless he is working with APIs or file IO
you could put non-unity apis in separate threads for heavy calculations
it's just as viable as coroutines. We use it in loads of places
ive just heard that async is better than courotines
hm that's interesting, never seen that before ๐
is UniTask still useful now that we have Awaitable ?
Awaitable isn't very mature, I've had teething issues with it
last thing i'd want is a weird anomaly in async code lol
is this a true statement i dont think it is: When you create a prefab in Unity, you're essentially creating a template for a GameObject. Each time you instantiate that prefab, Unity creates a new instance of that GameObject. Each instance holds its own separate data for public variables defined in the script attached to that prefab.
Yes it's true. Prefabs are an editor-only concept and everything is just instances at runtime
if you put prefab in the scene that already creates the instance, Instantiate just clones that template yea
well like if you have a public variable and you spawn multiple objects you cant have different of the variable right?
yeah each one have their own value of that var
public just means accessed from other classes
if you made them static, now thats another story. Suddenly they all share the same value cause it belongs to the class itself not an instance
yeah each one is a separate instance
as long as you have the reference
i dont know why people call public variables so dangerous then
Unity serializes and deserializes component data when instantiating prefabs and something to keep in mind that each instance of a prefab does have it's own place in memory, so at runtime they aren't 100% tied together
protecting from your future self or other collaborators
well i know about instances but like what if you have a class dog and a class cat with public speeds
naming conflicts
what about them ?
class is just a blueprint to what an / object will be . the instance is the created object
public class Dog {
public string Name; }
Dog myDog = new Dog();
myDog.Name = "Snoopy";
Dog yourDog = new Dog();
yourDog.Name = "Fido";
etc
hey everyone, how do i do something like this correctly..
var upDirection = Vector3.up;
var otherLighterDirection = Vector3.right * 0.5f;
var combinedDirection = upDirection + otherLighterDirection;```
this doesn't seem to work...why?
what doesn't work about it?
let me answer by saying this...
why does this:
var otherLighterDirection = Vector3.right * 0.5f;
var combinedDirection = upDirection + otherLighterDirection;```
behave the same way as this:
```var upDirection = Vector3.up;
var otherLighterDirection = Vector3.right; <-- changed
var combinedDirection = upDirection + otherLighterDirection;```
It doesn't, one is 0.5, 1, 0 and the other is 1, 1, 0
no the combined direction is the same...
not really, when you multiply the vector with 0.5 you are reducing it's magnitude essentially
the direction is the same, yes
The second:cs v1: 0.0, 1.0, 0.0 v2: 1.0, 0.0, 0.0 v3 = v1 + v2 v3: 1.0, 1.0, 0.0 The first:cs v1: 0.0, 1.0, 0.0 v2: 0.5, 0.0, 0.0 v3 = v1 + v2 v3: 0.5, 1.0, 0.0
hmm. let mesee
If anything, when you normalize them you'll get a magnitude of one but they do differ.
Shockly I'm not lying 
Is LayoutRebuilder.ForceRebuildLayoutImmediate recursive?
after the nice help yesterday, today smth new. Have to create a Grid for my Map editor, i thinking of drawing a "grid" sprite on top, but i dont like that solution. Does some one had a similar problem?
The only thing accessibility modifier or accessors do is restrict access
in the literal sense, yes
is there something wrong with this? everything else is working except this.. logging the removal never happens...
foreach(var enemy in separationColliders)
if(alignmentColliders.Contains(enemy)) {
alignmentColliders.Remove(enemy);
UnityEngine.Debug.Log("found enemy");
}
return alignmentColliders;
}```
can't remove items from list during foreach loop, the collection is immutable there
wth lol so how should i do it?
create a new list?
you can use a reverse forloop and do the same
if your ide is configured type forr, hit tab
yes that works.. why does the reverse work? if you don't mind me asking?
because removing backwards doesn't mess with indices
if you go forward remove item it shift and can cause skip elements
foreach is just going through an enumerator so its expecting not to change (immutable)
ahh ok thank you!
Hey, for what seems like the billionth time im trying to figure out Instantiate rotations, i just want enemy bullets to face the player when spawned but i cant get it to work, any ideas?
need to see the code
One sec
Right now the instantiate is looking like this
references are set correctly
and the bullet has this
ignore the update
i tried to make it follow the player for debugging but still wouldnt work
Using a position for LookRotation doesn't make sense, unless the bullets spawn at 0, 0.
Is this 3d or 2d?
3d apparently based on OnTriggerEnter
var bullet = Instantiate(Bullet, ...
bullet.transform.LookAt(M_Player.transform.position);
yeah 3d
oh i thought look at would do the math to look at the player
look rotation*
how's this any different?
Different from what? The Quaternion.LookRotation?
having transform.LookAt inside the bullet
the thing i have in update
it doesnt work either
In what way does it not work?
it seems to not effect it in any way
the bullets aim correctly up or down but not left to right
I don't know what that means
Well damn me
can you record a video?
Do you understand the difference between a position vector and a direction vector?
I'm confused why your editor marks these methods as unused when it knows they're Unity methods
i think so yeah
That should not happen
LookAt requires a position as argument
LookRotation requires a direction as argument
ahhh
You only set the velocity in Start so rotating in Update doesn't change the direction they're moving, so that's different at least
so in look rotation i would need sth like (spawnposition - playerPosition)
yeah, the negative of what i wrote
they would go the other way doing it my way lmao
this i still dont understand though
ohhh
now i get it
been a while since i worked with rigidbodies
So if i understand it right, LookAt rotates it but it still had worldspace momentum so it just kept going
Can you tell visually which way the bullets are rotated or are you going by the movement only?
because movement and rotation are different things
FYI, using anything transform related on a rigidbody object will break your interpolation and also probably introduces some physics oddities
Like bad collisions
In the original code they should have been always pointed towards the player but moving in a different direction
got it
its been a while as i said working with rigidbodies so i do produce some brainfarts
all this time the project has just been character controllers and navmeshagents
It's probably not too noticeable in this case since the bullets use triggers and don't rotate too much
so rotating through transform worked
well now they dont need to rotate at all, they spawn correctly
True
Oh and
this worked too
Thanks so much people, you've been really helpful once again!

Hi, I was wondering if the 'proper' place to put CharacterController.Move() should be in Update or FixedUpdate?
My understanding is that physics movements should be in FixedUpdate but I'm finding if I put it in there I'm getting jittery jumping and side-stepping.
Thanks
CC is an exception, it was designed to work in Update
Ok thank you. Does that mean things like where I'm altering the gravity in FixedUpdate for it should be moved back to Update due to CC.Move() being done in Update?
Yeah makes more sense to do it all in Update
Remember to swap out fixedDeltaTime to deltaTime though
Typically youโd use fixed update if you move things with physics. I.e. the object had and uses a Rigidbody
Yeah what Osmal said
Will do. Thanks ๐
Probably wouldnโt have movement in both Update and Fixed update though
Ah of course. Guessing because CharacterBody isn't using a rigidbody that's why it goes in Update typically.
Thanks. Gonna shift it back into Update.
Do you just move using the transform?
cc.Move does the moving
CharacterController.Move() is doing the movement. Am updating the transform for rotation.
๐
can someone tell me how can i see logs for each of my builds??
It still probably moves in fixed update as it's unnecessary to continuously calculate in update so what it probably does is buffer those values.
rather it probably uses its own internal fixed loop instead of the one that rigidbody relies on
All the info is here under "Player Related Log Locations"
https://docs.unity3d.com/6000.0/Documentation/Manual/log-files.html
i got it thanks!!
Because you selected it
left in unselected
right is selected
how do i do random.range
but with integers
hello how to make a player move based on the grid pls someone help
That question is way to broad, this sounds like you should watch basic videos on scripting
I did but it introduces some new errors in my script because my player is very complex
Lookup a youtube tutorial on grid base systems
Integration is part of the development cycle - bugs/unwanted-behaviors.
I did but nothing too useful
void HandleInput()
{
// Get input
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
// Prioritize vertical movement to prevent diagonal movement
if (vertical != 0)
{
movement = new Vector2(0, vertical).normalized;
lastDirection = vertical > 0 ? "Up" : "Down";
}
else if (horizontal != 0)
{
movement = new Vector2(horizontal, 0).normalized;
lastDirection = horizontal > 0 ? "Right" : "Left";
}
else
{
movement = Vector2.zero;
}
// Check if running
isRunning = Input.GetKey(KeyCode.Z);
// Move the player
float speed = isRunning ? runSpeed : walkSpeed;
transform.Translate(movement * speed * Time.deltaTime);
// Check if player is walking
isWalking = movement.magnitude > 0;
// Reset key press mode when no movement
if (!isWalking)
{
keyPressMode = true;
keyPressTimer = 0f;
}
}
this is my movement rn
my player basically has variable speed and can wander off the grid
Why use strings?
Yeah so basically in my game I want to make the player face a position I type in
What are you actually trying to do?
to make the movement grid based as right now the speed is variable and can wander off grid
If you mean that you want your player to be able to specifically travel just between squares in the grid, then I'd say the simplest way would be to Lerp between grid locations
so I need to make changes in the handleinput only right?
I'd put it in an IEnumerator, but if HandleInput() is called from the Update() loop then you could make it work that way
This is a good resource on Lerping for beginners: https://gamedevbeginner.com/the-right-way-to-lerp-in-unity-with-examples
thx a lot
hey guys im trying to resolve a problem i had yesterday and still cant fix it,
my character bullet only moves to ONE direction when i shoot to right or to left depending if i use the transform.right or -transform.right.
My class CharacterController have the boolean loookingRight, it switch to true or false depending on the direction my character object is looking.
So i tried to fix it by making this boolean atribute public, and creating a public CharacterController in my BulletController Class who determinates the direction of the bullet and the speed.
Then i added the object in the Inspector.
And made a condition: (mirandoDerecha its the same as lookingRight)
if (!playerController.mirandoDerecha)
{
direction = -transform.right;
}
else if (playerController.mirandoDerecha) {
direction = transform.right;
}
rb.linearVelocity = direction * speed;
and all this doesn't work, I don't understand why, if someone who has more programming logic than me knows something I would appreciate it!!
have you tried += for the direction assignments?
because certain rotations need to be added to your current rotations in order to make them rotate
If, lets say, I am trying to get a reference to an script that has been destroyed, that's not the same as null right?
why can't i move my character? is it a problem with the code or?
here is the code:
using System.Collections.Generic;
using UnityEngine;
public class movement : MonoBehaviour
{
[SerializedField] private float speed;
private Rigidbody2D body;
private void Awake()
{
body = GetComponent<Rigidbody2D>();
}
private void Update()
{
body.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, body.velocity.y);
}
}```
Like this is not null right?
it will equate to null but wont really be null
But if thats in edit mode it means the reference is just broken and should be null at runtime.
This is relevant, I am specifically searching for nulls, since it would only search for a new one if it's null
then yea it will == null
yes it's a problem with your code
may i know what the problem is
yeah one sec
so it's within the Update() part
it's not how you work with rigidbody.velocity, it just needs a direction and then the movespeed
you have some kind of.. other thing going on
im following a 4 year old tutorial so maybe thats the problem?
naw it's not the age of the tutorial, it's how the function works
well it works for the guy but not for me ๐ญ
maybe it could work, have you put the script on the object that you want to move?
yeah i think
and have you changed the speed variable in the inspector
i just have to drag and put it on the right after selecting the player right
i don't think i did
as long as it shows up on your inspector
i see why, you don't need the private after [SerializeField]
[SerializeField] already is innately private
you're basically doubling down on the private
oh damn
also was that error there before
what do you mean by before
like how before
when you first asked about your issue
yeah
the movement still doesn't work btw
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movement : MonoBehaviour
{
[SerializeField] float speed;
private Rigidbody2D body;
private void Awake()
{
body = GetComponent<Rigidbody2D>();
}
private void Update()
{
body.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, body.velocity.y);
}
}
how much am i supposed to set the speed as
and do you have anything in the inspector
speed popped up now
now change that
should i set it at a certain value
it's for you to test
np, btw pay attention to the errors they will tell you a lot
but how did the dude in the tutorial still do it even if he put [serializefield] private
yeah but the problem is i don't understand them ๐ญ
honestly it might still work even with the private keyword just fine
it's just that private is unnecessary
your core issue was that it was a typo
well lets look at your error again
Type or namespace name "SerializedField" could not be found
it just means that it doesn't know what the hell it is
i thought it was some computer thing i don't understand ts bro 
you can usually ignore the address and the code number (address is useful if another script is giving you the issue so you know where to look)
what IDE are you using?
because it should have flagged you the typo in your [SerializedField]
like so
oh ok
is it visual studio CODE or visual studio COMMUNITY
what are the best ides
visual studio CODE is with the blue logo
COMMUNITY is the purple one
purple one
ok so you have the best one
are there any better ones
it's up to personal taste really
i use community myself, because it's just pretty versatile and I can do c++ coding
and most people use community here as well
its VS and VS code
i hate c++ with a passion
eh yeah tomato potato

do one thing for me, send a screenshot of your code with the [SerializeDField] typo
lets see if it flags it
do i have to save it or no
no it should do it automatically
you should see it basically immediately
like this
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)
you want it to flag mistakes like these or else you're going to waste a lot of your time asking and waiting for answers
whats the fastest way to do it
use the links
You're also required to have a properly configured IDE to be helped
cuz i gtg in a bit
Takes 2 minutes if you know what to look for
2 steps, maybe three. You have to download a workload if you installed VS manually which can be sizey
when installing vs community i already did the unity thingy but now in unity hub theres no add button in the install
yeah im doing ts tmrw its hurting my brain
how do i select the function i want
er do you have debug mode on?
The animation event has to be on an animation clip, while you have the object selected in your scene that has an animator controller with this clip on it.
Also you need to actually start learning the basics of Unity instead of posting questions here every few minutes.
why is it not supported
oh
okay
Guys, I am suprerusty, how was that, I add stuff to the Update method of a child class without replacing the superclass one?
you don't; you just call the superclass one as well
override T SomeMethod() {
base.SomeMethod();
// own logic
}
you can't if the method is private, however
but i would maybe reconsider that hierarchy 
yes
what line is it coming from?
17
i don't know what line 17 is there
so gamelogic is null
you never actually check the local var
also what is even the point of that public var
the other object in the collision doesn't have a GameLogic then
What is causing this? I have no compile errors. It's cause it's not using the MonoBehaviour?
do you have compile error?
if not try Reimport the asset, right click it -> Reimport
Null reference error means a reference type variable is not assigned or its value is null
Look on the error line to search for all reference typesโone by oneโand check if they're null . . .
yeah i found the issue
but i have another problem
i tried every gameobject in my game
What type is GeneralistAbilityManager?
all of them are mistaches
Hello! I'm trying to follow a Unity Learn tutorial and things are working okay so far but I'm having trouble getting the hierarchy and properties window to show an updated part of the script, instead it only shows 1/2 properties despite being both classified as public. I've done something wrong or it's not refreshing. I have to go afk for a while smh
oh it is, then what do i do?
Assets can't directly refer to Objects in Scenes, but their instances can be configured with those references.
Please configure your !ide before receiving help. Your editor is not configured to work with Unity and will cause problems during development.
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
โข
Visual Studio (Installed via Unity Hub)
โข
Visual Studio (Installed manually)
โข
VS Code
โข
JetBrains Rider
โข :question: Other/None
I know you found the issue. I'm explaining how to look (search) for the variable with the error . . .
btw those aren't properties, they are fields. A bit of a difference
your changes seem unsaved
unsaved color
It is Monobehaviour if that's what you are asking
I stated that, no, I have none
try reimport then, this is used to happen to me when I created a new script on prefab, it was bug for me
had to trigger a recompile basically
sometimes either reloading, or creating a new script and copy pasting the content of the old one, helps.
So it's just Unity being weird?
ye
It may have missed a file change
See if the text displayed in the inspector for the script asset matches the contents of the file
if i disable Directory Monitoring i don't really need to worry about Refreshing correct?
like when i go into playmode it should all update?
trying to speed up my editor just a tiny bit.. i dont really wanna do the Full Domain Reloading thing.. but i found out about this directory monitoring.. wonderin if its useful?
oh, windows only, explains why I have never seen it ๐
oh really? TIL
You can only disable Domain Reload for Entering Play Mode.
In other cases the domain is always reloaded when source script asset change and its trigged by AssetsDatabase.Refresh
What you speed up is the check for changes, the event will get fired anyways
so if you disable directory monitoring it will probably still enumerate whole directory and compare against stored timestamps on unity window focus
does anybody know a really simple way to move the player in 2d unity?
ive been looking for a while and i get way too confused
Did you like try anything yet? 2D Tutorials form unity learn for example?
Immerse yourself in the world of game development with this comprehensive 2D Beginner Adventure Game project, designed to guide you through the fundamentals of creating an interactive experience. Follow along step by step to create your own 2D adventure game, with a choice of assets and options for customization along the way. Explore more 2D ...
mainly just youtube videos for now, but ill try this out. thanks
honestly, to learn the basics, stick to !learn instead of youtube. Lot of the tutorials are outdated or just bad in general when it comes to coding habits and setups
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
thanks alot guys, ive been stuck on this for a few days
from what i understand if i leave Auto-Refresh on.. and Directory Monitoring unticked..
then the changes are updated on their own.. but applied to the project when Ctrl+R (Refresh) is pressed
but then again.. im not fully versed on this part.. I'm more familiar with domain reloading. and how that works.. but not the auto-refresh and directory monitoring
I think, its two parts, not one with two variants. THe one is the detection of the changes, which can be auto or manual and how it detects them, via directory or files. And the second part is the actual reloading in unity, the domain reloading to be able to test them. Thats how I understand those settings
well these two options were found under Preferences
domain reloading under ProjectSettings
so. in my head they were different from each other
Thats what I meant. THats two parts of the asset handling
but i do know i dont wanna worry about domain reloading and whatnot..
sounds too much for me dealing with static classes
and initialization stuff
Assembly Defs may be a middle ground
Uh I would not ever turn off domain reloading after reading this ๐ https://docs.unity3d.com/6000.0/Documentation/Manual/domain-reloading.html
so in my head the way i think of it.. the first image is the Directory:
- this means the progress bar that progresses when going from IDE to editor.. or minimized editor to focused editor
then the other settings are to do with PlayMode: - this means the progress bar that progresses when going into PlayMode from EditMode
thats my starting generalization anyway..
its pretty much fine
how often you really mess with static vars ?
just be mindful to reset those
if you use static events, clean them up
the time you going in and out of play is wasted time lol
but the list what happens when turned off sounds to be like a good source of failure when observing and debugging things.
yea, here lately i've been doing little to-do lists.. ALL before entering playmode
im pretty sure its saved me more time than i can imagine
used to every little change i made i'd play-mode..
haha yeh, you get used to write bunch of code before even testing
yet to have an issue after 5 years of it off but who knows ๐ค I'm just one person
i like the new name navarone ๐
oh no no.. not like that ๐ just iterations
never will i make a new script fully before testing along the way
ahh, that makes me a bit jealous.
oh one time i had issues was some assets were not mindful of Domain Reloading being off with some people
(but the devs quickly patched the SDK after it was brought up)
i may try to incorporate it into my work-flow
but then again i may experiment with assembly definitions.. and see how that works out
if you use lots of third party assets you might have issues if oirignal asset maker didnt account for Domain Reloading being off
haha no, I am fully aware thats a me issue ๐ I just never had the time yet to really try it out in a project and was jsut scared reading the list. But i guess, once established, it might just be fine
took me a while to fully trust it, and like I said I don't use many third party assets that have scripts so less of a chance for me something going haywire
ya, it is a tad scary.. especially for someone like me
ironically the new unity 6 multiplayer player mode testing thing didnt like Domain Reloading off and threw weird bugs, I heard unity patched it since.. Idk I use ParallelSync which works fine with Domain Reload off
so you feel me here ๐ I just read "no additional OnDisable and OnEnable" calls and already felt like, dang, this can confuse me already when trusting those methods ๐
yeah true, I'm used to them, I used those anyway cause always got paraoid for leaked events but turns out its only issues with static mostly, still good practice too
can someone help me with this code im newer and need some help, what do I put so when I press M all movement is stoped for a set amount of time?
ah mb.. i just realized i wanted to discuss this in Unity-Talk.. mb im finished tho.. thanks for the input guys ๐
what code?
Huh, I have never seen this, why does this not have the checkbox to dissable it?
well I don't see code, therefore cannot help
b/c theres nothing to disable..
!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.
does it have an update loop?
or anything of the sort?
oh
No, just a method that can be called from outside
then its not part of the unity execution loop, as no builtin methods are being used, so nothing to be disabled
is that good?
mate did you read the "Large Code" part
no i did not
or just remove the empty lines and it will get small enough eventually ๐
general rule if its 7+ lines it should probably be in a link
as long as it doesn't take up the entire screen
my dc window already so small lol or phone
!learn
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
i learned c# and tried unity but somehow got stuck with the new input system lol
ty
so whats wrong?
aside from horrid formatting lol
Oh you want to stop all movement when pressing M ?
yes please
create a bool that is tied to the M key, if its true return out of the move input capture or return out rb.MovePosition (only do this if you need complete stop)
how do I make a bool?
declare it in your script
just like you had declared the other variables
declare : bool isPressingStopKey
usage : isPressingStopKey = Input.GetKey(KeyCode.M);
if(isPressingStopKey) return;
//stuff here only happns if isPressingStopKey == false```
only whats underneath
clearly u need to organize it in a way tha works
ugly nesting prevention
dont early return at teh very top for no reason..
early return pattern ftw
it just depends on the use-case
You can also put it in a method inside Update to not disturb Update
game canceled, heavy snow
you shouldn't actually
do Move() in update
CC should be moved in Update
its built to handle it..
Rigidbodies should be in FixedUpdate though
that sorta kinda tho
i still set velocities in update to match my inputs
CC is like a weird kinematic controller that Nvidia Physix has made unity just adapted the api
u can set velocity every frame..
it'll still only get applied on the appropriate physics tick
but.. be mindful ofc
wait wdym
if im using a rigidbody.. theres times i'll still put rb.velocity = input; in the update loop
it'll still only get applied on the next physics tick..
soo its still possible
ohh what does that do though instead of putting in fixed?
isnt Input already captured in Update anyway
private Vector3 targetVelocity;
private Rigidbody rb;
void Update()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
targetVelocity = new Vector3(horizontal, 0, vertical).normalized * speed;
}
void FixedUpdate()
{
rb.velocity = targetVelocity;
}``` and
```cs
void Update()
{
...
targetVelocity = new Vector3(horizontal, 0, vertical).normalized * speed;
rb.velocity = targetVelocity;
}``` will function the exact same
but it is based on what ur doing and how ur doing it ofc..
I had weird results at different FPS when using Raw in Update, so I used GetAxisRaw in FixedUpdate and fixed the inconsistent speeds
something simple as this.. (no worries)
something a little more advanced (with multiple forces possibly external forces) maybe not
i use Raw too.. ide prefers GetAxis tho ๐คฃ
i just autocomplete tabbed that entire code
ohh I usually do
rb.velocity = inputs * speed
in FIxedUpdate
idk if that matters
ya, like the first example..
thats probably the most proper way tbh
Input in update
applied in fixed
applying speed in fixedupdate vs update does it matter ? lol its been a while since I did those small test
I dont even use Update anymore for inputs thats why
new input system is event based
no polling
its because u can set the velocity of the rigibody in update as many times as u want...
it really wont matter until the fixedupdate runs.. (then w/e value is there At that exact moment will be used)
I think it doesnt matter because the rigidbody velocity doesnt deal with mass and forces
but yea.. for most cases for rigidbodies u want to be doing the actual logic in Fixed..
but u can get away with simple stuff in
but for AddForce you probably do want FixedUpdate for sure
thats true too
u could ya..
Dotproduct maybe?
this looks like a job for โจ dot product โจ
๐ช nailed it
but yeah angle would probly work fine too
u'd get teh smallest angle
closest angle to zero i believe.. it could be the opposite but yea look into Angle functions
Vector3 towardsObject = (obj.transform.position - viewer.position).normalized;
float angle = Vector3.Angle(viewer.forward, towardsObject);```
```cs
Vector3 towardsObject = (obj.transform.position - viewer.position).normalized;
float dot = Vector3.Dot(viewer.forward, towardsObject);```
i believe Dot is faster than Angle
"if this object is more aligned with the viewers forward direction"
Angle is dot product with some more calculation to convert it as angle
acos(dot(a, b)) is the angle, assuming that a and b are normalized
Then Rad2Deg
The angle is ideal if you want a linear response -- e.g. 30 degrees is exactly twice as far off as 15 degrees
the dot product is the cosine of the angle, so 0.9 -> 0.8 takes a different amount of rotation than 0.8 -> 0.7, for example
i heard someone say once u could optimize it even further using a Cosine threshold.. or something like that
you could take the cosine of an angle to get the threshold for your dot product
so that you aren't computing acos every time to get back to an angle
but tbh im not too sure about it b/c my geometry isnt that strong
yes this exactly!
is this Trig or Geometry?
oh nevermind ๐คช
Linear algebra
lmao touche
Is there a way to stop just the Update method of a script for a while?
Mmmmm, ya makes sense
void Update()
{
if (!proceed) { return; }
wasGrounded = characterController.isGrounded;
ProcessPlayerInput();
GroundCheck();
JumpCheck();
Move();
GetPlayersSpeed();
if (!wasGrounded && characterController.isGrounded)
{
headbob.CamRebound();
}
}```
So if proceed is false it would just skip the rest of the update right?
yup
u could disable the script entirely for a bit..
but that may not be viable in ur situation
Hi! I've been trying to use my camera feed on mobile but it doesn't overlap with what my actual camera feed looks like. It's more zoomed in than it should be and thus when I click on the screen it takes the info from my actual camera feed. Due to this it's inaccurate.
not sure i understand exactly what ur saying.. but if its to do with UI and the canvas u need to make sure its scaling and set correctly...
Yeah I've been trying that but the raw image remains zoomed in compared to my actual camera feed
where's your 'actual camera feed' coming from? just the camera app?
Yeah
I look at it to compare it and the input unity gets touchscreen wise is from the actual camera feed. I'm trying to make a thing so that you can click on the screen and it shows you the color it is. But it doesn't use the raw image camera feed you see
if your camera has multiple lenses most likely you selected the one that has zoom/telephoto lens
Oh that makes sense. How do you select the right one in your code then?
yeah that's what I'd guess too, there's probably some option you need to set
are you looping through the available devices ?
Not sure I understand. I'm just using my own phone which is connected with an USB cable
are you using WebCamTexture ?
yeah
ok so if you are, then you have the available devices
Alright
trial and error or check names, test each one and see which one you need
Thank you very much!
@rugged beacon #๐ผ๏ธโ2d-tools
Unity is using Visual Studio as an IDE and it's configured as far as the !ide command explains on Microsoft's site, I saved and it made no difference, been saving as I'm making changes. Could this mean anything? Idk what this means
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
โข
Visual Studio (Installed via Unity Hub)
โข
Visual Studio (Installed manually)
โข
VS Code
โข
JetBrains Rider
โข :question: Other/None
which ? are you sure the Unity Workload is installed?
show in Unity ->Preferences -> External Tools window rq
close VS, click Regen project Files button right there, once thats done double click script from unity again. Wait till VS loads
Did that and it's still not showing
public GameObject onCollectEffect; in the field there like the video shows happening, in the video the effect field is there and they drag the pre-made effect onto it
wait thats not what that was for..
show me VS again
also you need to check Console window for compile errors and if the script was actually saved.
having a configured IDE has nothing to do with fixing the field not showing up..
its just a requirement to get help here
I don't know how to get that "On Collect Effect" Field to show, idk what's wrong
did u save the file and add it to a gameobject? can u show your inspector? and not the video's inspector
Here
you really need to configure your !ide as well. i think that's been mentioned before . . .
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
โข
Visual Studio (Installed via Unity Hub)
โข
Visual Studio (Installed manually)
โข
VS Code
โข
JetBrains Rider
โข :question: Other/None
There are no errors showing here
why does my bullet not collide even tho i have rigid body
OMG i just noticed.. Unity 6 actually debugs the name of the script if it has a missing script..
No more guessing!
It's configured
using UnityEngine;
public class Bullet : MonoBehaviour
{
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Target"))
{
print("hit" + collision.gameObject.name + " !");
Destroy(gameObject);
}
}
}
this is bulletscript
hard to tell bc from your images it's not . . .
is this configured
do both objects have a collider. does at least one object have a rigidbody?
wym both
OHHH
that just means the script editor is set . . .
huh? what does the bullet hit (collide with)?
it hits wall but wall has collider
these are the exact instructions
heres how u could easily tell if it is or not
idk how to then
yes we know.. its just a step of the process
it says miscellaneous files in your IDE. this means it's not configured. did that change to your project solution?
this is only one part of it. there should be more than just this step . . .
show us the inspector for the bullet . . .
sometimes u may need to restart, atleast the IDE once u do the other steps to make sure its working
along w/ sometimes needing to regen project files
is there a collider?
yes u can see it in screenshot
rigidbody
a rigidbody is not a collider . . .
your wall GameObject has a Collider. does that make it a Rigidbody? no . . .
you can easily tell by looking for a Collider component on the GameObject . . .
nah.. if its a mesh it can have a mesh collider
primitives usually do come with a collider tho..
Create > Cube, Sphere, Etc
If I Destroy a gameObject that was part of a List, although it essentially becomes null, it's still part of the List and therefore counting for stuff like .Count right?
yes, the list doesn't care what the stuff inside is
I mean you could call the list counting every time something's destroyed
So the list counts what actually exists even if you destroy stuff
Yeah, just that getting a reference to the actual List is like 6 script jumps lmao

And it's part like for 3 different lists
you could make it managed, instead of Destroying the gameobject, you tell the script that owns the list to remove it, and that handles both the Destory and the Remove
oh
well, that could be difficult.
keep wrap it in a struct with the list ref ;)
Could I like... get a reference to a misisng script?
why is it a part of three different lists?
can you clarify what you mean by "missing script"
Like if I get this, can I get it from there and remove it from all lists that may be in, although it's not there anymore?
when that happens it means the serialized reference is still there but the thing it's pointing to isn't
how can you retrieve somethig that is not there?
the reference itself will be null . . .
So, this works like this. I have a reference to all present entities on the scene, stored on an empty on top of all. All entities get the reference of what they should be targeting from there. But then, for example enemies, each have 2 Lists that basically derivate from the other, a List of HeavyAggroPlayers and another with all the rest, it would always try to get their target from the HeavyAggro first. I would have to remove it from the top of the List and make sure it's not present on any of the other Lists that each enemy has
Could I just iterate the list in search of nulls to remove them?
To much to check each frame I would say
Could I check for specifically a missing script rather than a null, so I can update the List only then?
you can iterate and clear nulls but you gotta ask yourself when do you do that
best way to handle it is remove it from the list when you destroy it
you could use OnDisable or OnDestroy on the thing being destroyed
but i think it'd be better to handle it from the list side
as Mao suggested, you should/can update the list when an enemy is destroyed . . .
Yeah, there is no way EVERY enemy has a reference of what just died to remove from their lists specifcally
then those enemies can ignore that
It would be too demanding
Some ideas is don't let the object destroy itself but use a manager type system to handle it, another is wrapping it in a struct with a list of lists that it is occupying. Or, just make a variable on the object itself that has references to all lists that it's included into and iterate through those on destroying.
i would use events to trigger the update . . .
Ok, I think I know how
Best case -> events
or some subscription service to alert all lists that it's been destroyed at object level
really direct references are fine too... it's just events are fancier and encapsulates it a bit more tightly
The aggro manager checks first for the heavyAggroPlayers, then for all the rest, but will be stucked trying to get it from the List that just contains a null cause it sees it as containing something. I am gonna make so if after checking the lists it still has a null target, to just update the list, since something was clearly removed
but will be stucked trying to get it from the List that just contains a null cause it sees it as containing something
you could just make it check for null right there
wait, do all enemies have the same list of aggro players?
im not saying that's a bad solution; but the cause you mentioned is not really a problem
No, it's different for each one, pretty much they all know the players are there, but who they consider a priority is different for each one
It can totally be null at this a point, that's something that can happen, the heavyAggroTarget List may be totally empty
That's fine
This is what I am doing rn, so u can visualize it better
i thought the enemy has two lists: one aggro and one regular? how come you check listOfEntities.PossiblePlayerGroupsTargets?
also, did you try using events? i can give an example . . .
Oh, ya, possiblePlayerGroupsTarget is basically straight up gotten from the main reference, since it's basically everyone, but the other is specific to the enemy
Also, I have absolutely no idea of how to manage events
oh, i thought the enemy stored both lists itself? wouldn't the list on the main reference also contain players from the aggro list?
It does contain all active entities, whenever one is missing, it's removed
You could skip over invalid targets and make a note that you need to prune the list
yeah I haven't read all the context but I often suggest solving this kind of thing by not deleting stuff so that there are never any nulls. Like if the problem is 'dead things need to be removed from everyone's target lists' you could reframe that to 'everyone's target list should handle the possibility that there are dead things in there' and that way 'cleaning up those lists' becomes its own task and you can do it whenever you want (this is basically garbage collection)
indeed
i've been dealing with this on my own -- I have a lot of places that care about lists of Entities, and outright destroying them means I need to either:
- immediately stop tracking them (which could cause concurrent modification problems)
- check every entity object before trying to use it
Actually this one line seemed to do wonders
I wonder if I should have a "cleanup step"
instead of immediately firing EntityManager.OnRemove, I would do that near the end of the frame
a long time ago I found that 'have corpses' solves a lot of these problems in a way that feels intuitive
!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.
looks like you're modifying the list you are enumerating
and may even be valid for some things to target!
even an entity whose physical form has been mega-deleted may still "exist" in the form of memories, relationships, etc.
this maybe one of the most important "secrets" one has to figure out as a gamedev
I meant this one, sry
If iterating through the List I see a null I remove it straigh up
shouldn't that yell at you for removing while iterating?
oh no, I'm discovering mind/body duality via unity
also you often find that you want to keep it around just as a container for effects, event limiting and obviously, pooling
Entities?
Spirits*
yeah, dont do that
if you want to remove stuff from a list while iterating, use a regular reverse for loop, not a foreach
if your method starts with 'Calculate' it should have no side effects imo
yeah
finding the closest target and keeping the closest target list properly updated are different concerns
genuinely thinking about creating a non-MonoBehaviour "soul" object that gives an identity to the Entity's physical body now
I could do it outside the method before calling it, but... kinda.... why? Is gonna do pretty much the same loop
modifying a list while iterating over it will cause an exception
because they are different concers as prakkus said, and have entirely different reasons to be modified down the road
you should not have nulls in that list anyway, looks like a code smell to me
well, then you need to observe that destroy event, not be surprised by it
I'm here for it! It'll be perfectly confusing in my game about cleaning troubled souls in a graveyard
https://paste.mod.gg/sgwmggejzrlt/0
here is an example with events. nothing is tested as i just made it up . . .
Can't be any worse than whatever this class does
It is not causing it, it would seem
this isn't even my final transform
maybe there actually are no nulls so it's never happening?
Well, I am actually getting some exceptions, but it's working
@frigid sequoia the other site doesn't have context highlighting . . .
GameManager
Enemy
Player
What again?
well, that's y it doesn't collide
anyway to collide with transform.position?
https://www.youtube.com/watch?v=tNtOcDryKv4 no.. not w/o custom detection
Check out the Course: https://bit.ly/2S5vG8u
Discover 5 different ways to move your Unity3D gameobjects, see some of the differences between them, and learn which one I usually use.
More Info: https://unity3d.college
that question does not make much sense but no, transform.position teleports the object, the physics system then tries to fix the collisions based on the new position but it won't work very well
oh I see ty
Especially if you are every frame overwriting the positition, the physics can do very little to prevent that
what are you doing?
The GameObjects must have colliders, and then you use physics methods to check for collisions. Basically, you do your own custom collision detection because manipulating the transform does not involve the physics engine . . .
With this I mean, show the actual code ๐
I understand it now im changing it
Maybe you are moving the camera every frame, after doing that?
This was an example of using events. The player script would have the event on it. The GameManager and Enemy scripts subscribe to it (the event). When the event is invoked, the methods attached to it are called (+= Player_OnDestroyed). They remove the player from the list on those scripts . . .
Vector3 cursor = Input.mousePosition;
cursorPos = mainCamera.WorldToScreenPoint(cursor);
why does cursorPos return valuez such as (-4371.42, -12528.05, 10.00)
Try logging cursor first, and see if that looks more like a screen position or a world position
i should also mention that mainCamera [SerializeField] Camera mainCamera;
is asigned to the main camera
i tried and it is a screen position
read the function you're using. you're taking the cursor as a world position
you need ScreenToWorldPoint
So, why not use Screen to World?
So the UI is moved in Update.
Where is the camera moved? Update? LateUpdate?
Move the UI in LateUpdate
Tbh the drifting is not too visible in the video you sent
I do see these weird black streaks though
I think, because you are trying to render on screenspace, the updat eof the canvas is falling behind the camera movement render
why doesnt my col.tag work
First of all, why not use a 3d space canvas instead? And, you could try to force rebuild the layout with every update (not sure, thats a good idea performance wise, but you could test it)
Collision2D does not have a tag property
@proper needle You can get the collider from the collision and get the tag from that though
is there a way to make triggers solid
A collider is solid if you uncheck "trigger" in the inspector
ik but then i cant use ontriggerenter
but then i cant call a tag
You can't have a solid trigger as a trigger is a volume of space that you can pass through. . .
alr imma try
What issues, I guess meshes overlapping the button?
at least on the canvas, yes.
The parameter is a Collision2D type, not a Collider type . . .
Is Unity.UI not a thing anymore in Unity 6?
Look at the type in the unity docs to see what properties it has (you have access to) . . .
I said "get the collider from the collision"
oncollisionenter gives you col which is of type Collision2D, and you can see what properties it has here
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Collision2D.html
thanks that worked
The sorting layer is only "internally" for UIs. It will not let you draw the UI above your meshes. THerefore you would need an extra camera if you want it to be always on top
Thats why I suggested to try the forcerebuild layout
I am using Unity UI in 6, so its there, even if not in the docs weirdly enough
now i have this error
Read it and try to assign the terms to your method
you know what a parameter is?
alr thanks
Its in the docs I pasted. You give it the recttransform of your canvas as a param
did you try it in update?
I think, they dont do it with world canvas, as there is no perspective to the item. You just dont see the offset (if there is one), because there is not an object as close to it as on your example
Why did you change the parameter type?
What you also could try is to use screen space camera instead
Maybe that changes how things are rendered
how do i make this so it actually works
It might just be unity being unity sometimes
OnTriggerEnter2D uses Collider2D, not Collision2D . . .
please learn to use the docs and read about "Unity collision2d", should get you going to the right place with an example code
Again, look at the Unity docs for Collision2D for how to access the tag. You need to attempt to solve the problem. Also, what is Collision2D? Is that your own custom method?
someone here told me it was collision2d
i used oncollisionenter2d
No one said that though. You need to learn some C# basics, like what a parameter means. Check the beginner courses in the pins
guess you had it as world canvas and now the scale is messed up? ๐
ik what a parameter is
i learned that from javascri[t
javascript
They were talking about the type, not the method name . . .
reset your transform of the canvas ๐
when i do that tho i cant tag anything
Thats just the result of drag dropping back and forth between screen and world ui
so now im stuck in this loop
please do the basic courses. you dont know what you are working with and that will bring you here for every line of code
alr then
There are pathways on learn platform now, which will guide you
Right click on the component, reset
yeh, because its driven by the canvas now ๐ try to make it a world canvas again, then reset and then back to screenspace camera.
ah no wait, thats intended. because your camera is rotated. all should be fine. I guess your button is messed up
can you show the inspector of your X button?
any recommendations
i need the c# documentation for oncollisionenter2d
and when setting camera, it gets huge out of a sudden? ๐ try to make the plane distance something small to see if that changes
then use your hands and eyes to type it in 
thanks
i do that and it takes my years to find what i want lol
thats part of the learning curve
so, lets get back to your topic, which is not code related anymore, but whatever ๐
bruh i look up unity documentation and go from there
Can you show your scene view with the camera attached?
read again ๐
There is Game View and Scene View
Tbh, Google is better for searching unity docs than the unity docs search itself
wait, two cameras?
Could it be, that you assigned the wrong camera while looking through the other one?
or was that screenshot with that huge UI from your scene view?
ah okay
and when assigned the main one, how does it look like?
Okay, that feels like some querks with cinemachine
when back to camera overlay, where do you set the positions? In lateupdate?
And what is your cinemachine brain set to update?
CInemachine Brain component
Yep, you could try to use another method so cinemachine is done with repositioning the camera before you calculate the UI. Otherwise, you take previous frame positions and that will result in that lag
at least worth a try ๐
btw be warned there are differences between v2 and v3 of cine machine
but v3 has some nice newer stuff so do upgrade to it if not already
Is it part of unity 6 release or also usable in previous versions?
ah, just seen, its already in 2022
it says 2022+ but projects I work on had v2 still but probably cus lots of common stuff comes from like unity 2019 and earlier
cinemachine is great it will make cool camera stuff super nice
Best of luck and success with your first project then ๐ Im out for today, happy developing
There are plenty of people around ๐ Just ask and youll get answer sooner or later
fun fact, cine machine was "ported" to unreal engine cus its soo good
happy to help ๐
Hey, any good courses i can follow for unity? Im a total beginner and would love to try game dev. Its been my dream
You using cinemachine would've been good info when I asked when you update the camera ๐ฌ
@rich adder had to alter the code a bit but just wanted to say thank you. Everything works now ๐
Im building a mesh via script and I am looking for learning resources on how to apply textures or materials to specific sections of the mesh
different from build to editor
in editor, all of the lines get executed
but in build, from like 66 it just stops
im building with IL2CPP
Check the logs for errors
no errors
Where did you look
which one
keyMeshifSkinned?
that one is empty
yeah but in unity editor it works, why would it not in build..
@wintry quarry
yeah but like if it were to be a object reference, why does unity editor allow it
its weird
i guess i just do that?
oh also, this script has been here for a long time
there were no issues with it, untill i switched to IL2CPP
your camera shouldn't be attached to the player . . .
also, use !code to format and post correctly . . .
๐ 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.
overlay shouldnt be moving regardless or am I misunderstanding
overlay canvas renders after main camera
unless you mean world space
you're saying UI elements are drifting this is this irrelative to the main camera
ideally you have cine machine update in Update, the UI pos stuff is LateUpdate
or if you need both to be late update try to change the monobehaviour orders or as you said, use an event
what are you trying to do with the UI? what is the goal? i'm not understanding what is happening . . .
is this like a 3D object being converted to screen space when you pick it up?
the problem is the world -> screen pos must be before the camera changes in this frame
well you want the camera transform to have changed already, THEN do the world -> screen pos conversion
otherwise its going to be "out dated"
so you want:
player moves -> cinemachine updates stuff -> worldscreen pos for UI element
yeah that's probably it. Cinemachine has a few options for when it should be ran too somewhere on it which you can screw around with