#💻┃code-beginner
1 messages · Page 563 of 1
Sorry, end of work shift so I can't really help anymore
The canvas gets drawn directly onto your screen
An object at X=100, Y=100 goes at that exact pixel position on your screen
wait so anchoring doesnt matter if i do it overlay
It does very much matter -- but you can't try to "line up" UI elements with stuff in the scene that way
Yeah. Generally when changing stuff for a canvas, I find it easier to change the position and stuff in game view because it tends to create the canvas as a large element in random space within scene view
Yeah, you can see how it'll look by watching the game view
What is this text meant to represent?
Okay, so it shouldn't really have a position in the world
It's just going to be a thing attached to your UI
In that case, anchor to the corner it belongs in and then adjust its position as desired
Look at your game view to check your work
While editing an overlay canvas, I'll generally put my scene view in 2D mode, then select the canvas and hit F to view the entire thing
but the thing is
in game view i cant find my text
😭
OH MY GOD
i just clciked something i cansee it now
i v e been blessed
Nice! What was it that you clicked???
its this thing i edited the numbers idk how it works but now i can see a small text
Ohhh. I tend to set that to 1920*1080 then make sure my display is at the same resolution. It's basically telling the canvas how it's going to move/scale each of its element based on screen size
Hello! I have a problem with the resize of gameobjects :/
When an enemy is going inside a certain circle, the enemy size decrease by 30%. My feature work well.
But the result IG is "bugged", there is a little freeze when the object change.
There is a little gif of the obvious behavior
omg guys look guys
Here is my script ^^
Nice!!! I love the art as well btw, it looks great !
thx for helping!!!
I've looked at this gif a dozen times and I don't see any freeze
The change looks pretty instant to me
comparing floats for equality like this isn't a good idea
I am alon e to see the little freeze on mobs ? XD
what you should really do is put a script on the enemy and call a function on it
and just use a bool flag for isShrunk or not
don't mess around with comparing floats like this
Thx for ur advice, I'll update my code on this way!
It looks like the enemy's shrinking for one frame, growing back for one frame, and then shrinking for good
Do you have an OnTriggerExit2D method that restores their size?
If so, I suspect that the shrink is making their collider small enough that they leave the circle
ooh, it's happening many times!
This is a common problem with size-changing effects
I'd call it "flapping" -- rapidly going back and forth
Here is my IN/OUT code
If that is what's happening, then there are a few options
Yes 100% the problem I think
- Don't make the size-change affect the collider's size (just shrink the sprite itself)
- Don't allow the enemy to grow back at all
- Add a delay before the enemy is allowed to grow
A delay is pretty easy to do
You record the time that something is allowed to happen after
delayTime = Time.time + 1f;
Until Time.time > delayTime, don't do anything
mmmmh
Is there a condition in unity like
"full enter" "full out" ?
OnCompleteTriggerEnter2D
Idk x)
I don't think you can ask if a collider is completely enclosed inside of another, no
😢
The hard way, custom function to check if the current possition.x & y is inside the circle scale
Idk which option is the "proper" one
Add a delay before the enemy is allowed to grow
I'm not fan because later I'll have big enemies with slow moves
- Don't allow the enemy to grow back at all
Maybe a smooth move to the circle when enemies size change ?
According to the current size of the enemy
And the current move_speed
aaah not easy x)
You would need to use bounding volumes for this sort of thing.
Test mathmatically if a point is within a given bounds.
Or in the case of AABBs use unity's Bounds struct: https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Bounds.html
Ty i'll look at this 😄
Im stumbling over something which is probably just a simple math function away - how the hell do I rotate a sprite in 2d space so it faces into the direction it's travelling?
myObject.transform.right = theDirection;
how can i get all children of a certain object and then put them into an array?
if it has a rigidbody 2d then theDirection can just be myRb.linearVelocity
Transform[] children = new Transform[myObject.transform.childCount];
for (int i = 0; i < myObject.transform.childCount; i++) {
children[i] = myObject.transform.GetChild(i);
}```
but - why do you need them in an array, you can iterate over them directly from the object
e.g.
foreach (Transform child in myObject.transform) {
Debug.Log(child.name);
}```
oh yeah ur right
the second option is a lot more suited for what im trying to do, thanks for the help!
one annoying gotcha: you must explicitly write Transform there
If you do this...
foreach (var child in transform) {
}
...then child will be a System.Object
for some reason, Transform implements IEnumerable, not IEnumerable<Transform>
im trying to do the expert challenge 2 for the junior pathway and im struggling to get my sliders in the correct position. i put in the coordinates as the instructions said to but in play mode they are appearing at a wildly different place and i have no idea why it could be
can we see the scene view as the anchors and any potential layout groups could be affecting it
Hey, when you interact with a specific NPC you load a new scene. Once you complete the game in the new Scene, you go back to the main game, however i don't go back to exactly where i was when i initiated the new scene, instead it resets the whole game. Any ideas how to fix that ? And btw the sampleScene is the main scene. Just haven't got to change the name yet
If you load go from scene SampleScene -> PuzzleScene -> SampleScene then it will just load the scenes as is, nothing done at runtime will be 'saved'. Are you wanting to re load "SampleScene" but keep some state?
Yes exactly
You need to implement some way to store the old game state of things in that scene, or just load the puzzle scene additively and remove it once done.
Then your sample scene is never removed.
What's weird about those errors? They are very clearly telling you what is wrong.
If you load the scene additivley you need to wait for it to be loaded. If you want to manually activate it then it can only after this load is done (its async).
by default it should activate on load complete for you unless you changed an arg.
the doc page should explain this all and give examples.
- LoadScene will not complete loading until the next frame
- LoadSceneAsync will obviously require handling the async task properly.
Hey there! I am not sure where this belongs exactly so i might try my luck here, if thats the wrong channel please help 😄
So i have a Line renderer which should display 3 Points and i want my White Circle Sprite to repeat along the 2 created lines. But currently it looks like the picture. I need to have a 3d Material in the Linerenderer Material, so i created one gave it the 2d Img as Albedo (Which is a Single Sprite (Texture Type 2D) with Wrap Mode Repeat). On the SpriteRenderer i activated Texture Mode "Tile" and all goes well until the Edge of the Line where you can see it stretches very weird. Ive looked online but i have not really found why or how to fix it. Hopefully one of you guys can help? ❤️
Sounds like maybe you have weirdly scaled your object?
Make sure the scale on the renderer and all its parents is 1:1:1
looks like a classic non-uniform-scaling skew thing going on.
The object the linerender is on has no Children or Parents and is set to 1/1/1 on the scale :/
do you mean you set the texture mode to tile on the LineRenderer?
yes it set it to this
Tiling, Scaling 1 and 1 and left everything i dont know to the default 😄
Can you show the material too?
note that this will cause a bit of weirdness on the actual corner
with no texture it looks right aswell but with the dot its screwed
right, because each line is sheared a bit
oh that is way better yea
One edge is longer than the other, but they're trying to cover the same range of UV coordinates
so it skews
ohhh that actually makes alot of sense yea
Ideally, it would just create a separate pair of triangles at the corner
but I guess it can't do that if Corner Vertices is set to 0!
That is actually exactly what i wanted thank you very much
dang 😄 Happy new year haha
ah, nice (:
The corner winds up having constant UV coordinates along the arc. It doesn't look half-bad with this grid material
In your case, since the texture is transparent at its edges, you shouldn't see anything at all in the corner
yea the corner is just blank
but its not tooo much of a problem for this specific project since its thought as a helper line for where a ball is gonna move towards so the exact corner location isnt that important rather than the reflected angle from the wall 😄
yea thats actually very fitting
I cannot get my raycast to detect the ground no matter what i try:
void OnCollisionStay2D(Collision2D other)
{
string otherLayerMaskName = LayerMask.LayerToName(other.gameObject.layer);
if (otherLayerMaskName == "Wall")
{
Rigidbody2D rb = GetComponent<Rigidbody2D>();
HaltHorizontalMovement();
}
RaycastHit hit;
LayerMask groundMask = LayerMask.GetMask("Ground");
// Detect if there is ground beneath the player
if (Physics.Raycast(
transform.position,
transform.TransformDirection(Vector3.down),
out hit,
(transform.localScale.y / 2) + 0.1f,
groundMask
)
)
{
Debug.DrawRay(
transform.position,
transform.TransformDirection(Vector3.down) * hit.distance,
Color.yellow
);
isGrounded = true;
} else
{
Debug.DrawRay(
transform.position,
transform.TransformDirection(Vector3.down) * ((transform.localScale.y / 2) + 0.1f),
Color.white
);
}
Debug.Log("Colliding with: " + otherLayerMaskName);
}
so far, i have:
- double checked that the ground object actually is on the layer "Ground"
- written the raycast such that it doesn't require a layermask and visa versa
- added Debug rays to check what's going on
my editor setup:
You're using the 3D Physics raycast in your code
but this is inside a 2D Physics collision method
That does not sound correct.
i usually mix them up when trying to help someone with 2D, haha
lol the 2d ptsd
Note that Physics2D.Raycast looks and feels just different enough from the 3D one to be confusing
so pay careful attention to how it works
it is fixed!
here (also omg OMORI PFP i love omori so much :o)
I have a question. I am currently working on a menu navigation for my home screen. I am trying to make it so when I press a button, the program will close the current screen, and selected a certain button. Can someone please help me?
Why what's the issue with your current method?
when I close the menu (run exit) nothing becomes selected
update: just restarted unity, its all working now. idk why it didn't
Ahh right very fair. Unity does like to do random stuff sometimes but at least it works now
ty for trying to help
Go into 2d mode and can you show it and then how it looks in play mode?
And thanks my gf drew it for me!
How do custom game tick rates work
It’s not frames is it? (I kinda have an idea but I don’t get how to use it)
Guys how can i make a 2D object flash as in become brighter for a second?
That's a pretty vague term that probably means different things in different contexts. But no it wouldn't be frames it would be in seconds.
use a coroutine to activate a gameobject with a light component for 1 second
im sorry i never messed with light how can i make it flash that specific object only exactly?
wdym by "flash that specific object only exactly"?
do you want the gameobject itself to glow or to mimic a general lighting effect?
yes i want the object itself to glow
The best way I can explain what I want is Yomi Hustle. Where attacks last frames and then the game freezes so you can pick your next move
then you would probably need a custom shader, or add an emission map and toggle material emission
ill look into it thank you
never heard of it, but yeah basically you would break the game simulation down into frames and you can define how much time each frame or tick takes however you want
it's more or less what FixedUpdate is
easy to make your own as well
Ok that’s what I was kinda hoping
I just need to look into how fixed update actually works. It always kinda confused me
Simple example:
int currentFrame = 0;
float timer;
float frameInterval = 1f/50f; // 50 frames per second
void Start() {
timer = 0;
}
void Update() {
timer += Time.deltaTime;
if (timer >= frameInterval) {
timer -= frameInterval;
ProcessAFrame();
}
}
void ProcessAFrame() {
currentFrame += 1;
// do whatever game simulation should happen each frame here.
}```
Okay yeah that makes since
To add pausing you could just do:
void Update() {
if (!paused) timer += Time.deltaTime;
// the rest...
}```
it's just a number indicating how many seconds each frame takes
in this case I defined it as 1/50th of a second
Okay
I need to understand code format first. I can read it but writing it feels rly foreign still
But that’s good to know where to start with my learning
yes you'll want to have good code fundamentals before trying to tackle this
I recommend https://dotnet.microsoft.com/en-us/learn/csharp
Tutorial hell time
is there anything specific that you don't understand?
I am working on a input system for menu navigation, and I am having some trouble creating a delay in the middle of a script. I read online Invoke and coroutines help a lot in this kind of situation, but I do not know how to implement them. Can someone please help me? (I want the canMoveSelector variable to turn true after a few miliseconds so it doesn't skip any buttons)
{
if (currentSelection != 0)
{
if (input.y > 0.9f && canMoveSelector && currentSelection + 1 < MainInteractions.Length)
{
UpdateColorMain(1);
}
else if (input.y < -0.9f && canMoveSelector && currentSelection - 1 > 0)
{
UpdateColorMain(-1);
}
else
{
canMoveSelector = true;
}
if (currentSelection == 1 || currentSelection == 0)
{
if (input.x > 0.9f && canMoveSelector)
{
UpdateColorMain(1);
}
else if (input.x < -0.9f && canMoveSelector)
{
UpdateColorMain(-1);
}
}
}
else
{
if (input.x > 0.9f)
{
UpdateColorMain(1);
}
}
if (pressed)
{
MainInteractions[currentScreen].GetComponent<Button>().onClick.Invoke(); // run the button's on click event
}
}```
- are you needing this to halt the function's process for a certain period of time, or
- are you needing this to run another process while this function runs?
Is this where I learn code
this is where you talk to strangers if you are having trouble learning code
Ah
I am trying to make the bool canMoveSelector become true after a certain ammount of time. The rest of the prgram should be running while this happens
Yes I am wondering if there's any free courses that teach c# to help understanding I've been stuck in tutorial hell and am unable to script without a tutorial
I did do a script once that worked and it's still in my game
what are you wanting to create?
I started leaning from GMTK. I recomend you check his tutorial to unity
Thanks I'll check them out
I wanna make a multiplayer rts
did you check out coroutines in the Unity Scripting API and the Unity Manual?
And I plan on adding multiple classes in the future
so what have you built so far?
I've followed a tutorial series but he doesn't explain the code very much I've got click select and drag select as well and deselect and when I click the selected object move to the selected point
yeah tutorials tend to do that (not explaining code)
yeah, that's understandable.
Yea one tutorial just said copy and paste this script
have you programmed in c# before making this game?
Yep
I did, but I am not sure how to make that work. A friend built this script for me, and I do not fully understand how everything works in the script. How would creating a coroutine help in this situation? the NavigateMain function is being checked every update, so wouldn't it just restart the coroutine a lot?
join me in a call
i shall visually explain it
Not necessarily making an rts but a somewhat working multiplayer fps and single player horrors puzzle game
okay so you understand how classes work and some fundamental programming concepts
The puzzle game is out on itch but the UI is overcrowded and the puzzle is really difficult
alr give me a second
Not really
Classes are the start function type things right
oooooooo well i can explain some good stuff to know in a call once i'm done with computedduke
oki
You need to drag a GameObject with the script attached to it to the slot, not the script itself
- It's not a public function
- It contains more than one argument
Those also need to be true^
A class is not a function, it is a class which I would say is the "holder" of all of your variables and methods which can be executed in it to get a desired outcome (e.g making a calculator class to calculate addition, subtraction, multiplication, division for 2 numbers), A method like the Start method goes inside of a class and methods are functions which do a specific thing (which in my last example would be a Calculate(float x, float y){}; and would be called in start or update depending on what you put in it).
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/classes
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/methods
Another thing to note, Start() and Update() comes from MonoBehavior, they aren't inherent to what a class is
except in C# we call them methods
yes, here you go
this is the easiest way to understand classes:
- Our game is like the house we want to build
- Classes are like a box
- In those boxes, we can put materials (variables, fields, properties) inside
- We can also put tools (functions) inside that allow us to create our house (game) using those materials
Classes allow us to couple data with methods of manipulating said data in a neat little package.
never coded in my life
need help as im trying to make a puppet combo kind of game
or you could say like Fears to fathom
what specifically are you needing help on?
camera movement. interactions. enemy movement
toggling i guess it says
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
we could hop in vc
sure!
i understand now a class is a script and scripts are the building block to the game
its more that the .cs file is the script itself, but aside from that, yeah
I'm now watching a 1hour explanation on the basics of c#
What errors do you have? What part of your script/code is not working?
There are no voice chats in this server. Just ask your question instead of reserving a single person because you will likely get a better answer anyway
Server doesn't have any (for a reason) . . .
A class is a template or blueprint for creating objects, no more no less.
i just set up a call with
I sent over some resources to get started
it's more accurate to say that a class is an object that bundles data and relevant functions together in a neat package.
since everything in c# is an object
but in terms of unity, it's an object that can then be used as a component for GameObjects
A class is not an object
It defines a type of object
yeah, if it was an object it would be something more similar to Javascript prototypes
I think the blueprint definition is pretty accurate
Just imagine a Class like a Basket... In this Basket you have like Types(enums) Apples, Oranges, etc. with different properties (variables) like string NameOf Fruit .... int SizeOfFruit ... and Methods(functions) what you can do with them... void EatApple(); void EatBanana(); etc...
Also, in what context? Does everything derive from System.Object? No it doesn't, but nearly everything is convertible to System.Object
Methods aren't objects, for example
But we can define a MethodInfo object
the class is simple just the whole Basket with all Info of the items and what you can do with them
class its not an object, its a blue print for creating an object
whats difference between struct and class?
Hey all, im trying to make a generalised abstract class that other classes can inherit to implement as a singleton, this is what i've done:
using UnityEngine;
public abstract class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
public static T Instance { get; private set; }
private void Awake()
{
if(Instance != null && Instance != this)
{
Debug.LogWarning("Duplicate instances of player controller exist");
Destroy(gameObject);
} else Instance = this as T;
}
}```
And in my player controller for example, its being inherited like this:
```cs
public class PlayerController : Singleton<PlayerController>
{
// ...
}```
however when i try to access this singleton in another script:
```cs
public class PlayerTelementery : MonoBehaviour
{
private PlayerController playerController;
// ...
private void Start()
{
playerController = PlayerController.Instance;
// ...
}```
PlayerController.Instance causes a undefined reference exception to be thrown. Does anyone know what im doing wrong?
A struct allocates on the stack, where a class allocates on the heap
The important thing here is that structs, being value types, are passed by copies of itself and classes are passed by reference
What happends here is that if a value type leaves the scope, it's gone
A class is not gone. It has to be collected by the garbage collector when it's fully out of scope
im trying to make a gameobject that when clicked it pops up a ui menu
This makes value types the better choice when you have small allocations and/or want to run fast processes, as you want to avoid garbage as much as possible. However, it's not always the best idea here
Example, a Vector3 is small and a struct. It's used and called often by math so it should be fast
and when ground is clicked it closes teh menu
what is garbage collerctor?
It's an internal system used by .NET that handles the removal of stale reference types that are no longer used
You can look into some of its features with the GC class, but I advice you just leave it alone
In C++ you always had quite the risk of having dangling pointers because in that language there was no GC and you had to make sure pointers were properly disposed of.
.NET has it easier. You can say object referencing through parameters and such is kind of the same as the pointers, minus the manual disposing
does the player controller class have its own Awake method?
Unity just grabs the most specific method it can find and runs that. It won't run both Awake methods
it does yes
Consider making Awake virtual in that case, and then overriding it on the player controller
(and then making sure you include a call to base.Awake()
That makes a lot of sense thanks, but wouldn't this be bad practice? As im requiring myself to always call base.Awake() in anything that inherits from the singleton, and if i dont, things will break
I have a fair bit of code that will malfunction if you don't call the base method, so it's not exactly uncommon, I'd asy
I don't see a way around that if you want to assign the reference in Awake
BTW @fair badge this whole thing with classes and allocation is also why you should generaly try to reuse classes, like through pooling. It's always a very good idea to reuse a class instead of just creating a new one since you just take up more memory and force the GC to collect more stale objects
would there be a better way to assign it then?
I did this for a bunch of objects in my AI system, and it's been great
I do it lazily in my SingletonBehaviour class
i find an instance with FindAnyObjectByType
this doesn't check for multiple instances
do you mind sharing that code so i can see what you've done? I'm not asking in order to be spoonfed code, i just want to try and understand what you mean
https://paste.myst.rs/yt2633tu
Not too much too it -- it checks if it needs to find an instance when it's used.
It has a mildly funny behavior if it fails to find anything
I have Domain Reload disabled, so I need to do some cleanup when exiting play mode -- but objects are getting destroyed by that point, so my instance can compare equal to null
thanks, appreciate the help
how do i make a gameobject via script as in i click a button and it add a prefab to teh scene
couldn't you just do _instance = Find... instead of the Find then the null check? _instance is already "null" there and you'd just be assigning null to it if nothing is found anyway
or is that comment meaning that you are using the other data on your MB that doesn't touch unity stuff?
Right.
It's all stuff that would be irrelevant in the built game
I should check if Application.quitting is raised before stuff gets destroyed
(I'm pretty sure I've also had problems with this during scene unload)
Perhaps you want GameObject > UI > Dropdown - TextMeshPro
So I was originally going to have an array, and then try to have the game keep a list of all the different things that get spawned, and then... I guess just keeping track of it. I'm not exactly sure how to have the player leave and exit a scene but without restarting the scene so I was just going to do this, and forcefully have it manually update each time they leave but
surely there is a more efficient way to do this right?
ok so
I'm not exactly sure how to have the player leave and exit a scene but without restarting the scene
Not sure what that means
Do you want these things to persist when the scene changes or not?
yeah
Okay so for an example, lets say the player goes through an entire section and interacts with everything, clicks on a door to leave, and it'll load a new scene. If they go back through that door to the original scene they just came from, I don't want everything to just reload, but to be in the same state they just left it in.
Okay so you need some sort of save/load system here
It's not the first thing I would tell a beginner to do but most of us need to learn it at some point
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UIElements;
public class Castle : MonoBehaviour
{
public GameObject indicator;
public GameObject menu;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
// Clicks on tower
private void OnMouseDown()
{
indicator.SetActive(true);
menu.SetActive(true);
}
}
I dotn exactly know how to deselect it but yeaa
!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/
📃 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.

huh
its like that huh
Save and load could be a simple json string telling the game which item was what state. But it can also get super complex. You decide for the start what to include.
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UIElements;
public class Castle : MonoBehaviour
{
public GameObject indicator;
public GameObject menu;
// Clicks on tower
private void OnMouseDown()
{
indicator.SetActive(true);
menu.SetActive(true);
}
}
woa
ok how do i add a deselct thing
i guess in my case, at most id need to keep track of
A) Where the player is
B) What areas the player has already been to
C) Their entire inventory 💀
this is for an rts its a summoner tower so its clicked on and a ui pops up
The first two seem reasonably sane but the 3rd just feels like its going to beat me down
Hey there-- for whatever reason my linerenderer keeps bugging out and swapping locations on the 0'th index here. The transform that is attached to the location is not actively moving, and seems to be a purely line renderer thing.
The only thing I can gather atm is that somehow the object parenting is messing it up, but it's so inconsistent that I am unable to figure out what is specifically the issue.
The gameobject labelled bobberstart is placed on the end of the fishing rod, and does not move unless you look around. The only thing glitching around is purely the linerenderer
What is the line renderer attached to?
The fishing rod object-- which also has this script attached
totally irrelevant, but that's producing interesting video artifacts
Oh weird
are you sure that bobberstart isn't moving around? You can pause in play mode and have a look at where it is
I am certain
I've compared the two whilst split screening it and the bobber start object is not moving whatsoever
Yeah
I'd get a gif for proof it's not happening, but it's somewhat hard lol
What happens if you completely stop setting positions in this script?
(actually, just toggle the behaviour on and off)
I wonder if something else is trying to set the points as well
so it's only happening when you move around?
Moving two things separately is never a good idea if they are parented
Ig I don't understand what you mean by that
I'm not moving things that are parented directly really
But yeah I'm really quite at a loss
Bc I'm only reading world position data and directly feeding that into the line renderer
And the thing that is supposed to be moving (the bobber itself) isn't even the thing causing issues lol
Do you have anything setting bobberstart's position?
A very sneaky problem can happen if you use the position of something before you update it. You'll see the correct position in the scene view, but the position will be wrong when you actually use it
I'd try moving this to LateUpdate
Should I use a global pool or a specialized pool for each weapon? Imagine if I have 10 different weapons in the scene, all shooting different types of projectiles, missiles, lasers etc. Should each weapon itself have its own pool or should I use one big pool for all bullet types?
Lemme try it out-- I'll post updates
Consider using Gizmos.DrawSphere to draw a gizmo at the exact position of bobberstart
Gizmos.DrawSphere(bobberstart.transform.position, 0.1f);
This'll draw a small solid sphere at that position
That'll rule out a bogus position
I'm also wondering if you have a rigidbody on the player or on FishingRod
This smells like something that's updating out of sync with something else
It isn't guaranteed that in OnDrawGizmos the positon is the same as in Update/LateUpdate though
Oh right, you have to do that in OnDrawGizmos
duh
Using LateUpdate seems to be solving the issue-- though oddly enough now when moving and casting the rod, it'll move in a strange direction, but I can realistically fix it
That's interesting -- LateUpdate means you're running after rigidbody interpolation, I believe
I recently wrote a "GLDrawer" that I submit triangles and lines to and draw it whenever I want
It uses GL.LINES etc.
So works in builds too
I think the weird casting position is a result of my own implementation though so idt its a huge issue
I appreiciate the help though guys!
Thats a weird desyncing thing though
You'd kind of think that the positions would be finalized when on screen, but ig not 🤷
well that's the thing
If you do things out of order, you can get "off by one frame" issues
oh weirdddd
Are you using a Rigidbody anywhere? if so, is Interpolation on?
I have a rigidbody on the bobber and the player character for which the rod is parented to
I believe interpolation applies between Update and LateUpdate
Yeah there's no interpolation, so that's probably it
So you were getting one-frame-old positions
oh, if there's no interpolation, then that wouldn't be relevant
that shouldn't have affected when it was perfectly still though and you indicated that it would still do that when not moving
The video didn't show that; it looked like the error was proportional to the movement rate
as far as I can tell, at least
it definitely exacerbated the issue yes
Do you mean that it happens both when looking around and when moving around?
yep, but i specifically asked right after they posted the video
not when you're both:
- not moving
- not rotating
It could yes
Moving and rotating both cause the objects to move around, so that would make sense
It would be weirder if it was happening when nothing was going on at all
Sometimes it'd happen when standing in very specific circumstances, but I think that's because there's some slanted objects on the boardwalk which would cause the player position to shift
Just curious, do you have any other active cameras in the scene and/or do you have the scene view open side by side with the game view?
I have one camera for the render texture and one for the fishing rod to make it appear before other objects
Oh well you do have them side by side in the video
Okay, could be related to that, maybe the cameras interfered somehow when the linerenderer is being calculated for each of them
Just guessing though.
I thought about that-- but I think at one point I removed the fishing rod cam and the line also disappeared
And because the component was on the rod, the linerenderer itself was effectively on the same layer (that's my understanding at least)
The exact object the camera is on doesn't matter.
The camera's culling mask decides what layers it can see
yeah thats what i meant
apologies
The culling mask only targets the helditem layer, and the rod and therefore the linerenderer component would only be rendered by that camera then
That's my understanding on the topic
Either way, I appreciate the help for getting it working! I can now finally progress without losing my mind over a line that teleports 😂
I would want to figure out the root cause here
Fair enough
but I don't see anything particularly obvious at this point
yeah-- especially considering even though there may be some difference between the update and lateupdate-- it doesn't make sense as to how far away the positions were when the line was to glitch out
Idk-- I'll come back and share more assuming it comes back up 🤷
I'm using rider and sometimes it tells me expensive method invocation
like how expensive?
I dont get it
It's a very rough guess
$5 per call
/s
it's basically just warning you that you should cache the returned object for that method instead of calling it over and over if possible. you'd have to profile it if you want hard numbers
I don't really like how it marks a method "expensive" when it contains, for example a Debug.LogError in case something goes wrong
But I guess I already got used to seeing those non squiggly yellow-ish lines
what does cache mean
store it for reuse
I have a ton of methods flagged as "frequently called" because they're called by an Update message...even though they'll only run once, ever
i should probably turn off that analysis
how can you do that
well it depends on what the actual method in question is, if it's a method that returns void, obviously you can't. but if it returns some object then you just store it in a variable
like GameObject.Find returns a GameObject and beginners tend to spam that, but you can just call it once and store the returned GameObject in a variable instead of calling GameObject.Find each time you want that specific gameobject
nice
True; any method with a log inside will get flagged as expensive. I've seen methods flagged that didn't have it, but somewhere along the chain, one method had a log in it, thus activating the warning for every method along the chain . . .
in my case I keep using GetComponent
yeah that can easily be cached. though it isn't really an expensive operation per se
it's generally best used when you keep calling the method in update right?
i don't know what you mean by that. but storing the result of GetComponent can easily be done in Start and just reusing that variable so you aren't calling GetComponent unnecessarily each frame
Any GetComponent should be cached . . .
fair enough
does the position of this object depend on the position of the blue green red arrows thing?
set your tool handle to Pivot and the tool handle will be at the object's actual position
https://docs.unity3d.com/Manual/PositioningGameObjects.html
well z can be 0
Can be or will be?
(Vector3) myVector2
okay im stupid
i just realized
omgg
thanks :3
can you not multiply vector3's?
You can - there are three ways to do it
Vector3.Scale, Vector3.Dot, Vector3.Cross
oh i see
The reason the * operator doesn't work is because it would be ambiguous which of the three types of multiplcation you want
hi, i keep getting this error
UnityEditor.SerializedProperty.get_objectReferenceInstanceIDValue () (at <64861216782042de93237b5c061bff1b>:0)
UnityEditor.EditorGUIUtility.ObjectContent (UnityEngine.Object obj, System.Type type, UnityEditor.SerializedProperty property, UnityEditor.EditorGUI+ObjectFieldValidator validator) (at <64861216782042de93237b5c061bff1b>:0)
UnityEditor.UIElements.ObjectField+ObjectFieldDisplay.Update () (at <64861216782042de93237b5c061bff1b>:0)
UnityEditor.UIElements.ObjectField.UpdateDisplay () (at <64861216782042de93237b5c061bff1b>:0)
UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at <9b3502c626dd433da43ca50f8c32f6ba>:0)
UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at <9b3502c626dd433da43ca50f8c32f6ba>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <9b3502c626dd433da43ca50f8c32f6ba>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <9b3502c626dd433da43ca50f8c32f6ba>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <9a95e3c806024daf96fa9e2a7f9d9fba>:0)
in the editor in unity, nothing breaks and everything still works, but it spams the editor and only after i've run the game once and closed it in unity?
hey guys! just a general question, but if im starting out with unity is it better to use 2019.3 or unity 6?
Are you using any plugins? It's an error drawing the inspector of something
Why would you use a 5 year old version?
because most tutorials and the unity learn programming starter guide is from 2019.3!
well, the tutorial seems to be from 2019.3
or a 2019 version, not sure
If you want to do a specific tutorial, it's a good idea to use the same version that the tutorial was written for
But if you want to start an actual game project, using the latest LTS version is recommended
alright! but why? because of the latest features and changes?
Latest features, most supported, most able to build for modern platforms, etc.
plus you can remove the splash screen for free
this is all of them
thank you! ❤️
i did have mockhmd too, but i removed it for testing as it's experimental and nothing changed
Any Asset Store assets?
!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/
📃 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.
please! ^
oh mb
can anyone help me?
im using a slider in settings to change the lens of my cinemachine camera (in 2d) and it only changes after i close the pause menu (so when i set the time back to 1 from 0)
https://paste.mod.gg/xfjvlmfndyna/0
this is the code
A tool for sharing your source code with the world!
none from the asset store but i did download the files from this tutorial
Are you ready to dive into VR game development with the latest tools and techniques? This video is your ultimate quick start guide to creating a VR game using Unity 6 and the XR Interaction Toolkit 3.0. Whether you're new to the VR dev community or a seasoned developer, this tutorial has something for everyone.
Key Topics:
-Unity 6 installation...
hey im wondering if i have to code or anything im making a vr game and i just cant make the controller i have the model and stuff but i cant make it work
What's your actual question?
do i have to code?
I don't know, do you?
im no good at coding
If you want to make a game in Unity you generally have to code, yes.
find one online if you don't wanna do anything, look at the asset store
also, saving something so unity reloads stops the errors too, and they stop in play mode, but they start again when i exit play mode
and when focused inside a prefab in isolation it stops too
when i downloaded the asset where does it go?
this?
click open in unity
The way to add assets to your unity project is from the package manager within Unity
not from the website
It's the Character Controller
(which is a Collider btw)
rect tool dont work on it ?
rect tool is for 2D stuff and UI
isee ty 😘
Hi! I'm trying to make an infinite version of Minesweeper in unity. At the moment I'm just messing with the map generation. I want a seed-based tile map generation that supports local mine density (you will see what I mean soon). I'm generating the maps completely revealed. So my current system goes as follows:
There are two functions that generate the infinite map. One is opensimplex2 from fastnoiselite and the other one is the same function on a different seed but shuffled (previously via trickery with hashes and now it's just a big sine wave with big frequency modulo 1) so that it resembles a bunch of iid uniform random variables for each tile. There's some constant threshold p and a given cell is a mine if the noises added up (open simplex is smooth, the other is just white noise) go higher than p.
The render system consists of a list of chunks that has the chunks that will be rendered, and has a maximum size. Every frame, it looks at the camera corners and removes all chunks that are outside the visible part. When removed, I call SetTilesBlock to set all the tiles to null. After that, it tries to add as many chunks as the list allows, from the visible part. When a chunk is added to the list, I call SetTile to all of the cells in the chunk. Setting the tile requires knowing the tile type (safe or mine) and that requires calling the noise functions from above.
My issue is that this is actually extremely laggy! The functions that use the most cpu (I got that from deep profiling) are the SetTile and evaluating the noises at a given point, with 22 and 17ms respectively (should be less than 16 to run a 60fps). This makes me think that my approach was flawed from the very beggining, because it's not like games can't generate infinite 2d worlds (Minecraft does it in 3d). What is the issue here? Are tilemaps not the right tool? Maybe there are better ways to generate noise? Any help is appreciated!
this here right
package manager
Window > Package Manager > My Assets
this is not the package manager
what after i download it?
then import it
whichever you're interested in
show your console window
do you have the XR package(s) installed?
the vr ones?
Looks like you need the packages listed there and one of the Unity versions listed thre
er wait is this the same package you're trying?
the game's name?
the asset you're using
this
do i have to download all?
seems like it doesn't list its deps
i see one of the errors is for the inputsystem
make sure you've set that up correctly
oh
you didn't install the sdk did you
scroll down and read the requirements. you gotta install the sdk too
no, praetor linked the wrong thing
scroll down on the asset page
alright
where do i get the sdk tho?
it's linked below the template
wait i cant find its name to download it via package manager
make sure you're on the "my assets" tab and that youve added to your assets from the store
this lets it be managed properly
The video is an intro for the Alteruna Multiplayer development package (SDK) at Unity Asset Store. It bridges the gap between the complexity of real time network programming and the artistry of creators in all disciplines.
It is network development for the Unity creators: Easy setup, creation and use with no network coding required! Just drag an...
Is anyone using Rider (personal) fully offline? the wording in their EULA always gives me pause. I am wondering if it works indefinitely, offline
Why wouldn't Rider work offline, that seems unnecessary Actually I remember a conversation on here saying Rider is always checking to see if you actually own it or not (breaking license rules) using telemetry. What did the EULA say?
I could be remembering it wrong though
well, that is the problem. the EULA is worded in such a way as to not make clear sense. it Seems that you can use it offline, but maybe you have to connect for license verification.
and they will do telemetry, but not too much, unless they think they need to, and then you can turn it off, but not really. etc..
Yeah, there have been conversations about it, so you are probably recalling correctly. they have changed the EULA a bit since i refused it last time. it used to not work if you took it offline. that seems to Not be the case anymore, but it works differently for personal vs paid, etc. So, i was hoping someone using personal, who has kept it offline, can tell me that it is working ok
I'm guessing you are talking about https://www.jetbrains.com/legal/docs/toolbox/user/ EULA 6.3 (A), (B), (C)? That's a doozy
Yeah, that one is not terrible, but annoying. let me see if i can find what i was looking at exactly
So you have to generate an offline code to use it offline then you have to generate a new one periodically, so I guess that means you have to come online but then go back offline 
why even allow offline use then lmao
indeed. strange way to do it., but not too terrible. they gotta track ya somewhow! 😛
"you can be offline for approximately 2 minutes before you have to come back online to generate a new code to be offline again"
They have expanded and revised since the last time i read it, and did not agree with it, so that is good. I still wish the data was not held under Czech jurisdiction though. this is a personal thing. not trying to start a political conversation. here is a link the the privacy notice https://www.jetbrains.com/legal/docs/privacy/privacy/
but, in the end, i am just trying to verify from someone who is doing it, that there is not an issue with it, if say, user is in a location without internet for extended periods. Doesn't seem to be a huge issue anymore, but hoping for verification. long ago, it was Supposed to work offline, but did not for me. that is the root of this question
Bumping this.
ooo yeah a bit weird that they do that but yeah we shouldn't start a political conversation, couldn't you use VS or VScode if you have no internet?
or is it a preference thing
That's a hella lot of text for one message. Maybe keep the question simpler for starters and create a thread. It would also help if you share the profiling data(as a screenshot) and the relevant !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/
📃 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.
@steep rose
yeah, no problem there. I would like to utilize the advanced features that Rider has though, so collecting information (in case i end up stuck in Oregon without Internet again :D)
just the original question "Does it work indefinitely without internet" just trying to collect That information 🙂
ah okay, cool 😅
How do i adjust main camera size? I'm trying to make the main menu to a game but I just dont know how to do it
2d camera you just change the orthographic size. 3d camera is FOV, both are also affected by the resolution of the game. set your Game View to the desired resolution
not sure how that's related to making a main menu though?
but also main menu is typically UI, so check the messages pinned in #📲┃ui-ux to learn how to anchor and scale the UI based on the game's resolution
Thanks
where is that exactly?
read very carefully through the properties in that screenshot
im guessing its display or viewport rect but I just want to confirm. is that how you adjust it to your desired screen size?
no, it is literally called Size
How do i delete palettes?
If you mean a tile palette it's just an asset in your assets folder, delete that
when i add in other sprites like trees it always deletes the preexisting tile how do i stop that also when i place sprites into the tile palette it appears like this
use separate tilemaps also this is not the channel to ask this
Anyone know if there’s like a “main way” to resolve complier errors becuase i am so clueless
... what?
what does that even mean
read the error and address it
Like code wise becuase I physically and mentally have no clue how to code
Ok so I finally configured my editor, and I think the problem I have is that I have 3 unused private members
what do I do for that?
that's not a problem in itself, that's just warning you that you have stuff that's not doing anything, which you might have forgotten to remove/utilise
ohh ight
learn to code then
there's resources pinned in this channel
compiler errors are very broad, fixing them depends on what the error is
reading the error message will tell you what the issue is
I mean I can try that
well those three things are supposed to be doing something, not nothing
then make them do that thing they're supposed to do
Am i doing something wrong? Why is the asset not moving?
Is it imported as a sprite? Check it's import settings.
Also next time look for a more appropriate channel. This has nothing to do with code.
is there a manual i can read for c# to know whatever statement or action i write does?
Oh yeah thanks!!
Ok im so sorry
The API docs. Assuming you mean methods and such(the API).
Ok so I just realised that the axis that my player was moving was the wrong one, but the character is still stuck in place
atleast now the speed is correct
void DetermineRotation()
{
Vector2 mouseAxis = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
mouseAxis *= mouseSensitivity;
_currentRotation += mouseAxis;
_currentRotation.y = Mathf.Clamp(_currentRotation.y, -90, 90);
transform.root.localRotation = Quaternion.AngleAxis(_currentRotation.x, Vector3.up);
transform.parent.localRotation = Quaternion.AngleAxis(-_currentRotation.y, Vector3.right);
}
why cant i look left and right? i can look up and down
no errors too
!vs
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
I dont know much about characters, but looking at the values shown there, its clear you are applying movement to the character. But something in your code must be overwriting the movement
void Update() {
player.velocity = 0f;
player.velocity += 1f;
}```sounds silly, but there's not a chance that the code might be doing something similar to this, is there? like at the start of every frame the velocity you added last frame, is erased
ah, I just looked further up adn you posted code before
!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/
📃 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.
private void Update()
{
Debug.Log($"A: {body.velocity}");
float horizontalInput...
body.velocity = ...
Debug.Log($"B: {body.velocity}");```could you put those debug.logs into the start of the update?
alright
I'm confused
I told you to log it yesterday, how come we are a day later and this information still hasn't been shared?
It has been mentioned 3 times
Is this the result?
i was configuring my editor and installing VS took a while, and I forgot to send it here, my bad
these are what showed up, the number juts kept going up
guys i am trying to follow up a tutorial and i cant make see a new project option so i just cloned my new repo now i want to create a solution file and and a folder with a project,it used to do that in vscode but i dont know it doesnt in my
GitHub repository ► https://github.com/TheCherno/Hazel
Patreon ► https://patreon.com/thecherno
Instagram ► https://instagram.com/thecherno
Twitter ► https://twitter.com/thecherno
Discord ► https://thecherno.com/discord
Series Playlist ► https://thecherno.com/engine
Gear I use:
BEST laptop for programming! ► http://geni.us/pa...
like this
like I thought, something is erasing any momentum that you had gained last frame. Best suggestion I can give, add a lot more Debug.Log where each one is clear where it exists like log($"Jump() {body.velocity}") everywhere you alter the velocity
at some point one of those should have a value you dont expect, likely the place that resets momentum
ight, thanks for thye help
How would I implement an attackCoolDown function for when an enemy damages the player? Here is my code:
can any1 help me make a collision script
i always get errors when following tutorials
Try to follow a tutorial and if you face a problem that you are not able to solve yourself, ask here. Just make sure to include the relevant code, errors you get etc.
||using JetBrains.Annotations; using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; public class triggerscript : MonoBehaviour { // Start is called before the first frame update void Start() { Public } public void OnTriggerEnter(Collision info) { if(info.gameObject.tag == finish) } // Update is called once per frame void Update() { } }||
wait how do i show yall my scripy
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/ , https://paste.ofcode.org/ , https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
You can't put that there
I highly doubt the tutorial code looked exactly like that
yeah but they made the trigger a enemy and i couldnt do that
it was pretty old
this is the tutorial
”Enemy” is a string literal as a tag should be. finish is a variable, constant or something else that doesn’t exist.
okay ill try to fix it
Hint ||the double quotation mark might be of importance||
i just made it wayyyyyy worse...
How so?
If this is the way you write c# then I strongly suggest you start with some basic C# lessons before doing anything Unity related
Check the pinned messages for beginner C# courses
Instead of combining learning C# with Unity, start with just C#. Unity is a whole 'nother thing by itself and you will not have a fun time if you have to learn them both at once, and likely waste even more time in the process compared to just doing these seperately
I have issues with changes to SOs not being properly tracked by git, is this a known issue or maybe something I messed up in my settings/gitignore? unsure what the right channel for this is but yeah. whenever I pull from my master branch certain values of them are just empty afterwards, and when I change only those values and try to commit them it tells me that there's nothing to commit
That should not be happening. Make sure you are not selectively ignoring .meta files.
Also make sure you hit Save Project before committing
Other possibility is if you are setting values from code and not updating undo system
I know for these specific cases that cant be it since Im only referencing some strings to put into UI text, but Id like some more insight on this regardless, I didnt know this was a thing
I have run into issues with accidentally overwriting values in other places for sure lol
*.pidb.meta
*.pdb.meta
*.mdb.meta```
could this be the cause?
#↕️┃editor-extensions message
This post goes into persisting changes made by editor scripts
Are you hitting Save Project before committing?
just tried doing that, here's the result
warning: LF will be replaced by CRLF in Assets/ScriptableObjects/LevelData/Level1/Rewards/Pool1Early.asset.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in Assets/ScriptableObjects/LevelData/Level1/Rewards/Pool1Normal.asset.
The file will have its original line endings in your working directory
$ git commit -m "trying to push SO data"
On branch master
nothing to commit, working tree clean
so when I run git add it recognises something changed but when trying to commit it doesnt anymore idk
ty, if anyone has any other ideas feel free to respond to me there in that case
hey, im wondering, what do the colors mean? because the tutorial im following said to make sure that "OnCollisionEnter2d" was blue, but it isnt blue in mine
it looks fine for me as colors might vary depending on the ide
you following bad tutorial then, blue signalise its a method in most of themes, but its dependant of the theme
It means the method is not used anywhere. When IDE is properly installed and supported it recognizes reserved methods that engine uses and do not mark them like that. I think VS Code might still not recognise those properly as well.
You can mouse over as well it will tell you the reason
its saying its unused, i dont think its meant to be unused, but idk how to fix it
make sure that "OnCollisionEnter2d" was blue
well, colors will change depending on what theme you're using
but assuming default themes; methods are yellow in the default
it's unused to c#; unity uses reflection to access private methods, but without that context, it just looks like a private method that you aren't using, and since it's private, nobody else can use it
~~im not sure if/how you can specify that "unity uses it" context ~~
according to fogsight's message above it should know, did you follow the "setting ide up" guides?
Unity doesn't work on Assets internally, it have its processed equivalent to work with.
So any changes you make in Editor wont apply until you hit save or mark the asset of scriptable object as dirty to notify it changed and write back the changes by saving.
theres an error? what namespaces are you using at the top of your script?
"unused" is not an error
the ide just sees 0 references and figures its never being referenced u mean
Just have to make sure that plugin is up to date.
anything can be warned unused if the proper info is given
types, members, variables
didnt know that ive only seen variables
ight lemme check
Also like I've mentioned, if it's VS Code, it struggles with supporting those, might just have to ignore. Still make sure everything up to date
are you on windows here?
That's because you need to configure your analyzer. Right now it just defaults to either ignoring it, or suggesting a refactor that isn't important enough to explicitly mention
You can also change the severity, or assume all warnings are errors. Up to you
what does this mean?
ah i guess i just prefer it this way tbh.. might even take out the warnings for unused variables
no im just starting out and i want to know what it means
is that function call in your own code?
the message is quite explicit
it can "mean" a few things depending on where it's from
i havent written any
if it's from something internal, you messed up config or something is corrupt
If you want my 2 cents I strongly suggest you look into setting up strict analyzers that do warn you of these. It helps with mistakes and it really cleans up code
...ok, but check where it's from
unfortunately so, only my laptop runs Linux as of now. but I think it has been resolved anyways, I may really just not have clicked save project when I was supposed to...
read the stacktrace
what shell are you using? i thought both cmd and ps used > as a prompt?
git bash
hi guys, can anyone help me to figure out how to implement a slower loading between scenes?
the following code works fine but it is too fast
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.SceneManagement;
using System.Collections;
public class RetryLevel : MonoBehaviour
{
[SerializeField] private GameObject loadingPanel;
[SerializeField] private Slider progressSlider;
[SerializeField] private TMP_Text percentageText;
[SerializeField] private GameObject GameOverPanel;
public void StartReload()
{
GameOverPanel.SetActive(false);
loadingPanel.SetActive(true);
StartCoroutine(LoadSceneAsync());
}
private IEnumerator LoadSceneAsync()
{
AsyncOperation operation = SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex);
while (!operation.isDone)
{
float progress = Mathf.Clamp01(operation.progress / 0.9f);
progressSlider.value = progress;
percentageText.text = $"{progress * 100:0}%";
yield return null;
}
}
}
but whenever i try to introduce a delay or a fake loading progress the loading panel stays stuck at 0%
ah, ok. cool
how did you introduce that delay, exactly?
I installed Visual Studio Editor 2.0.22
through unity? idk how it works if u dont tbh
it should work fine provided you follow the appropriate !ide setup steps
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
VS actually had some problems supporting Unity 6
wait, whats the difference between VS Community, Enterprise and the other one?
But I thought they were fixed recently
holy code
for example like this as suggested by gpt
private IEnumerator LoadSceneAsync()
{
AsyncOperation operation = SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex);
operation.allowSceneActivation = false; // Prevent immediate scene switch
float fakeProgress = 0f;
// Initial delay
yield return new WaitForSeconds(2f);
while (fakeProgress < 1f)
{
fakeProgress += 0.005f;
progressSlider.value = fakeProgress;
percentageText.text = $"{fakeProgress * 100:0}%";
yield return new WaitForSeconds(0.05f);
}
operation.allowSceneActivation = true; // Allow scene switch
yield return operation;
}
community is for community (non-specific) use
enterprise is for enterprise (business) use
professional is for professional use
Functionally, virtually no difference, only Enterprise requires license.
ah, alright
not the code, check the stacktrace
yeah put everything in to one file, make it bigger
i don't think that's their code
idk what that is
you're right thats just smth i found on the studio thing
i can't even see whats inside
its only maybe less than half of whats there
...so, that's gonna have a 12 second delay, you sure that's what you want?
click on the error and show the stuff under the error message
i installed it properly now, and its no longer saying the methods are unused
apparently i didnt see the installation steps
still says the exact same thing
nope but is doesnt work
but i found smth in the code thats hightlighted in orange
@tiny wind So currently at least VS 2022 Unity methods support is just fine for Unity 6. So you must have something missing in yours. Go over the IDE install guide that was linked.
Take a screenshot of your whole console with the error selected
for example of what dlich said, like this:
doesnt say that it says the exact same thing as the statement with the red symbol
these notifications keep popping up
actually i think i have the wrong version cuz mine says Visual Studio 17.2.35527
does it literally just show the message and nothing else?
i mean when it makes me go into the studio it shows this with orange
yep
Make sure VS 2022 is set in Unity Editor. There's no reason to use 2017, VS was much improved since then.
which one do i download
just click it, don't double click it
just screenshot the console, please...
whichever is appropriate for your device
oh yeah when i checked the problems tab on visual it showed no problems
those are very different environments
so something's messed up internally
does the error appear after restarting the editor
gimme a sec
just to let you know it started after i downloaded the latest version
latest version of what?
unity
and this is on startup, right? not when pressing play?
yes
ive only found threads about it happening in playmode...
so it fixed itself
nvm i just restarted again and the red message appeared again
try closing all your vs and unity processes and trying again?
ah, the worst kind of error...
yeah its the same one
try #💻┃unity-talk, this definitely isn't a code question, maybe you'll get better answers there
i would close project, remove Library folder and then open project to let unity reimport all assets/packs
how do i fix it
it disappeared ty
this is the start of the problems im going to come across 😭
and i havent even started coding which sucks
seems like something got corrupted during importing then, if something not related to your code generating errors and they persist, then just repeat what i wrote before
oke
Fiddled with Unity's RectTransform, finally understood how they work.
Had a vague idea for a while but had to make my own layout.
Hey, anyone have any idea why my button's " area of effect" is much larger than the button ? if i click either of the four buttons closest to the submit button, it still registers as if i pressed submit. I'm new to this, so maybe it's obvious, but i couldnt find any answers through google
Hi . my player is not teleporting : / why? ```cs
public GameObject gameObject;
public Transform start;
public void OnTriggerStay(Collider collider)
{
if (collider.gameObject.tag == "wood1ded")
{
gameObject.transform.position = start.transform.position;
}
}```
player in inspector to "gameObject" and my point "start"
you modified the way the button looks without also making the button itself scale with it, so you are pressing on submit when you dont mean to because the trigger is much larger than you expect
also not a coding problem, this question is better suited for #🔀┃art-asset-workflow or #💻┃unity-talk
debug if the statement is being called at all
okey
Thank you, and sorry for posting in the wrong. I'll just ask a quick follow up question. What exacty do you mean the trigger is much larger ? I mean as you can see the rect transform is the perfect size
make sure the other gameobject has a rigidbody
also should probably be OnTriggerEnter
what you have selected looks to be the text itself. the button trigger is the parent of the text, and doesnt have the same bounds as the text (based off of the behaviour youre experiencing)
I made this method to get the top most and bottom most of a box collider 2d but it doesn't really work as intended can anyone spot any issue
private float _getTopMostOrBotMost(Side side, bool isTopMost) {
var boxColliderPaddle = side == Side.Right ? _cachedRightCollider : _cachedLeftCollider;
var center = boxColliderPaddle.bounds.center;
var size = boxColliderPaddle.size;
return isTopMost ? center.y + size.y / 2 : center.y - size.y / 2;
}
compare the bounds of the button gameobj and the text gameobj
You were absolutely right! It worked. Thank you so much
What is the diffrence ?
Difference between what and what?
this two pixel art sprites
thank you so much, this solved a my two days headache now
one that work and the other doesn't
One is the inspector for a Texture
The other is the inspector for a Sprite
@wintry quarry does it also work for 2d?
I'm not even sure how you even got an asset that is just a sprite
Everything in Unity is 3D ultimately
so I can just downcast it to vector2
how to turn the texture one into a sprite ?
Change sprite mode from multiple to single
You don't change it into a sprite
You get it to generate a sprite asset
And use that wherever you need it
You are a hero
Sorry another question
how to add the other tow textures to the sprite
Not sure what you mean by that
A single sprite can only come from a single texture
somethig like that
That's multiple sprites from one texture
anyone know where this could possibly be?
That's done by setting sprite mode to multiple and slicing it in the sprite editor
You need to install the sprite package like it's saying here in order to use the sprite editor
ok i will do download it
Exactly where it says it is
In the visual studio install directory
the installer?
No, the directory where visual studio is installed on your PC
ohh, ight
I don't konnw what iam doing 🙂
I mean there's clearly only one sprite in this texture, no?
make sure u sprite is set to Single
So I don't understand why you're trying to slice it
That's 9 slicing
set filter to point and compression to none
Hmm in other words pls 🙂
On your image import settings. They should be roughly a bit more rhan halfway down the inspector when you click your image in your project browser iirc
i can't use other words, these are the words in unity
Bro english is not my mother language
yah i did the filtir
i literally can't use other words, these are the exact words unity will show you
sorry
make sure to apply the settings
@naive pawn my player stuck in one position. i need after touch a block teleport to my position then move still on map but player is stuck. ```cs
public Transform target;
public void OnTriggerStay(Collider other)
{
if (other.CompareTag("Player"))
{
other.transform.position = target.position;
}
}
can u help me?
okey
is this still the loadzone thing
use OnTriggerEnter to make it activate when you first touch the collider
and what's the issue here exactly?
if i use ontriggerenter my player move one time
for my position
i need every time
is your entire level a loadzone?
help, I tried to reconfigure my IDE, but now thinngs like hovering my mouse over code and autocmplete are not there
did you follow the instructions as per the bot message
what loadzone meen?
the trigger you're using to make the player go back to the start
it sounds like it's covering the start position, too
what ide are you using
nvm its fixed now
yes i doing somethink like this. i need teleport for same postion every time on trigger
i was on the wrong IDE
unfortunately, none of what ive done for the past few hours fixed my first problem
character still wont move
can't really help without info
if you've posted about it before, link or reply back to it
this
what's your code
!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/
📃 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.
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
[SerializeField] private float speed;
private Rigidbody2D body;
private Animator anim;
private bool grounded;
private void Awake()
{
//Grabs references for rigidbody and animator from game object.
body = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
private void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
body.linearVelocity = new Vector2(horizontalInput * speed, body.linearVelocity.y);
//Flip player when facing left/right.
if (horizontalInput > 0.01f)
transform.localScale = Vector3.one;
else if (horizontalInput < -0.01f)
transform.localScale = new Vector3(-1, 1, 1);
if (Input.GetKey(KeyCode.Space) && grounded)
Jump();
//sets animation parameters
anim.SetBool("RUN", horizontalInput != 0);
anim.SetBool("GROUNDED", grounded);
}
private void Jump()
{
body.linearVelocity = new Vector2(body.linearVelocity.x, speed);
anim.SetTrigger("jump");
grounded = false;
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Ground")
grounded = true;
}
}
- Any errors in console?
- Show your Rigidbody inspector
wow i have... no idea what to make of that, tbh
make sure you've saved and recompiled
make sure the animationclip isn't setting anything it shouldn't
- no errors
Try disabling your animator for a minute
see if that fixes the movement
oh, it does
i guess this then
im moving again
yep you've made the classic animator pitfall of animating the root object
what
best practice is to put your visual elements (sprites, renderers, etc) on child objects and have the animator only animate those
otherwise the animator is controlling the position of the root object
meaning it won't be able to move
other than how the animator decides to move it
ah, mustve not seen that in the tutorial
You can try checking "root motion" which is a quick fix sometimes but I think it's not best practice
thank uu
becasue you're setting the localRotation of the same object twice
and the second call overwrites the first
presumably transform.root and transform.parent are the same
but how do i fix it
pretty sure you just meant to write transform.localRotation for the first one, not transform.root.localRotation
i don't know why you have .root there it doesn't make much sense
although actually... now that I think about it, several parts of this are weird
Which object is this script attached to?
ak47
uhh what...?
its attached to that
i put this script in ak47 and ak47 in player
This script does not belong on the ak47
thats why it says transform.parent.localrotation
it also has shooting
so i cant move it
Yes you can