#💻┃code-beginner
1 messages · Page 381 of 1
Is impactEffect a reference to the prefab or a scene object?
If it's cloning the object that hit something, they'll likely all hit that something.
It's a reference to a prefab I've set in the inspector, which in this instance happens to be the same prefab as the bullet
omg omg... I created a new prefab for the impactEffect and it doesn't loop. Is this a Unity thing or 100% me?
When is the ImpactEffect happening? Like once or multiple times probably?
You likely referenced a scene object. The excessive (Clone) implies so
The effect is only happening once, but when I think about it, the bullet script is on the prefab, so I assume that when it instantiates the new impactEffect, it's just running everything over as if it were new - at least that's my best guess and I've learned some valuble lessons this morning 😅 🙈
Thanks to all!
How would I destroy the entire game object if I detected a collision in DestructibleWall Collision? been stuck on this for a few days but I might just be stupid
so i understand whenever i want make multi type container i should just make new class, but do i really need make 20 different fields for each type?
Destroy(transform.parent) or Destroy(transform.root)
thank you
Debug.Log(atlas.SpriteCount) and atlas.GetSprites(supplied array) always return 0, disregarding any and all sprites in the atlas. It worked just fine up until a few hours ago and suddenly it broke and now I cant fix it. I've given up, can the Master Of Unity help out with this issue
Restart unity, check console for errors.
Did both, no errors
Simple things like correct atlas set?
Show us the logs and method that logs
References to collections and scripts are set up properly, as have the sprites and the atlas packings.
Then as dalphat said, show us the logs/script
Here is the code, its called in Start()
Do I drop the big log here or in another channel?
Screen shot of your console logs
Here is the error logs
wth!? 😄
Fix your errors or do not expect unity to run correct
Two other errors are unrelated, am using logerror for the debugging
Please show the code related to the NRE
Errors can break your runtime and stop your application from working
Especially null errors
Note: worked just fine a while ago with these two errors
Doesn't matter, you should not run your application with errors. Compilation will not work and it leads to undefined behavior in general
Elaborate on NRE
keeping those errors for "a while" ...
The Null Reference Exception that is shown
You'll need to fix your nre on line 53 of the player handler
PlayerHandler saves and loads the map between different playthroughs and scenes, in order to save the map I need properly setup buildings which I cannot setup anymore because the atlases broke
How to post !code (use the Large Code Blocks section if you've got a lot of 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.
Click the collapse button to uncollapse it and show a screen shot again
Uncollapsed with the PlayerHandler NRE
Scrollbar just shows there are more Debug.LogErrors when going down, nothing else worth of note there
Your nre is occurring before your logs. Fix the nre first. Everything else may likely be false positives.
No NRE
PlayerHandler was searching for pre-loaded buildings in the scene, however if the scene is null it was returning an error. Fixed
However the issue with asset.GetSprites and asset.SpriteCount still returns 0
Count is zero, so you'll not get any sprites from the atlas
You can see the sprites in the atlas and the atlas attached to the Images collection
Likely your referring to a different atlas as the console log states there aren't any sprites
Trying to make a ui toolkit's Progress bar as something functional as a for example Healthbar is a fool's errand? (in contrast to making it on a legacy system)
Not the case sadly
I am going over each item in the collection and taking the sprites out of them to supply into an array. Again, it worked completely fine, doing its intended purpose until it just decided to not do so anymore
It clearly says zero so whatever that atlas reference is has zero sprites
Only 1 atlas by that name in the whole project, properly attached to the collection. Is it possible that my code is creating a duplicate of the atlas with 0 sprites? Shouldnt be the case but it wouldnt be new for Unity to hallucinate
I am inclined to believe that it broke after Unity suddenly lost all references to the collection at random, however I am unsure if it has anything to do with it. It's been losing references at random for the past few months but every time I reattach them in the Inspector it resumes its normal activity, be it a prefab or a script or whatever
You're likely referencing something other than what you think.
Lets assume that I am indeed referencing the right atlas, what would the problem be then?
Log the item:cs Debug.Log($"Click to highlight the Item: {item}", item);
It highlights the proper asset
I'd rather assume the opposite. If you're wanting to suggest what you've said, your only hope would be to try different versions on Unity or recreate the entire project - assuming the project is corrupted.
And the inspector for this object would be #💻┃code-beginner message ?
What is a 'multi type container'?
Yes, exactly
Can you show the inspector for Workshop?
Inspector for sprite atlas + inspector for one of the sprites in the atlas, the rest are the same
So just a regular class?
I am new to unity and working on an idle game. I'm trying to make a button switch between showing pickaxe buttons and worker buttons. The code turns the buttons off but not back on does anyone know how i can fix this?
yes but perhaps there something like object
if i have multiple same datas but in different type
what are you actually trying to accomplish
is this code being called from Update?
Once your game object is set active to false then the Update and everything stop
yeah
It should've highlighted an item and not the work shop, if I'm reading your code correctly. Where's the item object?
once you disable the gameObject, Update no longer runs
ok thanks
Where this instance/reference of item should have had a levels property/field/collection
Can you elaborate please, I cant seem to understand what you mean
Do you wish to see the collection script
Item should not have been a sprite atlas so can you show us the item object that was highlighted?
Note that this doesn't stop you from calling methods on your component -- disabling it only stops Unity from running things like Update and FixedUpdate!
So you can freely call that method from somewhere else (if you make it public, at least)
Thanks i got it to work
Can you show the log message produced from #💻┃code-beginner message
yea, just a sec, unity crashed
I would also try reimporting the sprite atlas asset
We haven't seen the item object as far as I'm aware - we were given what's assumed to be the last element of the level from supposedly the item object. It should have highlighted the item and not the work shop (last level).
ive seperated the sprites. its hard because i can either make it look good aiming up but bad aiming down or the other way round
So when you single click the log, the object with a building library component should have been highlighted. Show us the inspector for that object.
Use the log I provided - I'm assuming the item is a unity object/component. #💻┃code-beginner message
hi there, im having problems with callback functions.
{
Collider2D nearestCollider = FindNearestInteractable(); //get the nearest collider,
if (nearestCollider != null) //and if it's not empty,
{
Interact(nearestCollider.gameObject);
Debug.Log("Interacted from OnInteract() to call Interact()"); //then interact
}
}```
for some reason, it runs whats inside OnInteract(), but the debug error log tells me that the method is missing
and to trigger it, im using /// interactAction.performed += OnInteract;
You set something up in the inspector that's broken
Do you have a PlayerInput?
yes, its properly set up
I couldnt use the exact same code so I had to change it for it to run
movement and others work, only the interact code doesnt
but ok ill double chekc
That doesn't change my advice
It's odd you're doing this if you're using PlayerInput
Do you -= somewhere to unregister when disabled?
Remove the log and put a break point where you've assigned the temp atlas (red circle by clicking to the left of the line number)
Attaching the log in a sec
yes, i did
When you execute the program and it halts on that line, check the details to see the level elements.
Hm, it doesnt halt at the break point
i dunno if theres anything wrong, but seems fine to me ...
movement script and other method works, but it only wont work when i use callback
Make sure to start the debugger before hitting play in the Editor - green arrow up top in Visual Studio.
None of this is the PlayerInput component
You just happened to name your input actions asset with the name "PlayerInput"
Which is incredibly confusing
But I'm talking about the actual PlayerInput component
From the inspector or somewhere else?
ok, this was here too, what about it?
do i need to rename the PlayerInput input action?
If you're not using this you should remove it
You don't need to but I would recommend it because it's causing you confusion
The name collision is not a problem (unless you use the "generate C# class" option, which would give you a class with the same name)
I called my input action asset "Input Actions"
very creative
ive removed it--n now my player wont move
I got some requests on how to use debugging for C# code in Unity projects and Visual Studio so here is an example project with a UI panel in which I show you how to use the debugger and breakpoints.
You can download the free community edition of Visual Studio 2019 here:
https://visualstudio.microsoft.com/de/downloads/
Debugging is essential wh...
Then you were using it
Why are you using two different approaches to input handling
Pick one and stick with it
oh, so thats what im doing currently?
hmm alr lemme check
Yes you're using both the PlayerInput component and a direct reference to your asset
I sense some heavy chatgpt guidance with that input handling
i use different tutorials 😅
Verify that the reference item has the correct level referenced, that the level has the correct elements and that the element (work shop) has the correct data (multiple sprites etc) @tender elbow
Srry for multiple images
kk ty for the help ill try to fix it
Count prints zero so most definitely it does not have the correct amount of sprites but you'll also be able to track what's the incorrect reference: item, level or work shop - one or more of these is incorrect.
You can just change the behavior to unity invoke event then assign manually without having to deal with bindings in the code
it does work but the object rotates around itself and i want it to rotae aroun the player
sounds like you need to correct the pivot point, then
That temp atlas named workshop sprite atlas has no sprites. Check the line before to see what levels were available and what the item was. There should be a window where you'd be able to inspect the locals and whatnot https://learn.microsoft.com/en-us/visualstudio/get-started/csharp/tutorial-debugger?view=vs-2022#inspect-variables-with-the-autos-and-locals-windows @tender elbow
either by changing the origin of the sprite or by parenting the object to an empty
// new pool gameobject
GameObject newPool = new GameObject();
newPool.name = "NewPool";
newPool.transform.parent = liquidManagerTransform.transform;
newPool.AddComponent<PoolScript>();
newPool.GetComponent<PoolScript>().blockTilemap = blockTilemap;
newPool.GetComponent<PoolScript>().liquidType = liquidType;
Debug.Log(transform.childCount);
foreach (Transform child in transform)
{
child.GetComponent<LiquidScript>().isActive = false;
child.GetComponent<LiquidScript>().isPooled = true;
child.parent = newPool.transform;
if (child.GetComponent<LiquidScript>().GetLiquid(Vector2.up) == null)
{
child.GetComponent<LiquidScript>().isPoolTop = true;
if (child.GetComponent<LiquidScript>().GetLiquid(Vector2.down) != null)
{
child.GetComponent<LiquidScript>().GetLiquid(Vector2.down).GetComponent<LiquidScript>().isPoolTop = false;
}
}
}
Destroy(gameObject);
In my liquid "pooling" system, when calling this script on a parent gameobject of children I am trying to move to a new gameobject (that it is also creating) for some reason it will only move 3/5 children before destroying itself, and if I comment out the "Destroy" at the bottom it will keep those two children in this current gameobject, if anyone knows why it would be amazing to find out!
The "transform.childCount" also does recognize all five.
how can I change the origin point?
Changing child.parent inside the loop will mess up the foreach iteration, I think.
Because it gets removed from the children
That you are iterating on
Ah, weird. Would there be an easy way to fix that?
I guess that does make sense, though.
think so
Could try a reverse for loop instead
for(int i = transform.childCount - 1; i >= 0; i--)
{
var child = transform.GetChild(i);
}
Should work?
I'll try it, thanks!
I am dropping it and reverting to a push from yesterday, ill try to retrace my steps and see what went wrong and where, thanks for the help nonetheless!
it is
Note that this might reverse the order of the children under the new parent, if that matters
it worked!
That shouldn't matter luckily! Appreciate it.
Currently my code is just about as horrible as you could possibly imagine, nearly 800 lines which I could easily rewrite in roughly 150-200 and it's painful to work in, but I am too stubborn to rewrite it until it's finished.
it is
in the sprite editor, you can change the pivot point of the sprite
you want to put it where the sprite should rotate around
I don't see the outlines or the camera icon on unity like image 1
Instead, I have the rendering of image 2. When I add Tilemaps, and I launch the game, I do not see them even by double clicking on the camera (image 2)
This scene is completely empty
ah, I see: you mean that when you add more things, the game view winds up empty
sprite renderer?
show me the inspector for Main Camera
No. The sprite editor. It's part of the importer for a sprite -- click on the asset in the Project window and look in the inspector
SpriteRenderer displays a sprite
Even when I add a capsule and launch the game :
also, that camera is at a pretty wild position
set its position back to X=0, Y=0, Z=-10
Is the capsule actually in view of the camera?
idk if it is a sprite anymore cuz i just made a capsule in the normal game winow to the left
Since I can't see the contours of the camera rendering, I don't know
Why not? Go into scene view and select the camera
See where it's pointing
you're going to have to show me what you're actually doing
you have gizmos off
top right corner of the scene view
turn them back on
okay, so you're using a built-in sprite
ye
If you want the shield to rotate around a different point, you can put it under an empty parent object
Then rotate the parent
yep
Make an empty object positioned in the center of the player
parent the shield to that, and rotate that object
I can't wrap my head around the localization plurals format
{0:plural:an apple|{} apples}
so...
-0 is where my replacement happens, I can name a field there
:pluralthe literal word "plural" because reasons?:the singular versionokay, singular first...|the plural versionwhy with a|if singular was with:??? how can I make the zero case? what about languages with duals or other plurals???
I don't get it 🥲
With guizmos + reset position + capsule on center = playmode nothing appear
Look at it in 3D. Is it in view of the camera frustum?
How far away from the camera is it?
ty it works
ty ty
What does this mean/what did you try to do?
Prefabs cannot reference objects in the scene
Oh it's a prefab
Prefabs can exist anywhere. Objects in the scene only exist when that scene is loaded
There are many formatters.
the plural formatter is one of them
hence needing to use :plural to indicate you're using the plural formatter
contact , but it's really annoying because I can move a 3D object but not tiles
You can move anything
Every object has a transform
The documentation should explain everything.
Okay, but in the tutorials, the camera is directly configured so as not to have to do that, why don't I have a result similar to that:
Because your camera is not directly configured so as not to have to do that
For example, your camera is perspective. If you're trying to work in 2D, why are you using a 3D camera projection?
I simply use the basic camera added on new 2d project
IF your project was created as a 3D project, the default camera is perspective. If it's a 2D project, it'd be Orthographic
It just changes the default, you can go in and change it whenever
Ok , I've recreate one again the project , seen be fix now
I don't really understand because I've already done it twice without having this result, even if I change to a perspective camera, the result is not like the one I showed above
The screenshot from the tutorial is an orthographic camera, not perspective
This code here will give the first item in database an id of 0?
why the double initialization of the Dictionary?
Update: I found out the problem was that it was detecting the bottom and not the clone. How can I make OnTriggerEnter2D detect multiple game objects.
It already does
It'll detect every trigger interaction
Does it not detect clones or
It'll detect every trigger interaction
Any time this object enters a trigger interaction (whether it's entering a trigger or something else is entering this thing's trigger), it'll call OnTriggerEnter
Well the gameObject that's the clone still isn't changing.
And it's detecting it, so IDK what happened
I have zero context as to what this means, but I can assure you that every pair of objects involved in a trigger interaction will call that function on both of them
If the function isn't calling, a trigger interaction isn't happening
I'm just watching a video. He says to clear the dictionary so we do not duplicate anything.
The Three Commandments of OnTriggerEnter2D:
- Thou Shalt have a 2D Collider on each object
- Thou Shalt tick
isTriggeron at least one of them - Thou Shalt have a 2D Rigidbody on at least one of them
But he also says we cannot serialize dictionaries. Then what is even the point of using the OnAfterDeserialize? Can you deserialize something you could not serialize?
I can guarantee you, when OnAfterDeserialize is called the Dictionary is initialized and empty
Doesn't seem like that would do anything. Use a list to store you entries and initialize the dict in start/awake
Ah so there is no need to initialize it again since it will be empty okay.
exactly
So the OnAfterDeserialize is like something general? Does it get called whenever Unity deserializes ANYTHING?
why are you using it if you do not know this?
Usually I use the ISeralization interface methods when I cannot use onvalidate
Ah no I am not using it. I was just watching this video and I read the document but I just got confused.
I will make sure to look up OnValidate
Do not get confused. OnAfterDeserialize is called by Unity immediatly after the data has been deserialized so that you can do things like fill non serializable data
It should work well with Scriptable objects then hm
I'm using newtonsofts json serializer anyways I believe I can just serialize the dictionary
so, for example rebuilding Dictionarys is a perfect example.
you should also have a OnBeforeSerialize to fill the List from the Dictionary so that that can be serialized
but that will not call OnAfterDeserialize, that is Unity serialization only
Hey guys I've been learning a lot! I've been working on this Player Controller script for the last 2 weeks. Everything works fine, but over the days I know for a fact I've double called things in the update, have a couple unused methods. Was wondering how I could clean this up? https://paste.ofcode.org/3b6amWMKR4vnPXwXj3qBWM4
Ah makes sense. Thanks
- delete any unused methods
- Get rid of duplicate code like:
CheckCurrentSpeed();
MovementBugFix();
CheckCurrentSpeed();
MovementBugFix();```
The update just looks....a mess...lol I know it gets the job done but.. ya know
Fixed those btw^ ty
it is a mess
public bool isMovementState = false;
public bool isIdleState = false;
public bool isWalkingState = false;
public bool isBaseMovementState = false;
public bool isRunningState = false;```
This absolutely needs fixing
You should use an enum
MovementBugFixForReal()
I will have to watch a tutorial on enums as I've never used them, but heard of them. its like a method that stores values and can be called anywhere correct?
Hi, im having the following problem: i created a trigger "Explodir" so i can do a transition from the state "Any state" to the State "Explosion", i set the trigger in my script but the animation doesnt play, although my trigger was activated. Am i forgetting something?
An enum is basically an int with a hat that you can't do math on. You just assign names to distinct values that you can use to check for equality.
ahh, so for example I can call it from another script so how would that look? the same as calling a static?
no. It defines a type that can have a number of different values and holds one such value at a time
It's just a datatype like any other
nothing special about how it is referenced or called from other classes
It's creating a Type, that you can use like any other type, but that type only has pre-defined named values in it
So you could create a Stats enum that contains HP, MP, STR, DEX, CON, and if you tried to do Stats.LUCK it wouldn't let you because that doesn't actually exist
Whats the benefit of using enums vs this ^
for example:
// Define the type
enum State {
Idle,
Walking,
Running
}
// Use the type in a variable, like any other type:
State currentState = State.Walking;
// More examples
if (currentState == State.Idle) {
currentState = State.Running
}```
this has 32 possible states
Because all of that becomes one line:
public State CurrentState;
and you can no longer be in more than one state at a time
oh!!! this looks way better
what happens if isIdleState is true AND isWalkingState is true
what does that mean?
With the enum that's not possible
they will never be true at the same time,
it's up to you to keep it consistent then
one gripe I have with the animator is there isn't actually an enum option so you basically do have to juggle bools
Or ints, but yeah it's hard to maintain
sure unless you make a mistake
Making invalid states impossible to represent makes your code more reliable
The should never be true at the same time.
With an enum, you can change that to will
So I'm getting an unintended behavior using this for loop, where it fills the same letter twice (え=e). I want it to fill it out using the rest of the characters in the array
// "For loop, skips the picked value and continues to skip one iteration"
for (int i = 0; i < 4; ++i)
{
// If we encounter randomInt2 we just skip it
if (i == randomInt2)
{
continue;
}
// Set the text randomly between 0 and 4
answerButtonText[i].text = answerKey[hiraganaArray[i]];
}
are you sure that hiraganaArray does not contain a duplicate?
and that answerKey is correct?
I think so, yes
void HiraganaDictionary()
{
answerKey.Add("あ", "a");
answerKey.Add("い", "i");
answerKey.Add("う", "u");
answerKey.Add("え", "e");
answerKey.Add("お", "o");
}
string[] hiraganaArray = { "あ", "い", "う", "え" ,"お"};
didn't you pick a random item from that array and set a random answer button to display it?
Yeah, but I was having some trouble implementing that so I wanted to break it down into smaller bites
show the rest of your code
Ahh, okay
randomInt2 should become chosenButtonIndex
this code will always write え into the last button, assuming that chosenButtonIndex is not 3
so if it also happens to randomly choose え to be the correct answer, and it doesn't put the correct answer into the button at index 3, you'll get a duplicate
You need to pick a random character for each of the answer buttons -- and you need to exclude the character that is already the correct answer
You can easily do this by making a list of the possible choices and removing characters as you use them.
furiously begins to take notes
Oh I see... so I need to modify my codes so that I am selecting a random character for one of the answer buttons, then "excluding" them from the list by removing them from the list. Then removing characters as I need them. Something like this:
1 - あ
2 - い
3 - う
4 - え
5ーお
あ has been removed, therefore the list shrinks to a count of 4 and we select at random the rest of the values
Yes. And you skip over the button that you've already assigned the correct answer to.
Can CharacterController be used for NPC´s??
of course
Sure, but if you want to use the navmesh then you might as well just use NavMeshAgent to move it instead
Okay, thanks
What is the design pattern, if you could call it that, where you have a script that primarily acts for references. So it would for example, it could contain serialized fields for each component, the other scripts would reference that script
I guess you could call that a 'store' but it just sounds like 'programming' to me. Your program is made of data and functions and programming is deciding where to put them.
Maybe a manager or a singleton
Sounds like some manager, but rather having other scripts full access to those references the manager should handle the inbetween and expose only what's required
Is it conventional? As in, have you seen it being used to an effective way before?
I feel like manager implies that it has behavior, which it sounds like this doesn't, an singleton implies information about how to use that object, not really what it actually does
Very common in game development
At least with unity
Could I use a struct for it
Ah, true. I guess it reads more like a table/database then
Most programs need to solve 'where do i store my objects that i created?' as a first principle. Unity obfuscates that for you by storing your objects serialized in the scene/components/etc , but that system is limited so you'll often end up needing to store your own data as well
In another other case, I'd just make it a struct and call it a day. But since Unity is such a large program i'd like to know if it actually is useful to be struct in this use case
if you want to store references, it doesn't really make sense for it to be a struct (unless it's a ref struct, but I would say keep it simple until you understand those things well)
I mean, in C# you use a struct for exactly that
For storing groups of variables without much code
you sure can, but why would you? that struct is essentially behaving like a class
You can get away with static types, but when you're dealing with scenes and volatile monobehaviour data, then something like a singleton becomes more preferable as you can clean them up with the scenes (or move them to the next so they do get that full static behaviour if you wanted)
It isn't though, is it? It is storing data that is being referenced and used somewhere else
Maybe in Unity's case, it would be a class, that's what I'm trying to understand
structs are value types, but if you store a reference type in there, it's just storing that reference, and if the only thing in your struct is reference types, it essentially is a reference type
this has nothing to do with unity
you are right that practically i'm not sure you'd see much difference
but that being the case, you should do the more semantically correct thing, which imo is to use a class
Okay, yea, thank you guys I see what you're saying
Think I need to redesign what I'm trying to do
sounds like game dev to me 🙂 If you're looking for other approaches, I'm a propnent of pretending that unity doesn't exist and making most of your game/logic in C#, and then mapping that over to unity's stuff to display it
hello all, i've been trying to get something to work for a while, but i'm not sure how to approach this
i have a function which i want to take a gameobject as an argument, a list as another argument, and loop through each child of the gameobject and then, if a certain script is found on a child, add it to the list
this is what I have so far:
private void FindAllComponentHealths(Transform parent, List<componentHealth> list) { foreach (Transform child in parent) { list.Add(child.GetComponent<componentHealth>()); } }
i have a problem, i have this helicopter object that should move when this funcion https://paste.ofcode.org/EVX6s3RGApGSG9gV8LyR4w is called but when called the helicopter stays still and it doesnt move, can someone help?
not good
private void FindAllComponentHealths(Transform parent, List<componentHealth> list)
{
foreach (Transform child in parent)
{
var ch = child.GetComponent<componentHealth>();
if (ch != null) list.Add(ch);
}
}
GetComponentsInChildren also exists
true, but changing the API call will not help OP understand what he did wrong
Yep
is the problem the rigidbody? becouse i tried to remove it but nothing changes
nvm i resolved the problem
You should not be moving via the Transform of you have a Rigidbody
Thanks
ew what are these charactes
It's Japanese!
Hiragana
oh.
i saw that in anime once, cool
i just realized, how do i stop shadows from double casting?
What does that mean?
This is a code channel btw.
oh shoot you're right 🤦♂️ sorry
If you have two shadows then you probably have two light sources
how can i create knockback with CharacterController
You have to manually lerp the cc.Move
Is ew really what you believe an appropriate response to another language is?
with urp 2d, can i make a freeform light bounce off of a sprite?
I wanna have some kind of light that shines through the window and just wanna make it if the players walks infront of that light, he blocks off the light with his sprite
How can i reference and interact with properties of this object aside from the start/awake function?
collider
oh, okay thanks
can i prohibit when player walks into the wall and passing the wall with Physics.CapsuleCast ?
you can store a reference to the progress bar in a field then just use that in whatever method you'd like
Does the player have a collider, and are you moving it with something other than direct teleportation
That's teleportation
That's not going to respect any colliders whatsoever
You are going to need to either move it using a Rigidbody or CharacterController, or manually check for colliders with a raycast and determine if your move is legal before doing it
how i access the child of a prefab
umh could you give me some example? im not sure i understand.
if it helps you understand, a field is a class-level variable
if you don't understand from that, then there are beginner c# courses pinned in this channel
Prefab.transform.getchild(i);
thank you
okay, thanks
Do notice it will give you only transform of the child, if you want something else that's on child you'll have to use get component etc
was about to ask that thank you
why does my character do this
`private void OnLook(InputValue value)
{
mouseWorldPos = Camera.main.ScreenToWorldPoint(value.Get<Vector2>());
}
private void LookAtMouse(Transform Wrapper)
{
var dir = (mouseWorldPos - (Vector2)Wrapper.position).normalized;
if (!flipTowardsMouse)
{
FlipX(dir.x);
}
Wrapper.right = dir * Mathf.Sign(transform.localScale.x);
var eulerDir = Wrapper.localEulerAngles;
eulerDir.z = Math.Clamp(
eulerDir.z - (eulerDir.z > 180 ? 360 : 0), bottomAngleLimit, topAngleLimit);
Wrapper.localEulerAngles = eulerDir;
}`
use mp4 to embed in discord, not mkv. also !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.
how would i make it so a prefabs child gameobject can use the SetActive method
We need some more detail. The child can already call SetActive on many things
i have code in a prefab which has a child, how do set the child inactive/active because ive only figured out how to access its transform component
SetActive is a method on the GameObject class. get its gameobject if you already have a reference to it
You reference the gameobject in the same way you got the transform
every component, including Transform has a reference to the gameobject it is attached to via the gameObject property
character starts drift looking away when not moving mouse
private void OnLook(InputValue value)
{
mouseWorldPos = Camera.main.ScreenToWorldPoint(value.Get<Vector2>());
}
private void LookAtMouse(Transform Wrapper)
{
var dir = (mouseWorldPos - (Vector2)Wrapper.position).normalized;
if (!flipTowardsMouse)
{
FlipX(dir.x);
}
Wrapper.right = dir * Mathf.Sign(transform.localScale.x);
var eulerDir = Wrapper.localEulerAngles;
eulerDir.z = Math.Clamp(
eulerDir.z - (eulerDir.z > 180 ? 360 : 0), bottomAngleLimit, topAngleLimit);
Wrapper.localEulerAngles = eulerDir;
}
Normal, when you don't move the mouse, void OnLook() isn't executed so your mouseWorldPos keeps its last value
ah so put it in a update function?
because c# is statically typed, you cannot change the type of a variable and GameObject is not the same as a Transform
if you want radius to be a GameObject type then make it a GameObject type and just access .gameObject on the first line on the returned object from GetChild
or make it public or serialized and assign in the inspector (this is better)
i cant because its a prefab
Call LookAtMouse() more frequently yes
yes you can. the prefab can reference its own children just fine
Is it being made a child at runtime?
would it not be the OnLook function?
how? when i click on it in my assets folder i cant see the child
Answer my question
double click the prefab to open it up in the prefab editor context
No. OnLook gets called by the Input System, you should not be running that yourself
my LookAtMouse is in the update function
i dont understand what it means sorry
Is the child attached to the prefab before hitting play? Or is it added by code after hitting play
Likely just do what boxfriend said. You will find out immediately
its attached to the prefab before hitting play
wait i think i couldve just used serializefield this whole time
i didnt realise it worked on prefabs
yes, that's what i said to do. and you told me you couldn't
📃 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.
my bad sorry thanks very much
Call it from OnLook() then, if you don't want the rotation to be affected when you don't touch the mouse
Instantiate returns a reference to the thing you instantiate. You did not save that to a variable, so you threw away that reference
brb is not that bullet
Bullet rigid body
lmao Discord has flagged your profile as spammer
Nope
Just on my side?
Maybe the rigidbody of the PREFAB, but not the one you just instantiated
Didn't pop up for me
i see it too lol
Brb is the variable i made for the bullets rigid body
but where do you assign to it?
And you put the prefab in it, I'm guessing
Am i supposed to know something hear
Yes, the basics of unity
Well im very new to unity
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Like 3 days new
Definitely check this out
I recommend the essentials pathway, and then the junior programmer pathway
Thanks will check it out
Your issue is because you are trying to set the velocity of the prefab instead of the gameobject in the scene
myNewRigidbody= Instantiate
myNewRigidbody.velocity =
You have to modify the new thing, not the prefab
wth is this lol
oh okm thanks
I guess I am the only one not seeing it
oh wow lol thats weird
is there a thing that checks when a key is pressed instead of down?
sure is
depending on what you mean by "pressed" and "down"
There's GetKey, GetKeyDown, GetKeyUp
so even if u hold it down it only does it once
GetKeyDown
does it work like that?
Would I lie to you?
no im just confused cause my codes not working
Sounds like a problem with your code
if (!radius)
{
if (Input.GetKeyDown(KeyCode.Space))
{
radius.SetActive(true);
}
}
else
{
if (Input.GetKeyDown(KeyCode.Space))
{
radius.SetActive(false);
}
}
when i press space it just goes inactive again straight away
what can i do?
if (!radius)
{
if (Input.GetKeyDown(KeyCode.Space))
{
radius.SetActive(true);
}
}```
Well this code is simply sure to either not run at all or to cause a NullReferenceException
What are you trying to do?
Toggle it?
yeah toggle it
radius is a GameObject not a bool
Just do this:
if (Input.GetKeyDown(KeyCode.Space)) {
radius.SetActive(!radius.activeSelf);
}```
delete everything else
ok ill try
UnityEngine.Object has an implicit cast to bool
!radius is the same as doing radius == null. If your object does not exist that statement will always be successful
doing if (!radius) doesn't check if it's not active - it checks if it exists
yes i just meant hes trying to use it as a bool but its just null checking
!radius.active then?
No this
I already showed you the way
when i wrote this it told me .active was obsolete in vs
Because it's wrong
I showed you how
aight
.activeSelf as the example shows
right but you said nothing about it being a null check compared to what they were actually wanting to check, you implied that what they had was wrong because it isn't a bool
No need for the outer if statement
could you explain why this works, thanks btw
specifically this radius.SetActive(!radius.activeSelf)
"If I press the key, set the active state of the radius object to the opposite of the current state"
why do I not have the "Convert to FBX Prefab Variant" option?
so i am new to C# and i'm trying to export a sprite, this to be specific, this is the code for it.
using UnityEngine;
using UnityEditor;
using System.IO;
public class SpriteExporter : MonoBehaviour
{
[MenuItem("Tools/Export Sprite")]
static void ExportSprite()
{
// Get the selected sprite
if (Selection.activeObject is Sprite)
{
Sprite sprite = (Sprite)Selection.activeObject;
Texture2D texture = sprite.texture;
Rect rect = sprite.textureRect;
// Create a new texture with the dimensions of the sprite
Texture2D newTexture = new Texture2D((int)rect.width, (int)rect.height);
newTexture.SetPixels(texture.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height));
newTexture.Apply();
// Convert the texture to PNG
byte[] bytes = newTexture.EncodeToPNG();
string path = EditorUtility.SaveFilePanel("Save Sprite", "", sprite.name + ".png", "png");
if (!string.IsNullOrEmpty(path))
{
File.WriteAllBytes(path, bytes);
Debug.Log("Sprite exported to: " + path);
}
}
else
{
Debug.LogError("Selected object is not a sprite!");
}
}
}
For some reason, be it the sprite in the heirarchy or the actual sprite in the sprite sheet, Its not reading it as a sprite for some reason and throws this error. "Selected object is not a sprite". (for debug purposes), Is there a way to export a singular sprite, from a sprite sheet, animations Included? or is that not possible.
when you export an image its not considered a sprite
its a texture
you have to make the texture type a sprite
ah so would I select the warrior_sheet-effect in the heirarchy?
and change the type to a sprite
or would I select the sprite sheet itself
and change its type
you would have to change the asset itself
gotcha
You can use the AssetImporter to modify this in the code directly
not sure how i'd do that 😂
after you save it in the Unity assets you grab its path and use the utility class
I have somewhat example asset that does this if you want to inspect the code
yes please
this is the asset I use it for
https://github.com/navarone77/Screenshotie
but Ill show/send you the code
the asset is a sprite
wait you're trying to extract sprites out of a sprite sheet?
yeah like a single sprite specifically this one
what a coincidence 😅
https://github.com/navarone77/SpriteExtractor
bro has made everything 😂
i make obscure shit that maybe someone might use 
tbh this is stuff that should be built in cause its dead simple
I'd like to add a way to only select specific sprites but I got lazy
you should do that 
if I download this, do I need the code?
not really
try it out and let me know if you dont mind
gotcha
but its battletested so far 🤞
@rich adder forgot to ask cause I was trynna figure it out, how would I install this I know it says it right there but not sure where releases is
ah I should put the link in the Readme woops
you see on the Right side "Releases"
nah thats for copying a repo
ohh
got it
camera clear flags set to none?
would I put it inside the package folder or the project folder itself?
You were right, thank you
did you win solitaire ?
I didn't understand
oh haha only old farts like me probably understand this one
when you used win solitaire
hello
i want to make in my game system where you have to find and collect 10 items, and then you will win, how do i do it?
learn how to add to an integer
learn how to use OnTriggerEnter
is there any tutorials on youtube for this?
im sure there is a youtube that covers collecting items yes
because i cant find it
What part do you not know how to do
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
do the pathways first
tutorials are only worth it if you understand coding enough to understand what is happening and be able to modify and expand the code in the tutorial as needed
you dont really need raycast as beginner to do collecting stuff
simple triggers
yeah im doing it always
but i want raycast not just walk and pick up
so learn raycast
its dead simple
where
the internet
the youtubes
i cant find it in my langauge
translate it
The observer pattern is baked into C# right? I can just use delegates?
I wouldn't call it "baked in", but events and delegates are a simple way to implement an observer pattern
You do still have to do stuff, it's not automatic
it just gives you some nifty tools for handling it
I have another question, I have a character that walks on a tilemap. When I use a Box Collider many times it gets stuck, somewhere I saw that for that not to happen, I should use a Circle Collider, but when I use the Circle Collider, for some reason, the character many times bounces when it moves Does anyone know how to fix this?
do i have to watch all 750hours to learn unity
no they all have different topics
I'm using a reference that has it coded out in classes in C++, but if I can just use delegates I will.
is there russian version of this
maybe ? look around
if you're fluent in the language I got a business proposition for you xD
yeah im fluent in russian
If i recall correct you need to fix this by using a Composite collider
what proposition?
it was a joke. (implying we can make a rus version of Unity learn, i see bigg $$)
oh
It works, ty
@rich adder sorry for ping 😂 you now how I would resolve this error?
😮 well thats..Interesting..I need to look into this one
how many tiles does your spritesheet?
although i test one with over 800 sprites so idk if that is
unless you mean the slice
yeah the slices
no its already sliced.. I meant the whiteboxes
oh not sure how I would check
It could be limitation of the texture method
ill check real quick and report back sry
c#
rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
that didnt work
either way any clue why my character doesnt run?
not with a single line of code no
haha sorry i was pasting the rest
test if the script is even running
how do i do the c# things
📃 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.
also would you mind sending me the image you used and how you did it up to that point ?
private float horizontal;
private float speed = 6f;
private float jumpingPower = 12f;
private bool isFacingRight = true;
private void FixedUpdate()
{
//This defines it so we know that horizontal = the unity setting
horizontal = Input.GetAxisRaw("Horizontal");
//stops them from moving
if (isDashing)
{
return;
}
//Legsanimator.SetFloat("yVelocity", rb.velocity.y);
Legsanimator.SetFloat("xVelocity", Math.Abs(rb.velocity.x));
//the character has a rigid body which has a vector. We are changing the x and y values to whatever our horizontal variable is * speed.
rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
is this the whole script ? send via links
you're missing a lot of shit
also did you verify the code is running .?
@rich adder this is the .png for the sprite, but its mostly an Import I took from unity asset store, also as for I set the settings for the sprite, as for splicing I clicked the sprite sheet window -> 2d -> sprite editor
okay one sec will send a paste bin.
its not that many sprites thats why Im confused on why that happened 😅
really insanely weird....
i reset unity and it started working. I reset it because i couldnt drag anything
classic unity bug
ok this is weird I'm getting the same error now..
I LOVE UNITY!
probably just my shitty script. Though to be fair it was perfectly working when i uploaded it lol
let me test 2021 project, something might've changed in 2022
alright, thank you
Ok yeah I'm not crazy...
we can safely blame unity (kinda)
so it works perfectly fine in unity 2021
something in 2022 changed that broke the code..huh..
so do I revert
if I do transform.rotation = quaternion.identity why doesnt it reset the rotation
public class RotateAuto : MonoBehaviour
{
public float speed_X = 0f;
public float speed_Y = 0f;
public float speed_Z = 0f;
void FixedUpdate()
{
transform.Rotate(speed_X, speed_Y, speed_Z);
}
void OnDisable(){
transform.rotation = Quaternion.identity;
Debug.Log(transform.rotation);
}
}```
how to get the parent of an object you collide with?
you dont reset the floats though
.transform.parent
thanks
I wonder if you're getting one more FixedUpdate
wdym
Probably not, but try logging it
the floats are a constant speed
wait nvm sorry i misunderstood
thats my thought too
but idk how to avoid it
print to find out
how can i get the gameobject?
.gameObject
also, you should still use Time.deltaTime in FixedUpdate so that you the speeds are per-second, not per-physics-update
I discovered a bug in a friend's library when I adjusted fixedDeltaTime 😛
thanks
their code assumed the timestep would always be 0.02
what would be the best way to change sprite depending on where the mouse pointer is (degree rise)
im not getting an update in plus
nope
an interpolated rigidbody, even
darm
i tried to type darn and damn at the same time
Could anyone with Unity6 open test to see if rich text works in the console?
I also have this on an object which looks towards the player
@swift crag like its okay keeping that object looking towards the player no?
Time.deltaTime in FixedUpdate gets converted to Time.fixedDeltaTime
Correct.
If you change the value of Time.fixedDeltaTime, then this code will make the enemy spin too fast
(or slow)
alr lemme know whenever you get to it 😭
i know yeah
i literally have no clue whats happening
what if you make it spin in Update instead?
still incorrect
what the actual fuck is this even
if I set the rotation to 0
why isnt it fucking 0
it keeps looking at the player if I don't turn on the autorotate
which is good
Holy hell it was a simple fix..
you want me to redownload it?
give me a second, i need to upload a new version
Is the object the child of another?
What you'd see in the inspector would be the local rotation
(that'd be the local rotation)
and?
you're setting the world rotation to Quaternion.identity
you're looking at the local rotation in the inspector
If you want the inspector to match what you've assigned, assign it to the local rotation
kill me
they will differ if the parent has a rotation
https://github.com/navarone77/SpriteExtractor/releases/tag/v1.1
here ya go, let me know how it goes 🙂
thanks man
i'll reinstall later
least stupid fucking thing in unity btw
it was my fault sure
but its still stupid
it would be not be useful to see the world position, rotation, and scale in the inspector (partially because the world scale isn't even something you can reliably set for a transform with a non-uniformly-scaled parent)
yea but it looked like it got left at a random ass rotation every time
Hi,
For my 2d game, I've created Physic Material to fix a problem when my player is stuck between 2 tiles.
But I can't assign the material on my BoxCollider, and I don't understand why
Oh , just that , thanks 😦
it does in unity 6
yoooooooooo
@swift crag :))))))
also ty to you Dalphat
forgot to say
i forgor to remove the obs overlay for blender so the player hp is a bit obstructed
o well
I was wondering why you had that thin black bar
blender shows ur file path and it contains my name so i dont like having it there
ngl, im extremely happy with how the UI looks
it took so much pain to get working but at least it looks alright
also my hit counter broke for whatever reason
o well
coming out pretty cool 👍
thank u :)))
i cant wait to make actual abilities and such
im holding back so much because i wanna get the tedious stuff out of the way
like you can see how that kind of gray-ish HP stays after you take damage for rly long
ill probably have abilities which allow you to recover that HP
same for the boss
so you wont want to keep constantly attacking because it can decide to heal back the white part
anyhow sorry for the rant
if (Physics.Raycast (ray, out hit, 100, 1 << 5))
{
switch (hit.collider.gameObject)
{
case slot1:
Debug.Log("Slot1");
break;
}
if (hit.collider.gameObject == slot1)
{
Debug.Log("Slot1");
}
}
Is there a way to make a switch case that does what the if statement is doing? I can't figure it out. The if statement works, but the switch gives this error on slot1:
A constant value of type 'GameObject' is expected
slot1 is a GameObject
why not juse use enums..
because these are specific game objects
i dunno how to use enums, nor did i even know that would be applicable here
but they all can have their own enum with same script just check the public enum type
how do I do that though
like I said I have no idea how to do that
like an enum of game objects?
what?
can you explain what the actual purpose of this is? because it seems like you're trying to make an inventory system, but comparing what was hit to every single inventory slot is a silly solution to that
checking enum field on like an object. not sure whats not clear about it lol
it does sound very silly, yes
but it is indeed doable (:
I have never actually used the when syntax
that is cursed
it is a silly solution to that, but that's the solution I'm going with. Yes it is an inventory system. Instead of changing the entire code of the inventory system, I just need to know how to get this to work
I'm not following a tutorial, I'm figuring it out on my own for the most part
and then you just need to know how to get something else to work, and then ...
you should instead just use TryGetComponent on the object that was hit to see if it has the relevant component you actually care about instead of doing . . . that
98% of this I've done on my own
no like creating an actual class for your object then stick the enum in there
use Object oriented to your advantage
working GameObject class is only useful for specific unity functions
Hello, I'm trying to set the layer of character's head so that the head is only visible to a specific camera which cullingMask i have set to a specific layer, but it doesn't apply that layer. Could someone please help me with this issue?
have you confirmed that the code is running?
sweet! 
also does changing the layer of the bone even affect whether that part of the skinned mesh renderer would be visible to the camera? i feel like those are separate things
yes it does run, i tested that by making setactive false to true
and how have you confirmed that the layer is not being set correctly?
with very long testing using layers that camera is not supposed to see by default, such as the Ignore Raycast layer (aka layer 2)
uh oh
why is that emoji gone
wth does that even mean. how have you confirmed that the object's layer is not being set to the Ignore Raycast layer?
just so you know LayerMask and layer numbers on gameobjects are different idk if you have done that on raycast
InvalidOperationException: Queue empty.
no clue what that means lol
sounds like you might be trying to dequeue on an empty queue
no stacktrace?
so the camera isnt supposed to "see" a specific layer which i set the object to because of cullingmask but that isnt the case
sure, that is not what i am asking you though. you said that the layer is not being assigned. how have you confirmed that
forgot to get it.. and its an intermittent problem
while(totalTime - frameCounts.Peek() >= averageDuration)
{
frameCounts.Dequeue();
}
this is probably the culprit. you can't peek if there's nothing to peek at
ah its your code
its from my rolling average
thought it was unity bug
ohh that smart
so by checking using unityexplorer i found out that the layer is not what i have set it to
i used to switch between two layers but eventually i narrowed down to the fact that something else must be changing it or it does not change at all
just curious whats ping pong do here, like moving the text?
flare
it used to do 1 pong per second.. but i messed up the values
are you certain you are even checking the correct object? also >unityexplorer
modding discussions are not permitted here. #1201856945791705108 message
ohh nice thats cool!
took me forever to figure out the rolling average..
and the Low..
its still not very good imo
what is the recent python install library for mlagents?
read the documentation?
I've
so whats it say
it's installed but outputs error
Hi again , I've some troubles with the Pixel Perfect Camera component.
Explications :
I've created simple game with camera and pixel perfect component.
All my sprites are with no filter and compression none with 8px base.
I've also set Pixel Perfect Camera on 8px.
My screen is actually 2560, 1440 so 16:9.
As you can see , my pixels are ugly and the play mode give me 2 errors (screen)
Someone can give me advices ?
In fact, it looks like aliasing
show sprite import
perhaps share the error and details on your setup in #1202574086115557446
just so you know next time should go in #🖼️┃2d-tools or #💻┃unity-talk
this is a coding channel
while (frameCounts.Count > 0 && totalTime - frameCounts.Peek() >= averageDuration)
{
frameCounts.Dequeue();
}```
seems fine to me. The sprite in your asset looks similar to the scene so im not too sure how it's supposed to look
also your scale is at 5X
it probably wont show accurate
I can't moove it , it is rewrite by pixel perfect camera after playmode
doesnt cinemachine incorporate that already
iirc it works off the original component
Same issue with cinemachine , already test after following this tutorial
Learn how to correctly setup a pixel-perfect camera with Cinemachine. Avoid common mistakes and enjoy a pixel-perfect screen.
✅ Get my courses with discount:
👉 Unity 2D Master: https://www.udemy.com/course/unity2dmaster/?couponCode=NEW-MASTER-MAY
👉 Unity Mobile Course: https://www.udemy.com/course/unitymobilecourse/?couponCode=MOBILE-MAY
👉 Uni...
I still don't understand what is exactly the issue with it
are you talking about the character, the enviroment ?
your reference resoluton should be lower no?
The both are distorned :
Image 1: playmode
Image 2: scene
I see
I understood that the reference resolution must be my screen size, but in any case, I tested with several resolutions and nothing changes
Already test : 320:180 , 1920:1080 , 2560:1440 , same result
Also I've two error on playmode :
that happens when the green dashed lines are outside the green area
The green lines are only present with cinemamachine, which I don't have here
So forgive me, but I don't have any hotline at the moment
If I add a 2D pixel perfect camera rather than adding it in component, I no longer see my game in playmode at all
well ur camera is far below the player srry, discord screenshots
I'm not sure to understand
the camera is probably either too close to the objects or past them in the Z axis. also the orthographic size is incredibly small
since the ground should be in view
Like this ? I've set Z to 0 and move camera + set size to 30
the camera should be at -10 on the z axis for 2d games (typically)
being at 0 with everything else also at 0 means it is too close to the objects
How can I guess that?
well knowing that unity Z is depth
if you're looking forward (Z axis) too close and stuff gets clipped
and knowing what a camera's near clipping plane is
-10 is just a convention. as long as the objects are further than the near clipping plane they will be visible
View is fixed, but same issue for pixel render
How do you do a non axis aligned bounding box cast?
basically Z position need to always be < on the camera than sprites position (eg -10 < 0)
ideally min enough of clip plane too ofc
do you mean a boxcast where the box is rotated? or are you referring to something else
(no it isn't)
look at the documentation for the method
what makes you assume that
wdym ?
well hopefully you've learned the value of reading the docs instead of making assumptions
every camera has a near and far clip plane, eg min distance it starts rendering and max distance it starts rendering
Ah yes then I understood correctly
Unfortunately I'm not making any further progress on my original problem 😢
if you're at 0.3f min distance then you need to be at least that far to start seeing objects
so what happen with new camera?
beacuse its scaling it at 5x
thats wrong
I just tried pixel perfect and mine doesn't scale the gameview at 5x, something is up with yours
I'm the one who puts it at 5 to see if it looks good, is that something I shouldn't do?
oof
thats whats causing the bluring my guy
if you want to "zoom in" you have to change the Pixel Per Unit size in the Pixel Perfect component
i think I hit my word "pixel" daily limit lol
Unity is not able to upscale correctly?
I find it difficult to work on 8pixel without zooming, the final result is quite good but, zooming sometimes allows you to see certain details
It seems strange to me
Sorry for this
The game view scale slider is used to zoom in closer on the game view output
you dont have to put it at 8
You should not use it to adjust how your game looks
notably because that slider has no bearing on the built game
If you want to make your pixel art larger on the screeen, use a pixel perfect camera and adjust its settings
nah is just funny coincidence as earlier had to fix a bug with my GetPixel and SetPixel function 
This is already what I did.
I actually have a good enough eye to see that the pixels are distorted when the player moves, even without zooming.
also note resizing gameview size can affect that error
Yes.
You need to have an even resolution. The aspect ratio game view modes may produce an odd resolution
the pains of 2D
One way to reset this window size ?
in the game view where it says "Free Aspect" change that to your reference resolution
it's quite difficult to see, but I can assure you that the pixels are still distorted here, without zoom and with this setting
put your Assets Pixel Per Unit at like 64 or something and screenshot what it looks like
1st with 64 PPU
2nd screenshot show the difference (like 1pixel on paint) with 8 PPU
oh 🥲
Sorry my English is not very good and there are a lot of things I'm trying to understand it's not easy
my english sucks too but pretty sure that conveys clear enough lol
also we should probably move this in #💻┃unity-talk in thread as not to flood this channel
It looks better with 64 as a parameter
Understand that I don't do stupid things on purpose, it's not in my interest or yours ^^
I have a simple code for capsule colliders on different body parts (to detect collisions for attacks) that are supposed to broadcast the other collider hit to a combat management script, but I'm getting a null reference.
I'm not really sure why it's a null either, as I even tested this method with an if statement (if other is not null then do the thing) but I still get the null reference exception error. Doesn't OnTriggerEnter assign the other to whatever collider enters the trigger collider? How could that become null? I'm probably missing something really simple here wand would appreciate it if anyone could help me out.
no worries, like I said you don't have to keep at 8. I find this sometimes might not be correct size for ALL sprites
but again dont take my word on it, i barely do 2D
So you would recommend putting a larger PPU and moving the camera back, ultimately?
show the line that throws error
other cannot be null
its probably parentCombatManager tbh
just FYI for an orthographic camera, moving it back won't do anything. it's changing the orthographic size of the camera that determines how much it can see
yeah thats parentCombatManager for sure
How can one tell. I would have thought that it would direct me to a line in the combat manager.
because even if Other were to be null by some miracle then it woul still not throw that line as cause, maybe in stacktrace
I understand what you're telling me, but I don't see how to correct it, in this case.
I'll probably make a post on the Unity forum because as it stands, I feel like I'm going around in circles a bit
this event literally gets Invoked with a collider, there is no way it throw you a null collider
There is improvement, but I don't understand that 8PPU on the pixel camera does not give the rendering I would like. Something must be missing
i wasn't providing any information about how to "correct" anything. i was simply making sure you understood that when you said "moving the camera back" that would not have done anything at all
I told myself that, since the rendering seems perfect with 64PPU but far too zoomed, you just have to "move back" the camera to get a good rendering, but from further away. I don't know if it's clear or completely stupid
just using larger PPU on the pixel perfect component that fits the look.
And yeah as boxfriend mentioned, in orthographic moving camera back won't do anything, orthographics have no Depth
you don't have to use 64 strictly though.. was just mentioning it as a starting value to "zoom" play around with another value..
imo as long as its multiples of 8
again, moving the camera physically back does not zoom at all because it is an orthographic camera. changing the orthographic size is how you change how much of the world the camera sees
I think I understood quite a few things, and I thank you. I'll try to dig a little deeper tomorrow, maybe with a post on the full forum on what I did, so as not to pollute more here
Thank you for the help. I changed how I was grabbing the parent combat manager and it's working now.
!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
your IDE should be highlighting the error for you
this'll change to "Assembly-CSharp" when you get things working, btw
thank you
what would be the best way to change sprite depending on where mouse curser is
math.atan seems to not be very good for what i need
might want to explain a bit more what you're doing exactly
also cursor is in pixel coords so if you need world you need convert ScreenToWorld
<Expletive>
when I used to leave my projects with compile errors and open them the next day 😢
are you using Assembly definitions?
i created an empty URP project and then added assets from another project and opened it back
sure. So i have a character and i have created 7 different sprites for him. All for different angles of him looking. For example, i have a sprite of him look upwards which i would like to play when the mouse is 0 to 20 degrees.
i dont know how i would use any sort of math.Atan to grab a value and run a if statement such as
if(angle is > 90 degrees and angle is < 180) { display sprite 2 }
oh so you didn't port the packages
the input stuff didnt import correctly for some reason
ahh
how did you add the assets ?
yeah you would use mathf.atan2
how would i turn the x and y value into something i can use for a if statement
Vector2 dir = currentPos - targetPos;
angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
if (angle < 0) angle += 360;```
