#💻┃code-beginner
1 messages · Page 700 of 1
You really are a lost cause
Ah so that's why CSGO doesnt have that issue, it's engine specific right ?
if you think everyone else is doing it wrong, the problem may lay with you
if you're just gonna be stubborn about it, i'm done trying to convince you
void Start()
{
Invoke("SpawnRandomBall", startDelay);
}
// Spawn random ball at random x position at top of play area
void SpawnRandomBall()
{
int spawnIntervel = Random.Range(3, 10);
// Generate random ball index and random spawn position
Vector3 spawnPos = new Vector3(Random.Range(spawnLimitXLeft, spawnLimitXRight), spawnPosY, 0);
// instantiate ball at random spawn location
int ballIndex = Random.Range(0, ballPrefabs.Length);
Instantiate(ballPrefabs[ballIndex], spawnPos, ballPrefabs[ballIndex].transform.rotation);
Invoke("SpawnRandomBall", Random.Range(spawnIntervalMin, spawnIntervalMax));
}
}```Can someone explain why this works exactly? Why is using Invoke in both Start and SpawnRandomBall what I needed to do to spawn the ball at random intervals?
well, specific to the physics engine, not the game engine
but yes
Aight I gotchu, thanks again, I'll run this through my head a couple times to see if I really want to switch to CC
But think about when you were new to this would you rather have people who are putting you down or people helping you with your future
it's basically recursion in disguise
SpawnRandomBall says, once i'm done, call me again after a random time
so it's a hidden loop
the Invoke in Start starts the loop
because each time it runs the method again
if i was not helping effectively, i would definitely want someone to call me out on that
cleaner/type-safe to do nameof(SpawnRandomBall)
coroutine with a while loop even better
also consider a coroutine - would show the existance of the loop much more clearly
-# casually stealing nav's advice
Yeah, the tutorial hasn't taught us to do stuff like that yet. I know about loops because I did a beginner JS course, but I always feel like when I'm going through a course, I should only use what they've taught me
some courses are pretty shit and don't always show you the better / cleaner way
So tell me if I'm right. The Invoke in Start is only actually being triggered once, right? And then it's SpawnRandomBall that's Invoking itself which actually makes it loop. Start is just to get it going the first time?
what do you mean by "type-safe"?
I guess i'll remake my entire movement with a Character controller instead, I dont want to have to fight the engine physics for every movement
I'm doing the one on the Unity site 😂
huh, which one?
Invoke("SomeMethd", time) vs Invoke(nameof(SomeMethd), time)
the latter will give you an error if you mispell the method SomeMethod
strings don't
microsoft javascript lol
well c# is just microsoft java
c# gotta love the statically typed , when possible use that to advantage than ugly strings (js 😦 )
oh god is that why people show up asking c# questions in the ts server
java = javascript, thus microsoft java = microsoft javascript, thus c# = typescript
microsoft doing shit "their way" love it lol
even a shit company can make decent stuff
like github, totally
did they actully create it or bought it out ? forgot
bought it out iirc
ah yea som like that.. i just know m$ copilot being confused with github copilot . the two couldnt be more different (at the time, idk about now)
so that's how i realize they're separate products
in my defense i never touched either lol
from what I know, github copilot at least works with your own codebase / context , microsoft copilot is some pretty garbage shit except for the free Image generation
there is also InvokeRepeating which does not need recursive call, but you you can't change the time each call unless it was a field you modify in that method, gets messy..
sorry i might be miss reading this but are you saying microsoft bought github?
Coroutines are nicer because you can pass arguements, stop specific routines etc. @thorn kiln
no, github
yes, github
when? also is this why there's the git hub ai thing
not to be confused GIT and GIT-HUB
what's the difference :/ only ever used github
Yeah, InvokeRepeating was what was originally used, but the exercise said I should figure out a way to make the intervval random, which they don't seem to be able to do
- see wikipedia, complicated business things
- no clue, but probably related
GIT is the actual technology, software behind
Github is just a hoster
You can use GIT without any hoster and create your own from Hard Drives / home network for example
I'll have to wait until I learn about them I guess 😂
ya basically you will be using them a lot once you learn them, they are pretty handy. besides looping / timing method
git is the system that manages commits and versions and stuff, the actual vcs/scm
git repos are projects managed by git, containing version history
github, gitlabs, bitbucket, etc are platforms to host git repos
git cli, github desktop, and ide integrations are interfaces to access git
i see
Hello
https://nohello.net this isn't a social space, if you have a question just !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 #🌱┃start-here
where is a place i can ask about editor scripts?
Thanks it worked! One issue tho, the saved image looks super dark for some reason
Insead of this
probably a colorspace issue
If i were to guess, it's because of gammacorrection/colour format, but im not sure what exactly is it
Okay i managed to fix it
i changed the colour format of my rnder texture untill it matched
Should I still use FixedUpdate if i'm working with a character controller instead of a rigidbody or do I just use Update and Time.deltatime instead ?
CC relies on a Move every frame instead of doing interpolation between frames, so you'll have to change to Update
Alright, and also what's the equivalent of Linear and Angular Damping for CC, do these not apply at all ?
think CC as a kinematic rb so those have to be done manually yourself
is it worth learning the new input system immediately?
up to you tbh
the sooner the better, but old tutorials still use OLD so its good to know both
knowing how to translate old functions into new will help you greatly
there's a learning curve to it, so learning it alongside everything else may end up being more of a pain
Alright, so I need to know actual physics for that right ?
To add linear damping
I suppose you have to write those functions yourself
Ok thanks, i'll see what I can do
When upgrading my project to a newer version of Unity, is it recommended to run the API Updater when it pops up, particularly with third-party assets, third-party DLLs?
well dlls cannot be modified so those wont work anymore if using old removed unity apis
meaning you need to update these if they break
Well, I guess I'm asking if I should click "Yes" or "No" for this API Updater pop up, if there's a general recommendation. I understand there'll likely be compilation errors that need to be fixed no matter what.
if using source control then do yes
Yes, I'm using source control. OK, thank you.
99% sure dlls wont change so no harm saying yes really
Yeah, I'm not just worried about the DLLs, but also the subsequent pop ups for any C# scripts.
yea it will do the whole project but you will know based on the changes
Quick question, do you think it would be useful to use a layered architecture in Unity? Is that uncommon?
https://paste.ofcode.org/BLyQkDmZi37JP54mctH5Yb How to avoid mini jumps on a slope and stay on the slope because when I move backwards it goes off the slope?
welcome to the complexities of slopes
Hmm, relative to your code.. you're missing an else on line 137
This feels like you have a box collider (not sure of the correct name for 3d) you should be using a capsule collider
This too
gravity usually isn't enough. You need some velocity along the slope to help you stay glued to it
Does this thread become code general in a way?
Since there is no more chat in code general
(also why make threads? isn't that more stack overflow / reddit vibe?)
I unable to find out that why Keyboard space is working fine for jump but Jump UI button is not working?:
Script codes attached to Player object:
using UnityEngine;
using UnityEngine.InputSystem;
public class MobileControlsFunctioning : MonoBehaviour
{
private Rigidbody player;
private PlayerMobileControlsInputs mobileInputs;
private void Awake()
{
//Cursor.lockState = CursorLockMode.Locked;
//Cursor.visible = false;
player = GetComponent<Rigidbody>();
mobileInputs = new PlayerMobileControlsInputs();
mobileInputs.Player.Enable();
mobileInputs.Player.Jump.performed += Jump;
}
private void Update()
{
Vector2 moveInputs = mobileInputs.Player.Move.ReadValue<Vector2>();
float speed = 5f;
player.AddForce(new Vector3(moveInputs.x, 0, moveInputs.y) * speed, ForceMode.Force);
}
private void OnDisable()
{
if (mobileInputs != null)
{
mobileInputs.Player.Disable();
}
}
public void Jump(InputAction.CallbackContext context)
{
player.AddForce(Vector3.up * 5f, ForceMode.Impulse);
}
}
public class test
{
int a = 1;
int b = a;
}
this code produces the same error
basically you cant do that.
cant set a field to another field when initializing
field initialisers can be picky, do you know what constructors are? You might prefer one of those here
yeagh probably
they're basically all set at the same time (when this isn't fully initialized) so it's not allowed to use other instance fields
if this were allowed (ie, decl order mattered) then these 2 classes would have different behavior
class A {
int a = 1;
int b = a;
}
class B {
int b = a;
int a = 1;
}
i feel like if it were allowed class B would work either way as a wouldn't have been a thing until after assuming code executed from top down like when in a function
right, but type/member decls aren't top-down, unlike statements
they all, semantically, exist at the same time
Not to say this is wrong but as a question for how that happens since the cpu is a linear process meaning they wouldn't exist at the same time no?
yes, there is technically/practically an execution order
It’s pretty standard that in initialization the value passed must be a compile-time constant, right? Because the compiler otherwise can’t know what the actual value should be.
but conceptually, members aren't ordered, so language design reflects that
you could totally design a language where A and B don't behave the same, where B.b might be an error or take B.a's default value or be UB
but that would go against typical design - not inherently wrong, just not what people are used to
Oh quick question i was talking to friend that uses java the other day about inheritance, something I've never used cause most class i make are MonoBehaviours so they can't have one so i was curious why c# or unity not sure in this case doesn't let us use multiple inheritances?
oh also practically, to have that behavior, you'd have to standardize/define/specify it
so that's more constraints on a compiler/interpreter/runtime, rather than it having the choice of how to arrange stuff
you're inheriting from MonoBehavior lol
Yeah inheritance is definitely something that can and should be used in Unity
anyways about multiple inheritance - that doesn't really fit the design/structure of OOP
But MULTIPLE inheritance isn’t a thing I think with C# in general
Honestly multiple inheritance just sounds like a nightmare anyway
it kinda exists in both java and c# in the form of default methods in interfaces, so it isn't exactly a practicality issue, more of a design issue
other more dynamic languages like js can use mixins
ignoring this, in terms of design - when you inherit/implement an interface, you only inherit its specifications, its contract
but when inheriting a class, you inherit behavior
if multiple inheritance is allowed, what happens if the behavior conflicts?
not to disagree since i have only looked into them but not used them myself don't they require said function / variable in that class aswell?
so many can get quite roudy
not if they have a default
not sure what you mean by that
Yes the declaration is required, but the definition is up to the implementing class
Although yeah recently there can be a default definition
a default :?
But the original intent of an interface is for the definition to be abstract and only the declaration is concrete
I yearn for multi inheritance and i really want the ability for default implementations of interface functions to be virtual
default impls basically mean interfaces can provide behavior now
oh they aren't virtual in c#?
i thought the point of interfaces was everything being virtual
i see
idk the other languages I use don't have the concept of virtual/override and everything is virtual lol
i want virtual in the context that i want interfaces deriving from interfaces to override default implementations
The main usefulness of interfaces is that the definition can vary
I.e. I don’t care HOW you give me what I’m requesting, I just care that you give it to me
ah, but they just end up as separate declarations?
That gives a lot of flexibility
ye and ide's complain about suggesting you use new iirc
i should look into that more
yeah which is nice when trying to call a function for different object types, ie damage to a player vs a wall
the other wacky thing with default implementations is you can only see them if your directly referencing the object as the interface
well.. unity says we have interfaces at home, it's called TryGetComponent lol
(default impls as the only impl is also "we have multiple inheritance at home")
eg.
interface IWeirdThing
{
public void DebugNumbers() => Debug.Log(1 + 2);
}
class MyMono : MonoBehaviour, IWeirdThing
{
public void Test()
DebugNumbers() //Can't do
(this as IWeirdThing).DebugNumbers() // can do
}
but as a compromise you can be cursed and slightly inject it in via extension like
static void Extensions
{
public void DebugNumbers<T>(this T source) where T : object, IWeirdThing => source.DebugNumbers();
}
class MyMono : MonoBehaviour, IWeirdThing
{
public void Test()
DebugNumbers() //Still can't do
this.DebugNumbers() // can do
}
how do I get this kind of dynamic icon-positioning thing where it creates a semicircle under a specific 2D position, then after it reaches the max amount of icons in that specific row, it creates a new row
what's the part you're stuck on specifically? figuring out the rows, the positioning, or applying the positions, or something else?
i have done no research or attempts at all
there's probably a thousand different ways you could go about this
ok start with that then lmao
.. i dont know where to look
the most obvious solution i can think of is hardcoding offsets but thats a pretty boring solution
try googling some keywords
https://gamedev.stackexchange.com/questions/198372/arrange-ui-images-in-half-circle-180-degrees-in-unity i mean i found this but i dont know if fill is applicable in this specific scenario?
nah some math would be in order to make it look like a clean curve
the accepted answer isn't relevant, they're using uniform segments
oh wait i misread it
that's... kinda a weird solution
but yeah i don't think it's particularly relevant
try googling about like, displaying status effects to start, just to get the system
break this into pieces
If its in UI, you could make your own layout group. Though that's more of an advanced topic than a beginner one.
I've made a couple using classes that derived from the ones in here
https://github.com/needle-mirror/com.unity.ugui/tree/master/Runtime/UI/Core/Layout
could probably extend gridlayout and apply an offset
- accessing status effects and their icons
- rendering them
- splitting it into rows
- making each row curve
- positioning the icons according to the curve
Hey all, I'm trying to enable/disable cameras in a list for a scene but for some reason when the trigger happens I get the following message:
MissingReferenceException: The variable [name] doesn't exist anymore. You probably need to reassign it. This doesn't make sense to me as I am not destroying any gameobjects, disabling them, or removing them from the list. Nor am I doing that to the gameobject this list is attached to. Does anyone know why this is happening?
Here is my code:
` public void OnTriggerEnter(Collider other)
{
Debug.Log("I have been activated");
if (other.gameObject.tag == "Player")
{
imagePlanes.SetActive(true);
switchCamera = true;
walkForwardScript.cameras[0].enabled = false;
walkForwardScript.cameras[1].enabled = true;
}
}`
what line is the error coming from?
and what's [name]
line 38 which is : walkForwardScript.cameras[0].enabled = false;
It's the name of my Camera list called cameras
waslkForwardScript's cameras list might be null
It's populated with all three cameras. Does turning off the component make it null?
Also make sure the WalkForwardScript its checking is the same one that's assigned to that object. Maybe you got another in the scene with an empty list and its using that one instead
I'll try, but this is the only scene this script exists in and it's not a prefab.
Yeah I'm getting the same thing.
maybe I'll just delete this list and make a new one.
I'm going to bonk myself
I accidentally added the script referencing the walkscript on a camera that wasn't supposed to have it. uuuuuuuuuuuugh
Excuse me i have a question, I am currently making a 2D Action RPG game using Unity 2022 and originally for desktop windows but I want to make an android mobile version, how to optimize it for 2D games for android mobile ?
Start from building and testing on the target device. Check metrics like cpu and GPU frame time and if there are performance issues, use the profiler to identify them.
When you know what the bottlenecks are, you can move on to addressing them.
Thank you very much for the info
Hello, I'm looking for some help.
I'm following the beginner 3D course on Udemy.
I'm facing an issue for the moment, I've a cube that start moving when I start the game. (without keyboard input).
public class Mover : MonoBehaviour
{
[SerializeField] float moveSpeed = 0.2f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
float xValue = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
float yValue = 0f;
float zValue = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
transform.Translate(xValue, yValue, zValue);
}
}
Log the x/z values.
How ?
Found the issues, my daughter has played with my Sim Racing steering wheel
It was not the neutral point anymore
is it possible to have a slider in the inspector clamp to whole numbers?
isn't that just an int with Range
i have no idea
chris is carrying
is your slider from Range or from a property drawer
its a property of a float in my shader graph
and i dont see a way to set a min and max when i change it to integer
that wouldve been very useful context to know
i believe unity materials only use floats? this is very much not a code thing though
if you want better answers, ask in the appropriate place
which sounds like it'd be #1390346776804069396
ok
mats can use ints pretty sure
eg. they are used for bools
so iwas trying to setup ml agents in unity i downloaded the sorce for ml agents and also downloaded the python libraries to that but when i open the project it is giving me errors like sentis not found i tried add from package manager com.unity.sentis but that is not working any idea?
I have a problem with my character controller, it totally refuses to touch the ground, whenever I try moving it manually it just teleports up as soon as it makes contact with the ground, which in turn makes it impossible to check for it
Here's the code, and yes it's incomplete because i've just started and want to solve this problem before continuing with the movement : https://paste.ofcode.org/iKkp8kWHUw7mfrEZtQ9pe2
You have an extraneous capsule collider on it
You should not have any extra colliders on your CharacterController
The CC itself is a capsule shaped collider
I tried removing the capsule collider but it didnt solve the issue
It's part of the solution
ah ok gotchu
First remove the capsule, then double check where the CC itself is
The other issue here is just the Character Controller's Skin Width
I removed the collider
The skin width of 0.08 looks like exactly what we're looking at here
What does skin width do ?
So should I reduce it or increase it to solve the issue ?
mb stupid question, I reduced it all the way down to 0.0001 and now it works thanks
why is OnMouseDown() not working for this object, it has a capsule, this is my code (printed inside of OnMouseDown, nohting printed)
OnMouseDown is outdated and doesn't work with the new input system
Use IPointerDownHandler (which requires an event system in the scene and a physics Raycaster on your camera)
I see
what's a resource I can read or watch to understand all about input/mouse input
also, is it reasonable to use an older version of Unity in case it's simpler/easier to deal with it
Understanding all will take months of using them and building familiarity
Not really in my opinion.
can anyone help, when i try to change the sprite of the item thats tagged such it doesnt change, i got a deadline in a few hours
use mp4 rather than mkv to embed the video in discord. also make sure to show 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.
#1390346878394040320 and don't share videos of code, it makes it much harder for someone trying to help you to actually read it
hey, i'm wondering, is there a way to create a Joint2D (in this case, SpringJoint2D) component through code, while also adding an attachedRigidbody to it, i have tried using the codeblock attached below, however i can't assign a value to Joint2D.attachedRigidbody, since it's read only, and i'm wondering - is there a way/workaround to do this?
for (int i = 0; i < pointAmount; i++)
{
GameObject pointA = _points[i];
for (int j = 0; j < pointAmount; j++)
{
GameObject pointB = _points[j];
if (pointA == pointB) continue;
var joint = pointA.gameObject.AddComponent<SpringJoint2D>();
joint.attachedRigidbody = pointB.GetComponent<Rigidbody2D>(); // error: Property or indexer 'Joint2D.attachedRigidbody' cannot be assigned to -- it is read only
}
}
You wouldn't assign to the attachedRigidbody property because it gets that automatically. What are you actually trying to accomplish with this assignment?
yes, that makes more sense. the attachedRigidbody is the one that is attached to the same gameobject as the joint2d (just like the documentation states)
i read it like twice and still used the wrong property lol
i have no clue what im doing wrong
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
public class #SCRIPTNAME#
{
// A Test behaves as an ordinary method
[Test]
public void #SCRIPTNAME#SimplePasses()
{
// Use the Assert class to test conditions
}
// A UnityTest allows `yield return null;` to skip a frame.
[UnityTest]
public IEnumerator NewTestScriptWithEnumeratorPasses()
{
// Use the Assert class to test conditions.
// Use yield to skip a frame.
yield return null;
}
// A test with the [RequiresPlayMode] tag ensures that the test is always run inside PlayMode.
[UnityTest]
[RequiresPlayMode]
public IEnumerator NewTestScriptInPlayModeWithEnumeratorPasses()
{
// Use the Assert class to test conditions.
// Use yield to skip a frame.
yield return null;
}
}
!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.
ok
seems like you're trying to use a template as an actual code file
how did you get that file anyways
assetripper
well for one, go check !learn . the issue is pretty obvious here unless you purposefully edited the code to look like that
and secondly we dont condone asset ripping here. dont post ripped code
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Hello, I need help. I want to destroy this brick with the ball, but Unity is giving me this error message. What can I do?
UnityEngine.GameObject:CompareTag (string)
BouncyBall:OnCollisionEnter2D (UnityEngine.Collision2D) ```
thanks
you don't have a tag named "Brick" but you are trying to check to see if an object has that tag. consider checking for the tag the object actually has
what's the best way to export objects and have their textures tightly linked to them all while using fbx?
this is a code channel
I have tagged brick, but whenever the ball hits the brick or the wall, the error message appears
show the tag
edit the tag and make sure there isn't any extra whitespace in it. after that, show the line of code that the error is pointing to
does soumeone know what the possible causes could be if i can play normally in unity but when i build the game i cannot use one surtein command?
check the player !logs
im a begnner btw
How do you get past hidden code
what do you mean by hidden code
i dont think hidden code is a technical term
we do not help with decompilation here
so did you check the tag for whitespace characters?
Where can I learn decompiolation
now answer the question i asked. did you check the tag for whitespace characters like i instructed?
dont...
somewhere else. it is against server rules to discuss decompilation
yes
Oh sorry
show the tag editor then and ctrl+a the tag to show it does not have whitespace
bro raycats are confusing me, is this not how you check if the raycast hit nothing?
RaycastHit2D hit = Physics2D.Raycast(node, (node - to), Vector2.Distance(node, to), groundMask);
if (hit.collider == null);
sneaky ;
The equality operator for RaycastHit2D is overwritten so you can just do if (hit) btw
this would be the boolean conversion being specified, not the equality operator
I don't know how to do this. I'm a beginner.
so you know where you created the tag? go there. click inside the box with the Brick tag and press ctrl+A to highlight everything in that box. it will then be obvious if there are whitespace characters in it
It works, thank you
I want to create a multiplayer first person game, what is my biggest chalenge as a beginner?
the multiplayer, especially if it's your first game / a game you make while a beginner i would not recommend it
multiplayer is not something you should attempt as a beginner. you need to learn the absolute basics first, then get some experience with making stuff before attempting multiplayer
Why is multiplayer so daunting? Updating states and making animations consistent between a first person n third person camera?
i think you should read up on how multiplayer works if thats what your thoughts of it is
What's some things you can real quick just bullet point regarding multiplayer that you know I'll struggle with?
well the whole handling the RPC (Remote procedure call) basically all the data that's shared with the other computers / server vs what's client sided
Ah ye you're right, its not the equality operator but the implicit conversion operator (which I believe is what you meant since boolean is arbitrary)
If I were to make a multiplayer game, could I first have my game prototype then make it multiplayer? Or would the multiplayer have to be incorporated from the jump and work in tandem with my game?
converting things from singleplayer to multiplayer is very painful, best to have it fron the jump
you'd need to make it from the get go the whole understanding of multiplayer is different than singleplayer
Ty guys
Multiplayer not only changes the way you implement mechanics like mentioned by people here above but there are also several other layers to it that are now not as important with the plethora of frameworks out there but when implementing networking from the ground up using socket programming, real-time applications are infamously difficult
it is specifically an implicit conversion to boolean, and it's not really an operator
Microsoft seems to call them that
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/user-defined-conversion-operators
ah, true
You also use the keyword operator when defining them
but yeah it's specifically to boolean, not sure what you mean by "boolean is arbitrary"
Its specifically to boolean because the specific return type is boolean. But the "function of the language" is overload of an implicit operator, what the parameter or return types are are arbitrary, is what I meant
it's not an implicit operator
it's an implicit conversion to boolean
this one is not arbitrary
the return type is used to define what type it can be cast to
trying to use it as an int doesn't mean it's going to get implicitly cast to a boolean first
I think you misunderstood what I was trying to say
do you think there's like, a single available "implicit operator"
you can define conversions, implicit or explicit, for as many types as you want
Im not sure why you think I'm saying that that's not the case
because you're saying "it has an implicit operator" that happens to return boolean? but that's just not the way it's structured, nor is it how it's treated
Im saying the same thing as you're saying here ^
you're not making yourself very clear
you don't define implicit operators
you define conversions
saying RaycastHit defines an implicit conversion operator is... i guess not wrong, but it's just not useful
Is using Cinemachine for first person cameras good?
I feel like it's kinda lazy n will bite u in the future?
yes
nope its not lazy its industry standard
Damn frl?
Can you access the raw C sharp?
My concern is that it looks not as customizable as if I were to do it myself, yfm?
you mean the source code?
yes it's available, but no you generally won't be modifying the code directly
Ya'll do noob stuff here?
you'd be extending it
and of course using an existing system will be less flexible than making a whole new thing
if you mean questions, !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 #🌱┃start-here
Well, I'm a noob and I wanna do something sonic related. people seem to gatekeep that knowledge
no clue what you mean by "sonic related"
and, well, we can't exactly give you the info you want if we don't know what you want
Coding wise, I want to player movement similar to sonic
3D sonic*
I can't really get the object to move
not sure where you're seeing gatekeeping, i googled "unity sonic 3d" and got several tutorials lol
but i digress. what issues are you having specifically?
are you getting errors, is it not moving as intended, is it not moving at all?
Not moving at all, even asked GPT to help me out
yeah ok ditch the chat bots
I installed the input thingy for controller input as well
Yeah, thats why I came here
input system?
I think so
alright so you're kinda leaving out a lot of context right now
what method of input are you using? Player Input, InputActionReference, etc?
Well, before I go further. Imma try doing everything again
Cause I don't see the script I made anymore
sad
are you following a tutorial?
I was
make sure you're following it accurately - and pay attention to what they're saying in the case of a video, they might mention an issue afterwards
but can't seem to find anything 3D platforming related tho
But I might be looking too hard
i mean, i did just find several with a few keywords as mentioned before
but also - the genre doesn't radically change the movement
you don't need to find a platformer-specific tutorial just for movement when it's the same across multiple different genres
tutorials usually won't teach you how to make your entire game
they'll teach specific aspects, and it's up to you to combine that knowledge into your vision
Yeah, I know that. I used some third person open world tutorial video for a reference
Hi I am currently trying to make a mini rhythm game system in my project, but how can a UI game object detect when it comes in contact with another UI object. I tried the same a approach with a regular game object using colliders but seems like I don't get anything for the Debug Log?
{
public Vector2 Velocity;
private void OnTriggerEnter2D(Collider2D collision)
{
while (collision.gameObject.CompareTag("QTE Icon Checker"))
{
Debug.Log($"{this.gameObject.name} has made contact with {collision.gameObject.name}");
}
}
// Update is called once per frame
void Update()
{
RectTransform picture = GetComponent<RectTransform>();
picture.anchoredPosition = new Vector2(picture.anchoredPosition.x - Velocity.x, picture.anchoredPosition.y);
}
}```
OnTriggerEnter2D takes a Collision2D, not a Collider2D
though, you probably shouldn't be using physics for the timing aspect?
Thanks for the feedback, and also I want to be able to detect it for a start? I was considering using Vector3 but the transform and RecTransform work differently
OnTriggerEnter2D takes a Collision2D, not a Collider2D
Nope no it does not that's OnCollisionEnter2D that takes Collision2D
they are different
maybe saying if its within a range between 2 x points
Has anyone ever tried doing collision detection with UI or checking when they overlap?
shit i need to sleep, i remembered they were different but got it the wrong way around lmao
mb
that doesn't even make sense what was i thinking 😭
Is it a good idea to make my groundcheck a seperate script for general use?
If you have many different objects in the game that need to reuse it, it might make sense to make it a separate script, sure.
if it's only used for your player, it probably isn't worth it
Hey. Im Really Early Learner. I Studied Python at school and im going to coding school in 1 and a half weeks. I want to start learning the basics so i dont have to watch every tutorial. I want to learn how to make the player movement myself
Same
Hey yall so I actually want to build something like the autodesk digital twin (check out the demo version) and I wanted to ask if it’s possible and how do I go about it?
Am I allowed to send links in here? I’ll share the link if I can
If there’s anyone experienced here who can give me a few pointers I’d be very grateful
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Code works but gravity doesn’t-
Help
public class PlayerPhysics : MonoBehaviour
{
public Rigidbody RB;
void Update()
{
if (Input.GetButtonDown("Jump"))
Jump();
}
//Jump Physics
[SerializeField] float gravity;
[SerializeField] float jumpForce;
void Jump()
{
RB.velocity = Vector3.up * jumpForce;
}
//Fixed Update
void FixedUpdate()
{
Gravity();
}
//Gravity Physics
void Gravity()
{
RB.velocity -= Vector3.up * gravity * Time.deltaTime;
}
}```
I'm curious to what tutorial you're following
Some random tut I found, that's related to a game I wanna make
can already tell the tutorial is shite
Why is gravity being done in there 😆
rigidbodies already experience gravity and that can be adjusted too
plus its not using drag or the mass so its just bad
get a better tutorial, or better yet build your knowledge properly through !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
That's technically what I'm doing? I'm watching tuts, and getting knowledge from them. That's how you learn no? Idk how to learn "properly" I'm just starting out.
Don't be mean pls
I'm just not sure why a tutorial would have you explicitly computing gravity when that's already done for you
You shouldn't have the gravity function at all
Probably. That's why !learn was recommended. Most YouTube tutorials are made by people who don't even understand their own code as a quick cash in on a high traffic keyword search
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
fair enough
modifying velocity directly isnt always wise, using AddForce() means we dont fuck up existing forces @lusty bramble
sometimes we do want to modify velocity but it depends on the situation (e.g. you do want a jump to remove existing velocity and push the rigidbody up)
question if i watch the whole 750 hours of free live do i become and pro at this thing named scripting ?
You can make a rocket that crashes into the moon /j
If you watch 750 hours of people golfing do you become a pro golfer?
well you need to like play the golf
i would watch like the first 5 people then start doing my thing
also i-am pro at playing Rainbow six siege and i only watched 3 people
Probably not no, but it would likely help a lot
Making games skills you up the fastest imo, even if they are as tiny and basic as possible
Being good at programming (again imo) is less about direct knowledge and more about experience in researching, thinking, problem solving, troubleshooting and failing 😄
tell a person a solution, they know what they're doing for a brief period
tell a person how to find a solution, they know what they're doing for an extended period of time 😉
yes , you smart
i like how you think
how did u learn how to code on unity?
with my hands
Tutorials on YouTube or the website?
idk i just watched my buddy do it
Alr
I'm js finding it hard to choose which method should I use to learn
i like your name
wanna learn together
Can you tell me what this is about? there is nothing on the stage and there are still such errors, the unity version is 6.1 (6000.1.10f1)
sure
Why 2nd variable of scriptable object periodically resetting after changing scripts? I don't touch SO script at all but cur amount just resetting from whatever number i set to 0. I don't think that problem in my scripts bc it's happening before i start the game
how did u learn unity?
I have 4 string vars and 1 for sprite and problem only with cur amount*
do you perhaps have anything in OnValidate that may be modifying it?
you've already been directed to where you can learn to use unity in the first channel you started spamming this question in. so take that advice and go start learning instead of spamming that question everywhere
I don't have any OnValidate methods in any script and there's whole SO script
using UnityEngine;
[CreateAssetMenu(menuName = "SO/InventoryObject")]
public class InventoryObjectSO : ScriptableObject
{
public Sprite itemSprite;
public string itemName;
[TextArea] public string itemDescription;
public int maxStack;
public int curAmount;
public virtual void Use()
{
Debug.LogWarning("Base items have no use method");
}
}
If anything modifies the values on the SO asset in the editor, it saves to the SO file, meaning anything else that uses the same asset gets modified in turn
Just for the reverse kinda info, unless it’s a rare bug Unity won’t be the one doing this
or if any code is modifying it at edit time but not also dirtying it that could also make it reset
I don't think i did something to change it before game start but will check it, thank you
if you're certain no code is modifying it then try restarting the editor and see if it continues happening
Nah, it's probably flawed code bc i've same error few days ago and it's still here
nah
you should give #📖┃code-of-conduct a read instead of spamming your inane question over and over
well if it's code then it isn't the code you've shown 🤷♂️
Short question (I think) - for a game like ping pong with touchscreen, what's the approach to making the ball go faster the "harder" you hit it? By indexing where you've started touching the screen and how fast you moved it?
Easy way to see if anything's modifying it, make it private and see what throws an error
best way is to use all avenues available
alr thanz
figure out what exactly it is u want to do. and go find resources and try it out asap
Guess i found out reason of reset but can't say for sure until i'll see if error persists or not
probably could just check the velocity of the paddle..
more velocity = stronger hit (if u wanna do it taht way) input mode would be irrelevant
I see, thanks!
https://paste.ofcode.org/Eex3bRfgXbAxT3Xux4vrJkPlease help me avoid those mini-jumps and how do I keep it from going off the slope when going down it? I don't know what's wrong with GetSlopeMoveDirection.
Source Code Available on GitHub: https://git.io/fAVCV
This tutorial focuses on providing a simple solution to rectify problems with bouncing/jittering that you may have when your FPS player walks down slopes.
i used this video to understand the slope issue and solved it by applying a constant downward force
if airbourne my gravity was downwardVelocity += gravityConstant;
if i was on ground or (slope) my gravity was if(downwardVelocity < stickyGravity){downwardVelocity = stickyGravity)
so when im grounded my gravity is = usually around -14 or so.. (helps smooth slope walking)
and when im not grounded (say i fall off the top of the ramp) it zero's out the velocity and starts applying the += gravity
ooo TY
Hello I have a question, i am trying to instantiate an object using Instantiate(smallfish, transform);
How can I make it so the object spawns higher than the reference
Whatcha mean by reference? Hierarchy?
the thing the script is attached to
This form of Instantiate you are doing makes the new object a child of the object the script is attached to
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
So there's a list of declarations you can reference
simply omit the second parameter and it will spawn at the root of the scene
is there a way i can make it spawn a bit lower than the object the script is attached to
basically i have a fishing rod and I want a fish to spawn a bit lower than it is now
Can you explain what you mean by "higher" and "lower"? You mean the physical position of the object?
or do you mean the order in the hierarchy window
yes
Use a form of Instantiate that takes a position and rotation
then you can pass in whatever position you want
refer to the docs
My Unity grabbable object's mesh collider is interfering with the rigidbody physics during the drop animation - the collider gets enabled while the object is still transitioning to its drop position, causing collision issues with the player, and the player mesh goes below the ground somehow while the collider stays the same . How can I fix this. ``` private void StartDropAnimation(Vector3 dropPosition, Action OnComplete)
{
Vector3 targetScale = Vector3.zero;
LeanTween.scale(gameObject, targetScale, pickupDuration)
.setEase(pickupEase)
.setOnComplete(() =>
{
transform.SetParent(null, true);
LeanTween.move(gameObject, dropPosition, 0.1f)
.setEase(LeanTweenType.easeOutQuad)
.setOnComplete(() =>
{
rb.isKinematic = false;
rb.useGravity = true;
if (meshCollider != null)
{
meshCollider.enabled = true;
}
ResetToOriginalState();
OnComplete?.Invoke();
});
LeanTween.scale(gameObject, originalScale, pickupDuration * 0.3f)
.setDelay(pickupDuration * 0.1f)
.setEase(popEase);
});
}``` If I set the duration to 1.5 in the move tween, I don't face this issue.
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);
this one?
yes
Oh yeah you probably want to add some offset the the position
so transform.position + Vector3(0, -1, 0)
or if it's 2D
don't enable the Rigibody/collider until after the tween is done
LeanTween probably has a way to pass in a lambda to run code at the end of the tween
I know DOTWeen does
i dont know what a lambda is but i will look into it
- The position is one unit below the world origin. You probably want something relative to your spawning object, no?
- That quaternion is not valid. Try Quaternion.identity for "no rotation", or
transform.rotationif you want the same rotation as your spawner object
Oh i thought the values were relative to the object the script is on
no
Instantiate is a static function
it has no idea about anything like that
it only knows what you give it
how can I get the transform from the spawning object?
transform
as you have already been doing
if you mean the position, that's transform.position
Don't confuse the Transform component itself with things like the position and rotation
Instantiate(smallfish, transform.position + Vector3(0,-1,0), Quaternion.identity);
Why is there a red line under Vector3
new it
new Vector3(0, -1, 0)
Good time to learn some c#
It's calling a construvtor/creating new instance.
i remember learning a bit of this in ap comp sci a
But i forgot
fuck its lowkey just not working anymore
😔
Well, see if you can debug the problem, otherwise feel free to post the script
All i did was change Instantiate(smallfish, transform);
To Instantiate(smallfish, transform.position + new Vector3(0,-1,0), Quaternion.identity);
;-;
What about it doesn't work..?
the fish is not showing up anymroe
Do you get any errors?
Then it must be instantiating somewhere. Pause your game after it's instantiated and inspect the scene/hierarchy
ok
oh wait
I found the fish
But this is not doing what I intended it to do
Now the fish is just spawning at that slightly transformed position and staying there
I want the fish to spawn slightly tranformed but continue moving with the hook
Sounds like you need to parent it to the hook.
It isn't in the hierarchy right now
Via code..
hm how to
Refer to the documentation 🤷♂️
https://docs.unity3d.com/ja/6000.0/ScriptReference/Transform.html
player.transform.parent = newParent.transform;
transform.parent = smallfish.transform;
?
Also, there's an overload of instantiate that allows to do it too:
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
You want the small fish to have the hook as the parent.
what do i refer to the hook as?
The script is attached to the hook btw
things need tags to be referred to in code right?
I also suggest you go over the beginner pathways on Unity ! learn as they cover all of these basics.
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
No.
If the script is attached to the hook, then you can assign the transform as the fish parent.
It should.
But anyways, these things are really simple to solve if you k ow the basics, so you really should go and learn properly.
you need to modify the instantiated object not the prefab
ok
also ideally you would use the SetParent method rather than assigning to the parent property
sorry how do i refer to the instantiated object?
Instantiate returns the object, store that in a variable for reuse
and like dlich said, Instantiate also has an overload that allows you to assign the parent
why keep coding when you can ask Copilot ? 
typically people want their code to work
someone can help me i have been all day trying to place a 3d trree in unity and not mater how matter i try every free i dowload say that there is not a render or there is not prefeb i do not know if it is a bug or what to do. I already downlaod universal render pipe converter and nothing
that's a portal what you're selecting
yea but it is nothign
aa
there are beginner c# courses pinned in this channel, perhaps you should start there if you don't know how to declare a float literal
Unity mostly uses floats, not doubles. What you have there is a double. And doubles can't be implicitly converted to floats.
Anyone know why this is happening
So i added a fish to the scene and made it a child of the hook, i transformed it until I got a position i liked
and i got these coordinates
but when i add this to the code it spawns like insanely far away from where i want it to
dont deep nesting tweens for the purpose to chain them with OnComplete, chain them properly using LTSec api
LTSeq sequence = LeanTween.Sequence();
sequence.append(LT.value()/scale/orWhatever);
sequence.append(LT.move()/scale/orWhatever);
sequence.append(LT.delay()/scale/orWhatever);
squence.start()
much easier to manage, and you can do LT.cancel(obj, true) without messing up the tween continuation
Is it patented to the hook?
I think so, thats what the line below is supposed to do
GameObject fish = Instantiate(smallFish, transform);
fish.transform.localPosition = new Vector3(your position);
You're positioning it with a world-space offset
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
It can, but Vector3 doesn't use doubles
Hi, I have some quaternion that rotates something clockwise when looking down at it from above but the angle axis vector points up. Are quaternion axes opposite to the axis of angular velocity?
ty ty this helped me solve it, jsut need to fix the timing
To anyone who just got stuck like I did, especially with mouse not being detected even with a collider to some objects:
Edit -> Properties -> Player -> Active Input Handling -> Both
anything less the 1-second duration on this line of my code
sequence.append(LT.delay()/scale/orWhatever);
causes the issue again, and with a 1-second delay, it's janky.
How can I constrain a generic to just if it implements a given interface? i don't care if its a class or struct etc. but i don't want new() because it has param constructors
I fixed it by always smoothly tweening the palyer mesh to 0 on the Y axis eveytime the tween sequnce finishes
If you just want a given interface are you sure need a generic?
anyway you can do:
void MyMethod<T>() where T : MyInterface```
hello
how do i use the quaternion.euler
Can i simply just do quaternion.euler(0,0,90f)
You call it and it returns a Quaternion based on the angles you gave it
wait so i can just do this?
the thing is i tried this but it did not work
Like why does this not work
GameObject fish = Instantiate(smallfish, transform.position + new Vector3(0,0,0), quaternion.Euler(0,0,90));
fish.transform.parent = transform;
because you're not capitalising things correctly? Does your IDE have proper autocomplete and error highlighting?
!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
• :question: Other/None
holy fuck im gonna crash out
20 minutes for that and all i had to do was capitalize the q
💔
Question, if i click play in unity
And start moving an object around
Is that local or world
What you see in the inspector is always the local position
and in code its world?
the position local to the coordinate system of the parent
position is world/global. localPosition is local
fish.transform.localPosition = new Vector3(your position);
So what values am i inputting in "your position"
local or global
from my understanding, if I transform the fish in the inspector, im getting local positions. Then i input those local positions into the code that i just sent and it should transform the fish as much as it did in the inspector?
I did it
and my fish is in the middle of nowhere
Wait wouldnt it need to be +=
Because rn when i set it to 0,0,0 it just puts it at the 0,0,0 in the game
@north kiln brotato chip pls help
i tried everything that i think makes sense and its still so off
Please refrain from continually pinging me into this, and post your updated !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.
A tool for sharing your source code with the world!
The code is hella cooked
{
GameObject fish = Instantiate(smallfish, transform.position + new Vector3(0, 0, 0), Quaternion.Euler(0, 0, -90));
fish.transform.localPosition += new Vector3(0, 0, 0);
fish.transform.parent = transform;
//0.425f, -0.013f, 0
}
I think this is the only section u need to look at tho
the rotate works but the transform doesnt
Why is your code not just what I posted #💻┃code-beginner message
+= new Vector3(0, 0, 0);
1 + 0 is still 1.
this line is pointless
except with the position mentioned in your first screenshot
its supposed to be the commented out part instead of 0
But even when it was it still didnt work
bc here u just used transform and i wanted to use rotate as well
Quaternion
GameObject fish = Instantiate(smallFish, transform);
fish.transform.localPosition = new Vector3(0.425f, -0.013f, 0);
fish.transform.localRotation = Quaternion.Euler(0, 0, -90);
yeah idk its not working
what's it doing then?
the rotate works but its not tranforming
then you are transforming it elsewhere
Are state machines used only for AI?
no, they also get used in animation, fighting game combos and many other places
The sub state machines? Is that the same thing?
UI, etc. Anything that has state could use a state machine
Ouu I see
So if I learn state machines I could understand the animation sub state machines? Cuz once I used them it broke many animations lol
There are barely any videos on that tho🥲
state machines are just a way to group your logic so you're not running around with thousands of if statements
🙏
Oh should have I used it in all the scripts instead of making functions for every thing?
you can actually run into similar issues you find with OOP with state machines if you don't group it all correctly
Damn I’m gonna have to re write everything🤣
I’ll see if I can find somewhere to learn about it
Does the official Unity tutorial cover it by any chance? I really liked all the lessons I did there
You'd want a combination of both, states and methods
How’d you choose what to use for what? Or that comes from experience?
Also would that make the code less messy? Because grouping logic sounds like it’d look nicer
mostly comes from experimenting. just trying something is the easiest way to figure out whether or not it will work.
I'd look at it as an alternative to just doing if-else statements as for one it's much cleaner that's for sure.
Anyone know why my line is behaving like this
I have the 1st point set to the tip of the fishing rod and the 3rd point set to the hook
But for some reason it is so far away from where i want it
I see I’ll definitely look into that then because my code is so messy with so many functions and interconnected scripts haha, getting hard to manage🥲
Thank you both❤️
you still seem pretty new to all this. maybe consider checking !learn or some other courses before jumping right into making your own game. learning each of the components one by one is going to make it a lot easier to spot which is causing the issue.
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
but there's also a lot of things that could be causing it and it depends on exactly what you mean by that
if you mean why it looks that way then it's the material
if you mean the part that's clipped off then it's probably some object in front of it that's blocking it
issue is i do not have much time
Like i need this thing done in 2-3 days
otherwise i would try to actually learn
i highly doubt you're going to have this done in 2-3 days
I just need it to be the best i can
Yea tbh as a beginner it takes a lot of time, today I implemented 6 animations and player movement logic and it took me 15 hours💀
Is it for like a college project?
yeah, when you're doing things for the first time it takes significantly longer then it would take for an experienced dev.
when i first started it took me weeks just to get some basic movement working. now i can easily program some pretty complex systems within a couple days
If you don’t care to understand what the code does then chat ChatGPT and pray I guess😅
already tried that
still a good idea to check learn. all the basics are pretty much a requirement for continuing further
Chat gpt is buns
That’s amazing! I’d love to get to that level haha, I’m starting to get familiar with coming up with the correct logic but I still make a lot of mistakes haha
Most of the time today of these 15 hours went to learning the whole animator thing because I was scared to touch it before 🤣 but I found a website where you can import animations so that gave me a head start
I don’t even wanna think about touching Blender😭
animation stuff is scary and cursed
Fr I hate it😭
Connecting it with all the arrows was hell so I used the trees and state machines and then it broke
you'll get there eventually, just takes time 
And I spent too much time and wanted to get other issues done so I can make progress lol
its easier for me to make stuff on fusion 360 than blender
Like even stuff that doesnt need to have measurements or anything
Idk why blender is so complex
Is that like a 3D design software?
cad software
blender is pretty crazy to jump into
Ooo imma look that up thank you
i've been doing dev stuff for like 5 years and i only just got into learning blender 
its useless for game dev
Oh god haha, how is it going?
I guess if I ever sell a video game I’d just outsource modeling and animation
I just wanna code🥲
well, it's going a lot better now that im doing simpler models that i actually need. i used to keep trying a bunch of stuff that were way out of scope like animals or big detailed buildings. I'm finding it a lot easier to just do some basic things like furniture, tables, chairs, ect.
That’s amazing! I’d be surprised if I can pull off a stick man🤣
Yea but like could you make money off of using them? That’s just for prototyping no?
kenneynl's license is so unrestricted you can re-sell it all directly iirc
Woah
(dont do that lol)
🤣🤣
if unity runs on C# does that also mean that switch are better than if statements if they get too long?
I can’t sell anything anyway I’m on a student visa🤣🤣
switches end up compiling into ifs iirc. the best solution is to reduce the amount of switches/ifs with better composed code
Yes, you generally want to use switch statements if you have that many cases regardless of the programming language
Lol the reaction is ironically my visa type
F-1
but yeah highly recomend kenneynl's and kay lousberg's assets for prototyping
confused whats going on here, i pretty much just copied the documentation
I’ll look into that too thank you! I imported a model and some animations from Mixamo
mixamo cool too yeah, you can even chuck some of their stuff into mixamo 😄
You have two imports that both have a class named Random. It's asking you which one you want
i've seen a couple things about kay lousberg's assets. i haven't checked them out myself yet. should probably give them a look sometime 
They are very nice and high quality yee
Some of their stuff is paid though
they do free packs + cheap paid bonus versions
looks gorgeous though
Wow that’s insane
Oh, oh wow
That's... Really really good
oh yeah for sure. i think i remember seeing another game that uses that.
-# i'll try not to drag this on aswell since we're getting a bit off-topic 
Jesus only $15 for even the blender files?
What the hell have I been paying Synty for
50% right now too
If this sale is still going on tomorrow I'm gonna go absolutely buck wild on those asset packs those would make for some fantastic prototypes
what are you paying for?
pain?
They also do this weird but cool patreon exclusive thing where they drop characters monthly but also you can just buy a seasonal pack outright. some of them are pretty specific but if it happens to cover a relevant project it seems goated
i have this santa's workshop prototype i was cooking for government funding that i really need to go back to now that Kay made these really cute elves
As a programmer without much in terms of artistic skills, most of my concepts are in the form of graybox pitches and better looking prototypes means better first impression and potentially more funding
Also abit smaller nicher and newer but Kay has a sister who also releases assets
https://tinytreats.itch.io/
cool peoples
Kay's got some cool stuff. I heard they made it all using Kenney's asset tool
also all their assets use vertex colors, no texturing at all
Does the fish instantiation only exist within the ontriggerstay?
I wanna delete the fish once its been reeled
fish is a local variable within OnTriggerStay, make a class field out of it.
you make it local here but not in the exit method...
what do u mean by exit method
Same way as with your timeFishing or hasFish, these are class-level
okay
in ontriggerstay you create a local variable with GameObject fish =...
but this var doesnt exist in thex on exit method down
caesar already gave them the correct answer for what they want to do, what you're suggesting wouldnt destroy the previously created object
Make it private instead of public.
You don't need it exposed to the inspector
You set the value via instantiate in code
i can just make it private by not putting public right?
Why does time fishing start at 3 when i start the inspector
A tool for sharing your source code with the world!
Because that's what you must have set it to initially, or it changed if it's during playmode
changed during playmode would not affect it if they are not in play mode
Do these fields even need to be public? Besides the 3 prefabs.
I have it set to 0
in my code
But if i stop my playmode and start it again, shouldnt it go back to 0?
Doesn't matter what's the default value in code if you serialize it
field declarations like that run when the object is originally made, which is when you added that monobehaviour as a component
reasonable confusion
Make it private if you don't want the serialized value in the inspector affect it
wdym serialize it
public fields are by default serialized, in simple terms exposed to the inspector and editable from there
Whatever value is there it will replace the original value when the game starts/object spawns in
I just like public variables bc i can see whats happening easier
To explicitly serialize a field you'd use the attribute [SerializeField]
You can also see what's happening if you debug the value or switch the inspector to debug mode.
that will be serialized tho
What will be?
First time I ever hear about that
Ideally you use a debugger to debug instead of making rando things serializable.
Or use a custom inspector/naughty attributes/editor attributes to show some var
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
is there a go-to way to serialise a Tuple? I just can't seem to get it down. neither of these seem to work
public class PeoplePageManager : MonoBehaviour
{
[System.Serializable]
public class peopleBios
{
[SerializeField] public (Sprite, Sprite, TextAsset)[] peopleBioss;
[SerializeField] List<(Sprite, Sprite, TextAsset)> peopleBiosss = new();
}
}
no, just use structs, that way you get names too
you can make a custom class with all the fields you need then Serialize this insead. a List<YourClass> would then hold all of these objects
something like this would probably be better as a struct that a class though fwiw
sorry if I'm being dumb but this still won't show in inspect
public class peopleBios
{
Sprite previewSprite;
Sprite mainSprite;
TextAsset bioText;
}
[SerializeField] public List<peopleBios> peopleBiossss = new();
[Serializable] above the class
and make the fields public (or add [SerializeField] to them)
that did it! thanks c:
and last one, as said above, use a struct instead of a class, as easy as just replacing "class" with "struct"
I'm assuming when they said "that way you get names too" they meant that when referencing the items in code, you see their names as opposed to just "item 1" or whatever?
yeah
You can do that with tuples too btw
(double Sum, int Count) t2 = (4.5, 3);
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/value-tuples
but yeah as it doesnt serialize you need the class/struct anyways
good to know, thanks v much c:
yeah but it's not actually part of the tuple, this way you have consistent & forced names
heeeeello!
Hi man
Complete begginer, no idea why this isn't working. The player sprite should be moving left and eight but isn't responding
Been staring at it for ten minute now
Did you assign the script to your gameObject?
Is the script assigned to the object with the variables assigned, and are there no errors in the console?
I think it's the first honestly
got burnt by this when I started Unity
yep, I added the script component
no errors at all :/!
Oh
screenshot your player
on it
unity version?
private void Move() {
if (!isKnockbacked && !animator.GetBool("IsRolling")) {
Vector2 curMove = new Vector2(0, 0);
curMove.x = Input.GetAxisRaw("Horizontal");
curMove.y = Input.GetAxisRaw("Vertical");
float curMoveAbsX = Mathf.Abs(curMove.x);
float curMoveAbsY = Mathf.Abs(curMove.y);
if (curMoveAbsX == 0 && curMoveAbsY == 0) {
animator.SetBool("IsMoving", false);
return; // skip frame since no movement this frame
} else {
animator.SetBool("IsIdle", false); // MC moving thus not idle
animator.SetBool("IsMoving", true);
lastActionTimer = 0f;
}
// Change MC Sprite to Move Direction (priorize Vert > Horiz)
bool isHorizRight = curMove.x > 0 ? true : false;
bool isVertUp = curMove.y > 0 ? true : false;
// Move Up
if (isVertUp && (curMoveAbsY >= curMoveAbsX)) {
SetDirection(Direction.Up);
}
// Move Down
if (!isVertUp && (curMoveAbsY >= curMoveAbsX)) {
SetDirection(Direction.Down);
}
// Move Left
if (!isHorizRight && (curMoveAbsX > curMoveAbsY)) {
SetDirection(Direction.Left);
}
// Move Right Prio
if (isHorizRight && (curMoveAbsX > curMoveAbsY)) {
SetDirection(Direction.Right);
}
rb.MovePosition(rb.position + curMove * moveSpeed * Time.fixedDeltaTime);
}
}
6.1, just downloaded it
yeah but then you should have error messages unless you changed the input system to old
(you can ignore the SetDirection() helper)
Can you expand the Rigidbody component?
I'm following a tutorial and understanding the code as I go so using something else might mess it all up
did you change input system to use the old one?
up to you my man ofc
that's the same screenshot
I don't think so
AHHH, SORRY
also.. don't cut off parts of the editor.
This one
My guess is you do have errors in the console when you enter playmode and try to move
the screenshot does it automatically, no idea why
I'll switch to imp
lemme try
CTRL+Shift+C for Console fyi
Error! Input related
Great. That's because your tutorial is using the old input manager and not the new input system'
Unity 6000 doesn't allow Input.Axis("Horizontal" / "Vertical")?
No, it just uses the new system by default
this is not a very good piece of advice, moveposition doesn't detect collisions
Does Unity change a lot through updates?
Seems self evident from the previous statements
depends on your perception of "a lot"
annoyingly
it still does, just gotta change the setting mentioned in the error
You can switch the active input handler to the old system or to use both systems.
Go to Edit > Project Settings > Player > Other Settings > Configuration.
See Active Input Handling.
It doesn't matter that much to just use the old system if you're just learning
(but generally no)
Wouldn't it be better to get used to the new imput system?
alright, I'll change it then
it would, but there's kind of a learning curve to it. imo, use whatever your tutorial is using for now, you don't need more things to worry about when you're just starting out
If it just gets in the way of you starting to learn then it's not really worth dealing with that now
X.Y.Z:
X - a milestone has been reached
Y - new features
Z - bugfixes and small quality of life improvements
and then the character says what kind of release it is
Alright, switched! Thank you all
Is this why there's no unity 2024-2025?
no, they've changed the naming for versions. Rather than get tied into yearly
I guess but there was unity 5 a few years ago
yep
Struggle of reaching a decent milestone every year was one reason. Another reason was competition with Unreal Engine. They released UE5, so Unity tried to one-up it with Unity 6.
just a way for them to delay a major release to push core clr back
Sounds like what intel did with their new products dropping the i# for core and core ultra
and now we're stuck with "6000" instead of "6" because of the yearly numbering
I wonder if we will switch to 20290 in a few years. 😄 And then to 70000.
is there a better way to adding on-hover size increase to ui other than just increasing the transform size when its hovered on
is there like a special gimmick i can do or something where no code is necessary at all
changing scale sounds like the way to go to me
it's how I always do it (for animating UI, otherwise everything should remain at 1,1,1)
yea an animation changing scale works too
In the past, animators were known for creating performance issues for UI objects. I don't know if they fixed it.
probably because it constantally makes the canvas dirty (requiring mesh rebuilding) and most dont structure things correctly to account for this
Wdym makes the canvas dirty?
changes to any graphic in a canvas causes recalculation of meshes and layouts. Its recommend by unity to use additional canvas components within a canvas to reduce how much is made dirty
Oh didn't know got like 80 plus objects that update kinda often in one canvas
I assume changes to a text field wouldn't count through right?
ofc it does, the mesh changes to show the new text
So if you have everything in 1 canvas and you have some small popup that changes a lot, perhaps that needs its own canvas component
Oh yeah i have like 20 different text fields that update on Update()
Never noticed much for the canvas in the profiler though
An easy way of checking Canvas' performance is to toggle it on and off, while looking at the profiler. If the difference is noticable, then some issues exist. The problem is bigger if you're working on mobile apps, as they have worse hardware and you need to be more careful with optimizations.
Fair, i though i think a bigger problem for me is lights 😅 damn things make adding more enemies a pain
Hello, I have a problem with the level generator. When I drag brick (prefab) into the level generator and then start it, I don't see any bricks.
what is "the level generator"
oh in that case you're missing a semi colon on line 42
we cant do anything to help fix the code if you dont send the !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.
this is the code, but the code shows no errors
if you are certain this code is running and that there are no exceptions being thrown then if i had to guess, i'd say this is probably 2d? and your camera is probably at the same position on the Z axis so it just can't see it. make sure you actually look at the hierarchy to see if anything is being instantiated
You can add Debug.Log(newBrick.name, newBrick); at the end of the inner loop. It will create logs displayed in your Console window for every instantiated object. After clicking on such log a corresponding GameObject should become highlighted in the hierarchy, making it easy to find it.
it will make exactly 1 loop because 0 is less than 1
the loop keeps going if the condition is fulfilled, this is not an until
Oh right, my bad.
Unity is ignoring changes to default values in variables in the script, but when I make other changes to the script like adding a print() that works fine. Why does this happen?
because it's a default value, not the active, serialized value
by "default values" i'm assuming you mean the field initializer for a serialized field? and it's doing that because the values are already serialized so you'd need to reset the component if you want to return them all to their default values
the default is only used when you create the component or when you reset it
wtf
yea just how it is
what do I do about that?
sometimes it will update if that var isnt serialized yet but once it is it wont magically change
do I just right click and reset on the script component?
ah so I have to change the default value both in the script and in the inspector?
You can add [NonSerialized] attribute if you don't want the value serialized.
I thought serializeField is just to make it visible in the editor
Ha no, its to let you edit the var value in a scene or prefab and save it...
it also saves the value in the scene/prefab file
ahh
what do you mean by that 🤨
if you have a prefab, use the field there as the default rather than the field initializer
I have to change both of these
(or make it non-public)
yes
but do you need the code one in the first place
alright thx
but plz make sure you understand what serialized variables are
ig I don't need both, but I think I'd rather keep the value in code because its easier to understand that way
Is there a way to make the variable visible in the editor without serializing and without making it public?
what's the point of having it serializing it then
serializing lets unity control the value
can be constant instead:
const float BulletSpeed = 19f;
but sounds like you want to control the value in code only (which you shouldn't do)
I thought serialize was just to make it visible, I don't need to actually do what serialize actually does
these kinds of things should be serialized though to make editing easier
its easier to edit in code because I don't have to switch around windows and click around a bunch
Its better to have it serialized
You can change the value while in play mode and you won't have to recompile all of your code just to change a value
Especially if its a value you'll be tweaking alot IE: The speed of the bullet
If the value in the script took precendence over the value in the inspector, that would mean that you could not set anything in the inspector, ever.
The entire point of the inspector is to be the actual final say
having it only in code means you have to recompile for every change and you can't tweak it in play mode
damn i just said what genesis said
Is it normal that sprite of scriptable object require almost 2k lines to store? Here the code i use to save it
public void Save(GameData gameData)
{
var fullPath = Path.Combine(_dataPath, _fileName);
if (!Directory.Exists(_dataPath))
Directory.CreateDirectory(_dataPath);
var dataToStore = JsonConvert.SerializeObject(gameData, Formatting.Indented,
new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
using (var stream = new FileStream(fullPath, FileMode.Create))
{
using (var writer = new StreamWriter(stream))
{
writer.Write(dataToStore);
}
}
}
public class InventorySlotData
{
public int slotIndex;
public bool isActive;
public InventoryObjectSO inventoryItem;
}
ok thanks everyone
err are you trying to serialize a unity asset?
you cannot do this, you have to save data in a way that can actually be loaded again later, meaning you "save" a sprite by some id or address you use to load it again later.
So i should save some sort of key and changeable variables?
btw, is there a way to limit a serialized string variable to a certain number of options, like a dropdown or something? https://i.imgur.com/rOT6vdW.png
use an enum, not a string