#💻┃code-beginner
1 messages · Page 606 of 1
well either use a component or they need to be contained inside one
So what’s the issue here, why can’t you just do what you outlined here
Make a new skill, give the game object a reference to it
otherwise wth is "gameobj.add"?
you wouldnt be able to attach a poco to a gameobject
Maybe your skill information should be stored in scriptable objects.
Is skill a component? I thought it was just a non MonoBehavior class that gameobject needs a reference to
so NewObj.AddComponent<s1>????????
Oh so skill is a component?
skill is a class
skill needs to be a component to be attached to a gameobject
otherwise it needs to be inside a MB container class, like thru a list or something
But up here you imply it’s a component
let me start over because its ot what i meant
well explain what you want the skill to do , start with that
Is Skill a MonoBehavior component or a non MonoBehavior class?
Skill is not a component, its a class(OOP)
NO
i not trying to add it
mate components are also classes technically. OOP means nothing. its all objects
all im asking if there is a way to store it
the difference here is POCO vs Component
Yeah I prolly should’ve just said MonoBehavior vs non MonoBehavior
Or that
Poco being a plain c# object, like public class MyPoco vs component public class MyComponent : Monobehaviour
yes, put it on a script attached to the GameObject
store it is vague af
1min
Yes, within the GameObject give it a variable of the type Skill and assign that variable to the new skill you instantiated
Skill isn’t a component
I don’t think
store it on a gameobject as a component or as a poco inside a list/variable in component
Yeah I'm saying make a component that HAS a Skill field
but really this whole question is way too vague to actually recommend any kind of cohesive or useful architecture
it's not clear what exactly a "skill" is or does
just going by "store it" we don't really know what they plan on doing with it
public Skill GetSkill(GameObject gameObject)
{
string skillName = gameObject.name;
for (int i = 0; i < Skills.Length; i++)
foreach (Skill skill in Skills[i])
if (skillName == skill.skillName)
return skill;
return null;
}
if there is a way to make a gameobject to hold Skill, i wont need to use this func
oh man
Yes - of course - to add data to a GameObject you make a script that holds the data and attach it to the GameObject
What you're doing here is insane
Do what @wintry quarry suggested, attatch a new script component to the gameObject that holds a Skill variable, then assign that skill variable to the instance of skill you made
you're basically just using an entire Gameobject to hold a string
so what 200+ scripts with the same fields just diff data
you almost never need the GameObject class , work directly with a specific component
no... one script
public class SkillHolder : MonoBehaviour {
public Skill TheSkill;
}```
maybe 200 instances
with different data
that part's up to you
^ then when you instantiate the game object assign TheSkill to the instance of Skill it needs to store
also this might be good usecase for ScriptableObjects
especially if you have a growing list of Skill
Ideally set it up in the inspector - ScriptableObjects are good here, or just make it a serializable class
i can see the mess i'll have if i use Skillholder
how so ?
Why would there be a mess
Not another string based system 
i'll try it and see how it goes
done and working, but for reason i feels like im gonna have problems with that in the future
maybe im just to exhausted and confused
anyway thanks
Howdy folks, in Unity 6 with a Core 2D URP project, I'm experiencing some odd behavior with my cameras. Trying to use a second camera to a render texture via raw image in the UI to display something. My problem is the camera preview is just completely wrong. Its vertical, not square and the zoom level isn't right. You can hopefully see what I mean here:
Any ideas what I might be missing?
i have a new problem with images(sprites)😫
the images arries are fix but the player skills are not, some skill getting wrong images
looks like the camera preview is set to a mobile aspect ratio
Hmm. Well it is true I'm in a mobile profile mode, but given how the camera is not the main camera, and is rendering to the texture as a 1:1 aspect, I'd have figured the preview would know what to do.
Is there a way to make them not inherit the global (wrong) aspect ratio?
It would just be handy to get an accurate preview while I'm off inspecting other stuff.
im not too versed in 2d and render textures but ur camera should control all that..
the build prob wont look like that preview..
- i never use the camera preview *
You are correct the build doesn't look like this. Neither does the actual rendered texture in scene/game view.
I just like the preview since it docks and hangs around while I do other stuff.
ahh soo its a pet peeve kinda prob
Render textures are also kind of broken in the editor. They often get stuck and blank out, and only refresh if you modify a value in the editor forward and backwards.
i just use the game-view
ie, I often have to change the camera background to skybox and back to solid color hehe
it also docks.. lol
Yeah but I am editing in scene view.
You mean just unodck the game view into its own window and use that. Harder to do since the actual game view is locked on the UI, which isn't necessarily going to have the render texture in view.
Yeah but my camera is rendering to a texture. It isn't used for the scene view.
I cant make it render to the game window.
Sorry if that isn't clear.
ya little
so this render texture its UI i imagine?
is ur UI scaling/ set correctly? the canvas/
The render texture gets put on a quad out of view of the game view.
Another camera looks at the quad and sometimes renders that to a spot in the UI. But not always. And that camera isn't done yet so there's no way to make it work in final form yet.
Render textures are really cool. In a 3D scene you might use them for all the display renderings of monitors in a ship's bridge for example. I wouldn't necessarily be on the bridge in the game view to look at them. Hence why its handy to cycle through all the cameras via the preview window.
But hey, at least I know why its acting strange now....
ive used em for TV's and Monitors
Yeah exactly.
not as UI tho.. seems like a clever idea for some cases
Yeah the RAW IMAGE type is actually only used for UI.
That threw me for a bit until I realized I could set the render texture to a material and add it to a quad.
unfortunately nothing stands out to check in ur situation.. seems like it could be a handful of things
yup, u can put a raw-image on a quad.. but it ends up just creating a material
w/ the texture slotted into the albedo/base
:nod:
I'm actually trying to reproduce this here: https://www.moddb.com/games/backspace-bouken/tutorials/achieving-a-90s-style-dungeon-crawler-in-unity
i still havent found a good solution to make tv screens and stuff actually glow..
i can make it a bit emissive i guess. but i remember doing that before and didnt lead the results i wanted
Maybe add a point light on the surface?
unlit was the best i could come up with lol.. Shader-illiterate
Every time I try to get learned on shaders I fall into the pit of learning something old or outdated because shaders have changed so much over the years.
this is my ultimate goal
when it comes to render-textures and stuff
raytracing
facts lol 🙂
good luck w/ ur question... you might have some luck in #📲┃ui-ux
Yeah I didn't think asking about Cameras in non UI/UX space would make sense there.
Always hard to say.
I'm not sure about this, but, you can build UI Shader graphs in Unity6 right? not sure if RenderTextures can be 'plugged in' as an image source, but if they can, plug the render texture in both the albedo and emission slots, add some bloom, glowing surface.
In code when you want the thing to explode you disable the gameobject that has the mesh. You enable the gameobject that is a collection of pieces and begin the explosion.
I dont want an explosion
I want it to be chopped
Chipped
So a barrel starts with its whole mesh
And when i shoot it
I taken a tandom piece of it and disable it
I can do that with code but
or i guess shoot it out somehow wirh particles idk how to do thag neither
but the model that i broke with blender looks off and looks dunb even with 1 piece missing
Well its mostly a skill issue. I'd work on breaking down the complex problem into manageable chunks. Start with modeling a solid barrel. Get that into the game as a thing. Get hits registering on it and delete it when hit. Then move onto a barrel that has some damage. Maybe 2-3 damage levels. If you are looking for dynamic breaking apart modeled on the fly stuff, that could be a tall order for anyone outside of a journeyman/expert.
So you have 4 models. A full barrel. A barrel with 1 piece, 2 piece and 3 pieces removed. Or damage levels or whathaveyou.
Start with just having the barrel cycle through its models as its shot.
I have 2 models? One model is sperated into a lot of pieces
WHen split it looks like this
So make versions of it that have a progression of splits. A whole barrel. A barrel with one piece removed. Two pieces, Three.
that seems like quite literally the most ineffeicent way to do this if im being honest
Start by just replacing the whole barrel with each progressively more damaged versions.
Why not just cycle through an array and randomly select one
But it still looks cracked even if i remove a piece the entire barrel isnt supposed to look CRACKED
That is why you model it with different pieces removed.
Maunally?
You can still have an array. You can still choose what to remove each time.
Physics isn't amazing in game engines.
You can't have a thing made of parts that is dynamically destructable like you'd expect.
You'll need to do some fudging
It can SEEM dynamic to the user though if done properly.
So you'll have an array of barrel gameobjects. Whole, Damage 1, 2, 3, 4 ,whatever.
Then you'll have an array of pieces.
You'll replace the whole barrel with one of the models with a piece removed. And spawn in the piece in approximately the location it needs to be, and let physics move that broken off piece.
Usually a explosion sprite/flash/smoke or whatever will hide some of the transition.
Given this is unlikely a core component of the game I'd follow KISS. Have damage level 0, 1, 2, 3. Have pieces 1, 2, 3.
The real question here is why are your barrel pieces offset so that a seam is visible
And rely on rotation when its hit to hide the fact its always the same progression.
I used cell fracture in blender and that is how they became
There's some assets that may do something like this dynamically too: https://assetstore.unity.com/packages/tools/modeling/mesh-slicer-59618?srsltid=AfmBOorFLuPZ2CbVAhBJT2eyxKqCc78zbYS-y7STinvcRmODqutO1u1Z
If you don't even want to model the barrel pieces and whatnot.
Its all about how much you value your time.
And there are likely other assets, probably some cheaper. I've just run across them trying to do various things on my own.
A $50 asset that can slice/cut/mangle 1000s of destructables in your scene? Or a zillion hours modeling each one to be destructable? That is a way to look at it.
Well I’m not familiar with blender but when we pre-fracture objects in it there are no seems since the pieces do not get offset from their original position.
maybe my setting are wrong
Could be. I know we use voronoii fracture
In blednder?
Yea but unfortunately I do not know the details of that part of the pipeline…
Maybe we have a special plugin
Actually cell fracture is probably voronoii
This cant be true 
Having stability in physics based systems is tricky. Particularly if you want something like a barrel made of pieces fitting together and using friction to keep them together until interacted with.
In this specific case I don't see the point in overcomplicating it. I'm sure there are really good reasons to attempt such things.
I am reminded of this every time I'm playing an Oblivion Engine game and the room becomes a vortex of Havoc haha ;p
Why arent my functions showing up on the button 
Thats not at all how destructible systems like that work. A graph of the connected pieces is build and traversed to determine what pieces/clusters should have physics activated and fall
Yes I said "like you'd expect". He seems to be under the impression you can slice it in blender, import it into Unity, and have physics hold the assembly together until bullets hit it.
There's a framework you need to write to manage such things in a meaningful way.
We are in code beginner... so trying to keep things reasonable if that makes sense?
that's how its usually done with 2D games
model different sprites with different damaged states
Hi im a code beginner, i love code
would it possible to have the barrel into pieces being held together by a script?
once interacted with by a trigger collider you'd then add physics to it
giving the feeling of it falling apart or sth
Well as the other user said, you could spawn them in and disable the physics on all pieces thereby "locking" it into place until you chose to unlock pieces. But that requires scripting to track and manage which pieces are hit, and their heirarchy in the model. Seems very much like overkill for a piece of scenery that you can shoot and have blow up?
Many different ways to skin the cat heh
Make sure you've added the component to the button object?
Can't really see how the button is fully setup from the screen grab.
yeaaa not very manageable
I had the script on the Main Menu empty object guess I had to add the object into the button instead of the script itself? 
The GameObject that is the button needs to have a Button Component and the Script Component added to it. Then the OnClick handler has the button gameobject referenced. Once that is all setup you should be able to pick which function on the OnClick handler calls from the script component assigned to it.
I still get mixed up on it from time to time too.
Alright well, time I get some sleep here too!
If you think about it you can only call a function on an actual instance of a script. You can't call it on the script itself
that wouldn't make sense
It does in my head 
Then you don't really understand how scripts work yet.
A script itself is just a blueprint for creating components.
it's not an actual component itself.
I dont I just write it and it does things 
what if the function is static?
Yes static methods belong to the class itself
but that's not the normal way of things
oh yea i only do it for utility scripts
this is not 2d though
I also wonder
How can i make a particle system, each particle be a random mesh
check youtube
i tried
the particle system doesn't support meshes. VFX graph does though
at least for HDRP
URP?
The Output Particle Mesh Context allows you to render particles using meshes. They come in a regular (unlit) and a Lit variety (HDRP-only).
unlit meshes only for URP
unlit is a neutral term right
lit means its affected by light
unlit isn't affected by light
unlit is when the material isnt affected by light
okay okay
damn
with the rednerer function in the particle systems
you can assign a mesh
Oh apparently you can, yes.
Just gotta figure out how to make the mesh textured i guess?
you'd probably have to change the mesh at run-time through code
or use multiple particle systems
damn thats cool
oh huh, never seen that before
had no idea
same
idk, works for me. You sure you're using the right material?
Im using this
None of these meshes will work
ica n set it to aircraft carriers tho
i think theirs just something wrong with my mesh for NO REASON
make sure your mesh is UV unwrapped properly and assigned with a texture in blender
if youre using blender
im ngl
then export the texture to unity
textures and custom meshes should be managed outside of unity
then assembled in unity
Meshes must be read/write enabled to work in the Particle System’s Mesh Render Mode
According to the docs^
Did you set read/write on them?
Is that set in unity.?
yes...
I have now...
And is it working>
hell no
show what you did?
Hi i want to import a model from blender to unity, how do i make a collision box that is the same as the mesh
use a MeshCollider
mesh collider
I enasbeled read and write here
that's for the full barrel mesh
what about the one you're using in the particle system?
i Cant edit anything
you're looking at an imported prefab
you need to look at the mesh import settings
like what you're lookingat here, but for the other mesh
all mesh are the same i dont know what you are saying..
all have read/write enabeled to true
you have like 50 meshes here
i can use any 50 interchangebly in the partrcicle system
all fail
all ahve readwrite true
Well idk - I just discovered particle system can uses meshes 10 minutes ago
so this is the limit of my knowledge
I learn new stuff about Unity all the time
Ah that explains it
what is a SUB mesh
dose anyone know how to like when you press a button you disable the button that is active
hard to explain... basically a set of triangles in the mesh which gets drawn with a material
multiple submeshes -> multiple materials
it's probably how you have the two different textures on the barrel
when you say "button" are you talking about UI?
yes
had to explain and hard t understand
if ane asy fix, what is it in my case or?
do i bake a texture or something or like
set its interactable property to false
so im making a shop but when i open a tab the others are still open
you'd have to make a version of the mesh with only one submesh
(which means only one material in Blender)
tabs? What happened to buttons? I'm confused
pictures and a better explanation might help
no so one sec
BUT IM USING 2 COLORS
That can be done with UV mapping
so when i press a button i want the other one that is open to close
the other... button? tab?
I'm not sure I see what's open here that needs to be closed
so for example if the colour button is active then i want the hats button to be disabled because otherwise they are both open
I think you want all the buttons to be active all the time
it sounds like you want the tab that the button opens to close
Otherwise how would you switch back to the hats?
or am I still misunderstanding?
ANyway I already answered above how to disable a button
Hi i learnt you should prefab everything you do in unity, is this fine?
so if i press all the bottuns all the other bits inside are open
right so isn't it those other "bits" that you want to close?
ughh idk its hard to like understand
I think it's pretty simple
you either want to close the "bits", or you want to disable the buttons
so if i poen the colours tab i want the other tab that is open to close
right exactly
yeah
but i want it to do it automatically
and when you switch:
void SwitchToNewTab(GameObject newTab) {
// close the old one
if (currentlyOpenTab != null) currentlyOpenTab.SetActive(false);
currentlyOpenTab = newTab;
// open the new one
currentlyOpenTab.SetActive(true);
}```
yeah ok
thanks
@wintry quarry but then how would it know that tab is open?
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
wdym? Your code would tell it which tab to open
Your code tells it
look at my function
we store whichever object you pass in there in that variable
currentlyOpenTab = newTab;
to use this you would do like:
public GameObject HatTab;
public GameObject ShirtTab;
public void OpenHatTab() {
SwitchToNewTab(HatTab);
}
public void OpenShirtTab() {
SwitchToNewTab(ShirtTab);
}
for example^
those functions would be the ones assigned to your buttons
im not sure what to do
yeah
I literally showed you exactly what to do...?
like i put the code in a c# script but where do i put ti
it dosent know what the currently opentabs are
praetor you have sent me down a rabbit hole
Hey guys, stupid question but is there any function equivalent of Transform.InverseTransformDirection that only needs a quaternion for efficiencies sake? ergo, instead of needing to create a gameobject with a transform and destroy it each time I want to find a direction relative to a rotation, I can just use a Quaternion related function? This is the example code I've been using right now for a building system for my game. Currently the system is working perfectly, it's just that I dislike building and destroying gameObjects each frame just for this one simple function. It seems really inefficient. Any help is greatly appreciated.
Transform testTransf = new GameObject().transform;
testTransf.rotation = Quaternion.Euler(0, buildAngle, 0);
float addZ = Vector3.Angle(buildForward * Vector3.up, getHit.normal);
if (testTransf.InverseTransformDirection(getHit.normal).x > 0)
{
addZ = -addZ;
}
Destroy(testTransf.gameObject);
dispTransf.rotation = Quaternion.Euler(buildForward.eulerAngles) * Quaternion.Euler(new Vector3(0, 0, addZ));```
(Quaternion.Euler(buildForward.eulerAngles) * Quaternion.Euler(new Vector3(0, 0, addZ)); is the end goal roation I'm trying to find)
I didn't read/understand all of what you wrote here because there's a lot - but you can just multiply quaternions with direction vectors to rotate them
var rotation = Quaternion.Euler(0, buildAngle, 0);
Vector3 rotatedNormal = rotation * gethit.normal;
Vector3 inverseRotatedNormal = Quaternion.Inverse(rotation) * getHit.normal;```
I think this is what I need, thanks!
So i added a mesh collider but the mesh still falls thru the floor
If you don't have your console window open when you're using Unity, it's like driving a car with your eyes closed.
So you are saying i should listen to my console
yes
it means you would need to mark the Convex checkbox on that collider for it to work
phone pics
Heres one more 4 u
basically - collision math is much simpler for convex shapes. It wouldn't be performant to allow concave shapes to be dynamic.
So concave is not filling the whole mesh?
For a convex shape you can draw a line from any point on the surface to any other point on the surface and the entirety of the line will be contained INSIDE the shape.
For concave shapes that's not true
using a moving particle system with a box collider for ubllets, on collision with a barrel, on my barrel script i have an oncoliision enter, or i guess ontriggerenter since the bullettrail isTrigger is true. but nothing triggers in the script
pay actual attention to it then
particle systems don't trigger these things
even if i just have a box collider on it?
should i parent a box collider then?
particle system as a hcild
please finish a thought before sending a message
Thank i didnt really understand but i think i understood enough
ok I just realized you mean the particle system is not relevant.
Why are we mentioning the particle system then
Anyway it seems like you're mixing up 2D and 3D stuff
which that link box sent you would be showing you
if you just follow it
well its literally just a moving gameboecjt
OH MY
i just had a typo
dawg
it stioll doesnt work but at least i fixed the typo
preshy
now go through the rest of the steps in that link i sent to find out what else you've done wrong
am rn
i have a questiojn do you know exactly what it is
DONT TELL ME
dont spoilt it
but do you
ypur read it 3 times nothing
then show the relevant objects
😮💨
so you didn't pay much attention to the information in that link
boxfriend i literally just
i hate my type of people too
i just cannot
i dont have it in me
i read it so many rimes
and i clicked istrgiger and other struff so many times
regardless, shouldn't ONE of those prints go through.
again, finish a thought before sending a message. we don't need this spam
alright i'm out good luck
jesus stop spamming the channel.
#📖┃code-of-conduct
wowd dude do you want me to use capitalization and periods too?
why is the trail pink?
that's the "no material or shader not supported on this pipeline" color. also not a code question
where to put general questions?
is it possible to switch a project from one render pipeline to another?
yes, you install the package for the other pipeline and assign the relevant pipeline asset in the graphics settings. but that is not something you need to do for this, you need to make sure you have actually assigned a valid material to the trail renderer and that the material has a shader that is made for the pipeline you are using
thanks
How do I remove this error. Its all looking fine. btw i am watching gmtk's tuotorial
you're probably missing a }
you missing a }
its there
show the entire class because errors don't lie
using UnityEngine;
public class BirdScript : MonoBehaviour
{
public Rigidbody2D myrigidbody;
// 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()
{
if (Input.GetKeyDown(KeyCode.Space) == true)
{
myrigidbody.linearVelocity = Vector2.up * 10;
}
}
first, !code
second, you are missing a }
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
you are missing the one at "public class BirdScript : MonoBehaviour
{"
you didnt close the class at the end
well you've gone and added a { for some reason instead of adding the missing }
noo, you put the } at the end of the whole code. If you find yourself with more of these errors maybe I suggest you to maybe understand syntax in C#
oh k
there are beginner c# courses pinned in this channel that will teach the fundamentals of the language, like the basic structure
👍 thank you
Shouldnt this detect only colliders tagged "Player"?
cuz its just ignoring everything.
@slender nymph good luck with your flappy bird game 😊
this works, but everytime u add a layer new it automatically gets added as unchecked so is not a valid solution
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Collider-includeLayers.html
The **additional **layers that this Collider should include when deciding if the Collider can contact another Collider.
So it just overrides this?
yes
Alr, thx
Past few questions have been an interesting read lmao
Friendly reminder for all that you when you're spawning game objects at different points in your game to include the in game location. (Position.x + x, position.y + y, position.z +z). I pass this on to you because it took me a lot longer than I'm comfortable admitting to realize the error in my thinking. Maybe there's a better way, but that's just my take
I have this error message:
Assets\Scripts\Enemies\Wolf.cs(126,35): error CS7036: There is no argument given that corresponds to the required formal parameter 'damage' of 'Wolf.TakeDamage(int)'
This is my Coroutine in Player
{
Debug.Log("PlayerDamaged");
isDamageable = false;
Body.color = Color.red;
HP--;
yield return new WaitForSeconds(0.2f);
Body.color = Color.white;
isDamageable = true;
}```
And this is the code that is supposed to Start this coroutine, but i get an error message, even tho i have no int paremeter.
```Player.StartCoroutine(TakeDamage());```
Whats wrong here?
seems like your TakeDamage method previously had an int parameter but you haven't saved that file since making that change
wait, is the TakeDamage method you just showed the same one on the Wolf class?
It did, and i also thought this could be the issue, however even after reloading and checking if i saved the issue remained and it also had this problem when i included the integer
Wolf also has a Method called TakeDamage as a Contract in an interface
right and you're starting the coroutine from the Wolf class. which means that is this.TakeDamage() not Player.TakeDamage()
and Wolf.TakeDamage expects an int parameter
Oh i figured it out, im so sorry
remember, unless you call a method on a specific object, you are implicitly calling it on this
It was Player.StartCoroutine(Player.PlayerTakeDamage());
instead of Player.StartCoroutine(PlayerTakeDamage());
Thank you!
I have the most random glitch icl, I tried to implement a camera rotation system and it ended up causing the players position and rotation to change
is your camera a child of the player?
Yes, is it interacting with the rigid body?
it interacts with its transformations
your camera shouldn't have a collider, so it won't interact with physics
Ok
you're giving very little info here, some context would help
it doesn't, maybe show the content of the foreach
Ok I'll try to figure out how to show my 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/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
no, that's not what that means
The error is on the line of the foreach though
that too, I always think its best to make a camera controller script that takes the transform from the player object :)
and treat them seperate if that makes sense?
you cannot remove objects from a list you are foreaching on
ok thanks. I will try that now
Oh, how do I remove them then?
for loop and go backwards!
use a reverse for loop instead
for(int i = list.Count - 1; i >= 0; i--)
you could linq to filter the list before assigning it
Isn't that gonna return error as soon as I remove anything?
(im biased against mutations)
its also valid to use .Where().ToList() but its gonna make more garbage than the manual method
no
if it were going forwards, it'd cause bugs, but that's not the case in reverse
You get the error when going forwards, because the loop might start with 10 items, you remove 1 item, so once you are at item 9 the loop wants to then move to the next non-existent item as it was told 10 items exist.
But going backwards, you start at item 10 and go backwards to the first item. So once you reach the first item in the list, it doesnt actually matter at that point that the list was modified to only have 9 items
(you won't get an error, you'll get a bug)
yeah looping forward and removing items will cause items in the list to be skipped
with lists there's generally no need to cache the count, so you'd just get the count of the list in the condition; the loop won't go over the bounds of the list
🗣️ 🧱
im. just absolutely lost on what that's supposed to mean lmao
guy speaking to brick wall meme
hes breathing on the brick
many people explaining the same thing but person who needs it probably not even reading it
i read it "spitting bricks"
im adding this to my vocabulary 
just search them up
there are beginner c# courses pinned in this channel. those courses cover the basics like collections
Arrays and lists are C# specific and not Unity specific, so you should be able to finds lots of resources online - w3schools has a great C# course which covers both arrays and lists in good detail imo, and with a "sandbox"-like way of practicing on the site, all for free
thanks a lot
ill look it up
Hi, i have a little problem when i'm trying to add a script in my gameobject i have this message, and all my script didn't work now
how much time does it take to learn the basics of C# in unity
How long is a piece of string
As much time as you'd need to go through the courses on !learn or pinned in this channel and becoming accustomed to reading the docs when you don't know something + a bit of time to understand that such questions are meaningless
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
It all depends really on how best you yourself learn things.
For example, some people learn best by reading, some by someone verbally explaining, some by visual learning or by picking apart existing code etc.
So, I learn best usually visually and verbally, so I've learned a lot by watching Youtube tutorials about things. Granted they usually tell you the wrong way to do things and there's a lot of lazy coding in them, but for the most part they've been a good resource for me personally.
A lot of times, just asking a question in here and talking about it 'out loud' helps me get to the solution.
Im tryinh to make procedural wall generation for the backrooms, and stumpled accross this video(https://www.youtube.com/watch?v=wQj-l0vDQsA that describes how he generates walls. At around 3:13 he slightly explains it but i have no clue how to actually do it. Could someone help?
I think im supposed to describe stuff here...
I made the backrooms in unity and unreal and also a bunch of other stuff.
0:00 - Intro
0:04 - Time Stamps
0:28 - using Unity
0:43 - Prop Hunt
1:03 - Mario Kart
2:00 - 3D Among Us
3:00 - Backrooms ( Unity )
5:03 - Switching to Unreal
5:35 - Backrooms ( Unreal )
7:04 - Visuals
8:25 - Walls
8:50 - Wa...
Not sure if a video with "in unreal" in the thumbnail is gonna help much with unity
its in unity
he does it in both for some reason, but the underlying logic of how the wall generation works is what i dont understand
You have to research the topic on your own, this is a big thing, nobody can teach you it in just a discord channel
Well, they described it briefly in the video: draw lines(walls) randomly on a 2d texture. If a line hits another line, generate the wall(generate a mesh or just scale a cube). That's basically it.
// void Start()
{
rb = gameObject.GetComponent<Rigidbody2D>();
rb.AddForce(new Vector2(Random.Range(10, 20), Random.Range(10, 20)),ForceMode2D.Impulse);
}
This doesn't seem to have an effect, even if I scale the force values to thousands. Why? Mass of the object is 1
Well your function declaration is commented out 
it's not, it's just the stupid discord code formatting
Assuming that's just a copy-paste error, my guess is that something's rewriting the velocity in update
The // is not part of discord formatting
I deleted the update method
Can you show the inspector of this object?
Where's the script
where's the MenuBallMove?

I swear, the easiest problems are the hardest to solve cause you'd never think you would be so stupid as to miss it
Happens to the best of us
There is no timetable for learning a programming language. It solely depends on the person learning, their aptitude, discipline, and determination. Two people can practice for 5 hours for a week and be a drastically different levels
Discipline is key. Practice every day, write ALL of your code, and repeat, repeat, repeat . . .
Always think you're stupid and make the dumbest mistakes. Never assume or take anything for granted. start from zero every time you tackle a problem; leave no stone unturned . . .
fax no printer
looks like you have a new goal, practicing debugging 👍
if code doesn't do anything at all, is it even running? 
I didn't hear back from you, so here's a sample test—this is similar to what I suggested. If you don't need Unity, you can run a quick test in c# . . .
I was wondering if anyone could help guide me to the correct information for my question? I am trying to connect my unity game's data to a website to allow players to see their stats (damage taken/time played/etc). What would be the best way to connect my game and website to allow this transfer of data as well as store this data?
and if this is the wrong place to post this, let me know and ill post it in #archived-networking
you'd need a server+database as a central system to hold everything
the website interacts with the server, the game interacts with the server
#archived-networking would be relevant for specific parts, but i think your current question is more about architecture/system design, no specific channel for it
would you know of a tutorial to perform this? or additionally any free/simple ways to create the server and connect the website and game to?
I think https://playfab.com/ is a pretty popular choice, and I'm sure there's plenty of tutorials on Youtube
ive given you some new keywords, try looking those up
Unity provides these services (free for some amount of requests) or try nakama
thanks a lot guys
Hello
I'm trying to add music to my unity game
I have an Audio Source obiect with that script:
Yeah, happens that this thing I was getting done may allow me to test It directly afterwards, but... it' gonna take a while...
On some scenes where I want to turn the music off I use object with that script:
But yeah, I should try that now, just to know how to do it
but when I'm comming back to the basic scene where I want to start music again I get this warring and it doesn't work
- Using static variable (playOnNextScene) is discouraged. Make that a regular variable on the singleton instance.
- your code in lines 21-24 in BG_Music will run even when you destroy the object. That's not a good idea.
- Awake is not going to run when you load a new scene. so the actual singleton instance will not be able to consume that bool.
No problem; the link is basically what you wanted. It's just a sample of how you'd setup the class (that holds the time variable) and the use of IComparable. If you run it, you'll see that it sorts the list based on the Duration of a Timer class . . .
yeah because you're trying to play the audio source you're destroying on line 19 on line 23
but there is always an instance
Yes in fact there are multiple instances
how?
when you load the scene there's an instance in the scene that you loaded
which destroys itself on line 19 right?
But taht is also the instance which runs the code on lines 23 and 24
DontDestroyOnLoad
so it's trying to play its own audio source as it destroys itself
Destroy does not end the function
yes what about it?
it's used to DON'T destroy object
so normally it dont destroy objects but in my code it destroy it?
What happens in Awake when instance is not null, but also playOnNextScene is true?
Huh?
Do you know what your code is doing?
i was thinking that i know
You have the DDOL instance that stays between scenes, and then other instances that are destroying themselves
do you understand that bit?
DO you understand when Awake runs?
on load
on load for that particular instance
It will only run once per instance
So your first instance will DDOL itself
Second and subsequent instances will destroy themselves
this is all just what your code is doing in Awake
But your subsequent instances are also the ones running lines 23 and 24, after they have already started the process of destroying themselves
It's not your original DDOL instance that is running those lines
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.SceneViewMotion.SetInputVector (UnityEditor.ShortcutManagement.ShortcutArguments args, UnityEditor.SceneInputAxis axis) (at <18226ebcc7724db583d19c0aeb6444e9>:0)
UnityEditor.SceneViewMotion.WalkLeft (UnityEditor.ShortcutManagement.ShortcutArguments args) (at <18226ebcc7724db583d19c0aeb6444e9>:0)
UnityEditor.ShortcutManagement.Trigger.ExecuteShortcut (UnityEditor.ShortcutManagement.ShortcutEntry entry, UnityEditor.ShortcutManagement.ShortcutStage stage, System.Object context, System.Boolean reset) (at <18226ebcc7724db583d19c0aeb6444e9>:0)
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler()
did my unity spazz out or did i do something
spazzed
alright
also, i duplicated a wall, but they didnt even get duplicated, just a new plane with completely different scripts and attributes
oh wait im just stupid newvermind
so uh... How can i make it.. not do that
That's caused by non-uniform scaling of a parent
The rule of thumb is to not parent things to an object whose scale isn't uniform
e.g. [5, 1, 1] is a non-uniform scale
As the child rotates, it aligns with the parent's scaling in different ways
causing shearing
thanks
skewcity
btw you're like a developer now, you should really be using screen recording instead of a phone lol
Yeah i know, its just that every sinmgle time without fail the nvidia apps videos take more than 10 mb lmao
OBS is 🐐
ShareX is good too
both can record like 30 min video for less than 20mb lol (a bit exaggerated but you get the point)
sharex is great
alright thanks a lot, i like this server a lot more than most other coding servers. Almost every single one have most people been more of a hassle than a help
also, for recording the game view itself, the Recorder package is fantastic
(not relevant here, though)
I'm trying to do some basic netcode setups but the buttons I have made to start client, server and host dont work at all, they dont even highlight when I hover over them.
follow this tutorial https://www.youtube.com/watch?v=3yuBOB3VrCk&t=676s stuck at 13:00
❤ Watch my FREE Complete Multiplayer Course https://www.youtube.com/watch?v=YmUnXsOp_t0
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👇 Click on Show More
🎮 Get my Steam Games https://unitycodemonkey.com/gamebundle
Quantum Console https://assetstore.unity.com/packages/tools/utilities/quantum-console-211046?aid=1101l96nj&pubre...
your scene doesn't have an event system
doesn't seem related to any of the networking stuff
You need an event system if you want UI to be interactable
added that and it worked, ty
what does an event system do tho? why doesnt a canvas suffice?
the event system reads input and checks if you've interacted with something
typically UI elements, but it can also hit things with colliders
It's the thing that actually tells stuff it's been clicked on
It's automatically added when you create your first canvas
Processes UI events like clicking, hovering, etc to send to the UI components
Also if you add a canvas or any UI element from the menu it adds an event system automatically
ohh
The fact you didn't have one means you either copied these objects from another scene or you manually added the components
"what's this do? Doesn't look important"
it's like how i instantly close most popup windows without actually reading them
Hi i got mesh collider on an object and it doesnt give it collision
- What are you expecting it to collide with?
- SHow the inspector?
screenshot please, not phone photos 😭 , and why did you cut out the inspector
the inspector is the most important part here
you don't have a mesh assigned to that collider
so there will be no collision geometry
I cant screenshot normally rn
How to turn it 90 dagrees?
it's the child object that is turned
Btw i see its not hollow in the inside
you need to either rotate the child or put the collider on the child.
Put the mesh collider on the object that already has the mesh
How do i access the child
In what context?
with your mouse
In the context of moving only the hitbox
you can't "move the hitbox"
you can only put it on a child object and move/rotate/scale that child object
Oh shit you were correct
the simplest solution is yes to just put it on the same object as the renderer with the same mesh
Well how am i suppose to know that???
I'm telling you it
Uncheck "Convex"
but if you do, it cannot have a rigidbody
Like convex and concave i understand now
So convex fills the gap
HELL YEAH IM LEARNING
I didnt see the hitbox when doing convex so i got scare its not there
Also you typed "hitbox" its not called hitbox??
it's called a Collider
Alr alr gotcha
but I typed "move the hitbox" because I was quoting you
hey i need some help so im creating a runner game but in my shop scene i want to be able to equip a cosmetic and for it to show up in a different scene? anyone know to to?
Alr so you said a simple rigid body, how do i get it
save the information about waht cosmetics the player has etc in something that survives between scenes, such as a script on a DDOL object.
I didn't say "simple" i said one that isn't dynamic
that means a Kinematic RB
Kinematic Rbs will not move on their own or with the physics simulation, only via your script
how would i save it
in variables
ok
for example:
GameObject equippedHat;```
anyone have experience with downloading this? I'm trying to right now but it won't let me, when I add by git url nothing happens
check your console for errors
most likely you don' have git installed or your URL is wrong
I don't think I have git installed, how do I install it?
what do we call this type of bosses where he follows you and your job is to keep distance between you to and dodge his attacks? and do you know any tutorial on how to do it?
but check your console to make sure that's the problem first
I'd call that an auto-scroller boss
although it doesn't have to be an auto-scroller; the screen can stay focused on the character
Fen you'r awesome you're always here to help
nothing there :/
Make sure errors aren't disabled in console. Also Can you show a screenshot of the console directly after entering the git url?
it's a level design called auto scrolling. you just have an enemy (boss) that stays on the screen to attack you . . .
Alr i think i got it, thank you very much collider dude
@wintry quarry new error 💔
thank you
looks like your url is incorrect
make sure you dont have any trailing extra chars or whitespaces
pretty sure that sample is now already part of the Package Manager no need to even pull from git
i get this wrong around 15 times in a row every time I add a package from Git
anyone know the problem with this code? it wont change scenes when i go through the box collider, yes my box collider is set as a trigger
do the logs print
no
is ur game 2d?
yeah
thats why
The Three Commandments of OnTriggerEnter:
- Thou Shalt have a 3D Collider on each object
- Thou Shalt tick
isTriggeron at least one of them - Thou Shalt have a 3D Rigidbody on at least one of them
can you explain?
you need the 2D version.this one checks for 3d colliders
this resource explains it fairly well: #💻┃code-beginner message
im using the 2d version
no you aren't
not the function
oh
that function looks for 3D colliders
how could you tell its the 3d version
because it doesn't have the word 2D in it
Because it's not 2D
where should i add the 2d
anything 2D physics related in unity has 2D usually affixed to it
did you loook at the resource given to you
Opened my project and this 3d model is suddenly transparent in scene view but not in game view?? This makes no sense and wasnt happening before. Any ideas how to fix this?
(also goddamn why are the unity docs like this. You don't see the OnTrigger2D code until the very bottom of the page / code sample 😢 )
My bad 😭
You can quickly clear this from everything in your scene by double clicking the eye next to the scene in the hierarchy
that hides everything, then unhides everything
I must have pressed a shortcut to hide it accidentally, thanks
i changed it but now its saying this "onTriggerEnter has an incorrect signature"
so change the signature
im new thats why im here
did you look at the link praetor sent literally has the signature written
if only a resource that walks you through everything you need to check had been provided to you
You really should read that page you were linked to
It's written for complete beginners
If you don't know what it's saying, look up the words you don't know
what is not clear? because the resource was created for beginners so if something isn't clear it needs to be reported so it can be made clear
i dont understand c# to that level
lets break it down, which part exactly you're stuck / confused about
Okay, let's start at the page that was linked:
https://unity.huh.how/physics-messages
The first step:
its just confusing
Do you have logs in your function?
then stop what you are doing and go learn the basics. there are beginner c# courses pinned in this channel and the pathways on the unity !learn site will teach you then engine
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
ok, thank you
The page is literally step by step, question and answer. You click on the links that answer the questions. It's the most simple thing you're going to see.
First step: put in some logs. Do you see em?
a lot this is reading , not so much to do with c#
i'm willing to bet they are actually looking at the doc page that praetor linked rather than the much more useful huh.how site that was linked almost immediately after they asked for help
why do you guys have to be so mean
literally where has anyone been mean
We're not we're just saying to click the link and read it, it explains it in plain english better than any of us here
This whole back and forth question and answer thing is literally how the page is structured
im gunna read this
yes, those are courses to start from beginning
the rest is good too https://learn.unity.com/project/beginner-gameplay-scripting I learned from these on YT when Learn was barely a thing
i dont know what's going on, but the bullets in my script dont decrease, and also after some time when i fire the player bullets, it stops the game, somethings wrong, maybe is the enemy script? How do i post huge scripts?
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
btw, this is the script of my enemy, i dont know what im doing wrong.
What i tried to do, wich didnt worked, was that after the bullets of the enemy dry out, it executes an animation, and the enemy must wait till that animation ends to return shooting
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
public class HatSwitcher : MonoBehaviour
{
public static HatSwitcher instance;
public GameObject Hat;
private void Awake()
{
instance = this;
DontDestroyOnLoad(this.gameObject);
}
dose anyone know what is wrong?
you are generally expected to match every opening { with a closing }
yes ik but when i take away the { it is all an error
You are supposed to add a }, not remove a {
yeah it worked tbh i didn't even think of doing that
is your IDE working? normally tells you where its missing braces
also might wanna do a proper disposal of copies of Instance, incase you have more than 1 in scene
if(instance != null && instance != this)
Destroy(gameobject); return;
instance = this ```
btw, for an strange reason my bullets dont decrease, and the game randomly stops, what i did wrong?
What do you mean "randomly stops"?
Do you perhaps have Error Pause enabled in console?
well, thats not the big of the issues, but for an strange reason the gameplay "crashes" mid game, when i shoot the enemy, or thats what i thought, it just happened twice, and with random circustances.
But the issue is, the animation doesn't play, an the bullets dont decrease
crashes as in what it freezes?
no, it closes
its like the player dies...But without having her dying
wich is...weird
Whole unity closes?
are you getting a Bug report window ?
I don't know what that means.
thats not game crashing lol
Hi
That's probably the editor pausing.
my bad, the game stops
that
This will happen if Error Pause is turned on (and you get an error)
then yes you probably have pause on error
the issue (wich wasn't the main issue but still), is why?
but the main issue, atleast for me, and i think this might fix it, cuz this happened after all the code editing i did
Is why it happens the bullet thing
t h a t s w h y i m i n h e r e
yes but if its an error we need to see console
its hard to look at it, due i dont have yet the animations, and i have them on the script, it completely invades the logs
hey i made this code which i want to use for my player but i cant figure out why he doesnt fall down after a time when holding the space bar. when i release it and press it again he does his second jump which i allowed through my code, but he just doesnt stop accelerating in the air until i release the space bar.
https://paste.ofcode.org/pv4kgt7E4YtseKbWMx9PgY
https://paste.ofcode.org/auMusC8D8hiY3QV4CZXcKb
idk what animations have to do with logs
ok now we're getting somewhere.
it still wouldnt pause
you have to show runtime errors if any
Show your whole console. Do you have error pause enabled
You can also make it show only errors by selecting this
dis is all
are you trying to work with a disabled Animator or something?
importantly, you have errors hidden in the console right now
:|
i mean, i have the animations set in the script, but i dont have those animations made already, except OBVIOUSLY the reloading one
There are zero errors in this screenshot, but, if you had one, it wouldn't show up in the console window
i mean, with looking at the code u can't see the problem?
I mean is the ANimator component disabled? Or maybe it's a component on a prefab instead of in the scene?
Or a disabled GameObject
no, its not
the enemy walks good
huh o-o'''
d a n g
was this after the reloading tthing or was that working?
tbh I always prefered transition states than calling Play directly
Note that these are warnings, not errors. Trying to play a missing animation state wouldn't throw an exception and break your code.
there is def more code throwing these
If your game was pausing, that means that an actual error was happening
when the game pauses, screenshot your entire console window
Ensure that you have errors shown (notice how the button is now light gray, not dark gray). Play until the game pauses. You'll have an error in the console.
as said, its random, i play it and didnt trigger :<
So balas is the bullet count? And the shooting works, but balas is not decreasing?
exactly
How do you know? Are you looking at the inspector?
no, im playing it
aaah the decreasing part
yes
im looking at it
Since balas is public, something else could be modifying it
Like another script of yours, or maybe an animation (unlikely)
lets see if works
btw you can just make it private and it wouldve told you which script was using it from outside
you generally want to keep all fields private
if something else needs access, usually a read only use a Property getter or Method that returns that value
otherwise stick to methods to modify them so clearer whos touching it (eg you can invoke events or print logs when its modified)
youre trying to destroy a prefab
you're likely passing the prefab to Destroy rather than the instantiated object
yep
it's your code, you tell us why
You're doing cs private Bullet bulletPrefab; Destroy(bulletPrefab)
instead of
var bulletInstance = Instantiate(bulletprefab
Destroy(bulletInstance )```
o h
im sorry if i sound dumb...but what's the difference
well thats why you had the error then lol
one is destroying the prefab in your project (an asset)
the other is Destroying clone, aka the instance made from that asset
o h
and unity stopped you as well you probably dont want to delete your asset...
haha yeah that wouldn't be good if you can just start deleting assets that easy
wait, is this actually in my code, or you're guessing?
cuz i been looking in my code...and i didnt find it
that is just an example of what you are doing, not your literal code
oh
And no it's not in the code you linked us
the deleting thing is in the object
public class MortemRifleProyectile : MonoBehaviour
{
public int damage = 5;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.transform.TryGetComponent(out ValeriaController player))
{
player.TakeDamage(damage);
Destroy(gameObject);
}
}
}```
thats not it
well, there's nothing else
there is
dont you have something shooting bullets?
That's something you are going to have to find
or i think
just show that one
We don't know where you're calling Destroy
in the object itself
Does this not take you to the code where it happens, when you double click the error message?
the game crashed and this thing appeared
the game crashed? or the game stopped doing what you coded it to do..
hey my player gains height as long as i keep my jump button pressed and i dont know how to do something about it. im relatively sure this section of my code is what causes the problem. i watched the tutorial i was following 3 times and i just cant find it.
i was slapped back to the editor
It didn't crash. You have Error Pause enabled. This will pause the Play mode when you get an error
cause if that appeared you have pause on error on
Also you did not answer my question
but i mean, this didnt happened before trying to make the reloading s h i t
so you try to destroy an asset according to your error, then it pauses
? what question
Double click that error message and see if it shows the code where it happened
my T R U E issue, atleast for now, is that the bullets amount dont decrease
we dont know what you added from before till now
its random, and i restarted it, so its lost
i mean
look for all scripts that contain Destroy 😬
only one
public class MortemRifleProyectile : MonoBehaviour
{
public int damage = 5;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.transform.TryGetComponent(out ValeriaController player))
{
player.TakeDamage(damage);
Destroy(gameObject);
}
}
}```
Add a log after balas --; line:
Debug.Log("Bullets left: " + balas);```
Show what it prints when you shoot
dont think Destroy(gameObject) would throw such error
well, i searched all scripts
no destroying
It would if it the code runs on a prefab
But I don't think ontriggerenter can run on a prefab
Or something went horribly wrong
if it wat
If the *

