#💻┃code-beginner
1 messages · Page 19 of 1
Thanks!
One of them is world space, one of them is relative to the parent
oh
how would you have a eulerangle in the world space?
oh
is it like
the x,y,z of world space
instead of your player?
The same way you have one relative to the parent, except relative to world origin
so if my character moves forward on the x axis, and is always facing the x axis, yet it's not always on the world spaces x axis
idk if that makes sense
Position has nothing to do with orientation
If your character moves forward on the x axis that has nothing to do with euler angles
i mean where it's facing
can you give me an example
create 2 empty gameobjects rotate one and make second a child of it look what changes
If you have an object with euler angles of 0, 90, 0 it's looking to the right. That object then has a child object with a local euler angle of 0,0,0. It's still looking to the right, because its parent object is
and local is the child object rotating based on the parent
ohhhhhhhh
ok
i got it better now
parent object with euler of 0, -57, 0 then the child with local euler 0,0,0 is 0, -57, 0
suppose the parent was 0,20,0 and the child's local euler was 0,10,0
world space would be 0, 30, 0
Hi, do you think there's a way to affect meshes with code, like extruding at random positions?
maybe with probuilder ?
usually you'd use something like a vertex shader for that, but I guess you can edit the vertex data directly
with HLSL ?
Ye, unless you can make them with shaderlab yet]
ok will dig that, thx
Hey guys im playing around with coding a turret with a specific radius and I have the radius working how I want but I want to be able to show the radius in game. I use this for when the game isnt running and its correct
private void OnDrawGizmosSelected()
{
Handles.color = Color.white;
Handles.DrawWireDisc(transform.position, transform.forward, baseTurret.targetingRange);
}
I know this cant be used when the game is running and ive been trying to scale a circle sprite to the radius and a few other things but I just cant seem to get the correct size. This is probably a math thing I dont understand unless there is something similar to how the DrawWireDisc works that I dont know about.
how do i change the material
drag it on there
I would do the circle sprite way on this
seems the most efficient
Haven't touched gizmos for a while, but isnt handles the editor debug tool?
Make the sprite 1 unit wide, so when u import it and u set the pixels per unit it has to be same width as that ,
and then if u set the scale to the radius of the turret it should be the same
hey, I'm looking for a way to write this method to avoid having to make a bunch of methods that are basically the same...
foreach(Helmet h in inventory) {
//show the item in inventory
//There are no class specific fields or methods being called in this method
}
}```
Here inventory is a list<Item>; Item has children, like armor and weapon. Those children have children such as helmet, chestplate etc. Is there a good way to make this statement more dynamic so I don't have to make one for each child of Item?
few draw methods in there
Just make another outter loop, no?
sorry not following?
You're trying to loop over a list, and for each item find a helmet?
sorry I completly forgot to add the part where I wanted to run this to find any specific child of Item. The method I show works, but only for the Helmet class. In the end I want to avoid having to make one of these for each armor piece and any other possible filters added in the future.
can you give a working example of what it does so
is the loop looking for an item ?
Like, at runtime you want a search box to filter out item names?
basically condense:
foreach(Helmet h in inventory){}
}```
```private void DispArms(){
foreach(Gauntlets g in inventory){}
}```
```private void DispChest(){
foreach(ChestPlate c in inventory){}
}```
into one method
Probably want to look into regular expressions
and some parsing methods, but c# has a lot of libraries for that stuff
do you want it to return an item ?
or check whether you have something in ur inventory?
no, just be able to tell it what kind of item it needs to show, then it will instantiate slots for all of the items it finds of that type
I dont need to know if its there I just need to grab all instances of them
so those classes need to share something a parent or interface idk
using reg expressions, would I be able to define a type for it too look for?
they do
they are all children of the Item class, which is what the main list holds. All attributes that are needed to instantiate a new slot prefab are part of Item, so I dont need to make calls to any of the child's properties, I just need to grab all children of a certain type
so u can have item type enum in Item class and loop through inventory grab all items with certain type and do stuff with them or I misunderstood
he cant because the inventory has subcategories he would need to loop through
if you click on any of the red slots it will bring up all items of that type in the green area
Honestly, if it's not much you're probably fine with what you got.
foreaching over a list is pretty quick since if it's empty it's just a 0(1) operation
yeah, it just hurts to write repeated code, it just always feels like there is a better way to do things lol
the list would be the entire inventory so its still O(n), but I dont think there will be that many items in this game so time complexity isnt a huge concern
Oh so you're trying to scan an inventory for each type of item eh
List<Item> screenShowList //Green part
void disp(searchTerm){
foreach(Item i in inventory){
List<Item> tempList = i.returnAsList;
if(i is searchTerm){
screenShowList = i.returnAsList
}
}
}
something of this kind would work
syntax might be wrong
but this is how i would do it
Yeah, what you can do is make a flag enum
send that into your foreach loop of the inventory
if item enum type is any bit of this bitwise enum then you add it to a list
this would work, you would just need to make a method in your inventory class that returns a list per type
correct me if Im wrong, but I believe searching for types like this wont work
i have no idea
this isnt correct code
good utility if you havent used bit enums before
Ill look into it tyty
enums like , armour, gauntlet, weapon
would you suggest against using linq?
way better than normal enums since you can check multiple types with one operation
and I don't really use linq but it's pretty powerful
I just remember seeing someone say that its slow, especially for games but idk
if u plan to have item to be helmet and chestplate at the same time that is 
They don't need to be a combination, each bit would be what's required to be added to the list
how would that work Ive used flagged enums like twice in my life
im pretty sure I use it a lot in one of my projects like that
cause I had a weapon system that I needed to check weapon requirements for mods
hummm
Yeah, you make a bit field with the bits you want flipped, you bitwise AND with the item's field and if the value is > 0 then you add it to the list
so https://hatebin.com/myyopdlpru what do I change here so DisplayRelatedItems could get two types of items at once making use of flags
there's this too
when you don't want to use bitoperations lol
is ur profile pic from transformice btw? 
So this method will return back true if one or more enum flags are set, so for an example of the inventory scan, even if more than 1 item is flagged by different types, it should still be true and be added to the list Returns true if all flags are set it looks like
I see
Turns out I am dumb and I was only calcing half the size of the radius so I just had to multiply by 2 lol. Thanks for the help
whats up with microsoft using food examples tho its always bread eggs or dessert
https://i.imgur.com/n4dtGzU.png
Right so, 1010 would be the bitmask that you're looking for. 1101 would be the item enum type. Since the AND flipped and gave us back something greater than 0, we add it to the list.
ideally, your item type should only have a single bit set
I think I was wrong about has flags, it looks for all bits to be set
I haven't tested out anything yet, but I want to be prepared for it in case in happens: I have a boxcollider2d as a trigger in front of my player to check if there's something that is interactable. If I'm checking what the other tag is, what would happen if I ran into an instance where I have 2 different tags like NPC and Chest. When other.tag is called is it going to get the first one that entered or will the second one override it, or something else entirely?
It will run each other's code I would assume
what order? Depends what one you collide with first.
lol i left out an important part, I just have it there to change a bool whether there's something interactable in there and nothing else. but if there were 2 different ones in there and then I hit the button to interact, is it going to do both at one time?
Yeah, probably if you're like standing near them using TriggerOnStay (I think that's the name?) and then you press a button, the next update will trigger one after another.
I'm not too sure if the trigger functions do any proximity checks on distance, but if needed you can sphere cast and do that yourself, thus making your own trigger detecting methods
So if you want something to trigger first based on distance when you're in proximity of both triggers
ideally I'm only looking for one of them to happen
Hm, I guess I can have a variable to have the first one saved to, like a list that's only 1 item long and then have it get removed on the ontriggerexit
In that case you'd want to set some type of member bool on your character probably
Yeah, there's a lot of extra logic here gotta think of
upon pressing interact button box cast ahead of player and whatever is hit first with interactable script do stuff with it should be good
alright, thanks for the help guys!
That sounds like a good idea, if by chance it hit both, then do a distance check perhaps
BoxCastAll I assume naturally returns array of who was hit first and last so u could just iterate and stop at first occurence of interactable element
idk tho
show setup for player/camera
Ok I’m on my way home 15 minutes
@rich adder
If I have a variable that is being assigned a new struct every x frames, is that also changing the variable
variable's reference?
do you spawn the player here? you have to bring all its components with you
i spawn it in the player select and put it in a DDOL
you have to bring all the dependencies it has with you then
What would be the easiest way
anything you need to carry over to next scene put them in a common parent and on that parent do DDOL
How would i carry over the camera
?
Why is the player turned off
Structs are not reference types
But it's pretty unclear what you're asking
So you'd have to give a concrete example
not sure what ur asking, did you close the IF ?
I have this code that reassigns a Struct value to latestInput every frame via assembleInput(). Does this mean that, every frame, latestInput is referencing a new object? I'm guessing no since you said that structs are not reference types, so does that mean they are value types?
^
i only use #if Unity_Editor and havent really touched it any other way
you have to close the if statement
it's closed at line 77
if that's what you meant by close
yeah you did #endif ?
not sure what that error complaining about tbh
if you want to exclude the whole file can't you just put it in the Editor folder?
for some reason, my editor folder cant communicate with other scripts outside it
ig cause of assemblies
is the script on a gameobject?
yea
tht might be the issue
I think
its probably trying to serialize the script for build but then it has exluded if editor
unity prob dont like that
Still not clear. We don't see any types here, nor what happens in the assembleInput method.
But to clarify about structs, yes they are value types, so when you assign one it is being copied to a new place in memory and this new assignment doesn't affect the old value in any way.
maybe may be
okay, so lets say I had a struct that I passed as a parameter to a coroutine. That struct would be saved as a local variable in that coroutine, and any updates to the original struct variable would not affect the local variable because structs are a value type, correct?
anyway, this doesnt usually happen in normal build, ig it only exist in the devt build
No, it's not referencing anything at all. It contains the actual struct data
Because it's a value type, not a reference type
ok, ty!
Correct
Note that no matter what, you'd always have a local variable
Even if it was a reference type, doing theParam = new Whatever(); would just overwrite your local variable
(but, conversly, doing theParam.foo = 1; would, indeed, modify the object that both the coroutine and the coroutine's caller have references to)
what is the coroutine's caller ?
whoever called the method
void Foo() {
StartCoroutine(MyCoroutine(anArgument));
}
Foo called MyCoroutine
Comparing Types
Hello, I am attempting to use a custom GUI to update my Sound Manager Volume like so
public class SoundManagerEditor : Editor
{
SoundManager soundManager;
float desiredMusicVolume;
float desiredSoundVolume;
private void OnEnable()
{
soundManager = (SoundManager)target;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (soundManager != null)
{
desiredMusicVolume = EditorGUILayout.Slider("Music Volume:", desiredMusicVolume, 0f, 1f);
soundManager.MusicVolume = desiredMusicVolume;
desiredSoundVolume = EditorGUILayout.Slider("Sound Volume:", desiredSoundVolume, 0f, 1f);
soundManager.SoundVolume = desiredSoundVolume;
}
}
}```
The issue I am having is that I'm not sure how to save the data that I am changing in the inspector. Ideally I'd like to have persistent data between play mode and edit mode and be able to have the data saved after deselecting the object. I really do not know where to start. I looked around a fair bit on the forums and tried SetDirty() to no avail and I am struggling to figure out many other promising methods. Can someone point me towards some useful docs on the subject? I tried asking in [#↕️┃editor-extensions](/guild/489222168727519232/channel/533353544846147585/) but I didn't really see any response. Is anyone here able to help?
I also looked into using serialized properties but the issue is that I am trying to access a value setup with getters and setters which makes the values non-serializable in the first place
Not entirely sure what setup you have, but if the values are not serializable, then they are not saved.🤷♂️
They would be reset as soon as the object is reloaded from disk(deserialized).
How do I do 2D STG-type movement with the visual script editor?
I think you should ask it in visual scripting channel (server)
Ok, thanks.
Guys, I'm experiencing a bug where if you swap weapons while my pistol is reloading, it no longer shoots
I also logged the pistol's active state when switching weapons, it still stays active even though I made a script to specifically disable it's active state when swapping weapons
The pistol is a child of 2 game objects
The 1st parent of the hieracrchy handles the weapon switching
Hello, I am trying to save WorldSave to json but I get this weird text in json file. What is a proper way to save things like that to json?
I am generating tiles in my code and then I return chunk list to WorldSave
I cant see your json but gameobject is not serializable
Don't look at gameobject, I will delete it later. I'm having problems with tileList
Yes
Oh wait
So I have to create a class that will store only values and then load values into tilescript script?
Yes
Ohh
Yeah now it sounds logical
I will try
Can I save scriptable object or do I have to create a new class?
So is already saved in secondary memory?
Can you explain?
I dont know too much on SO but SO should be already stored in file system
I havent tried run time creating SO so idk much on it
when do I need to remove listeners
let's say this
class ClassB {
void Init() {
ClassA.onEvent.AddListener(onEventTriggered);
}
void onEventTriggered() {
// do something
}
}
I know that if I destroy ClassB, I have to remove the listener to ClassA
but let's say ClassManager destroys ClassA
do I have to remove the listener from ClassB to ClassA using ClassManager before destroying ClassA?
class ClassC {
void DestroyClassA() {
ClassA.onEvent.RemoveListener(ClassB.onEventTriggered);
Destroy(objClassA) // lets say there's an object for ClassA
}
}
based on logic I don't need to remove the listener since the "data" is inside the onEvent class so when destroyed everything would be removed
but just wanted to ask if my assumption is correct
With regular events you should unsubscribe the subscription you make when you dispose of an object. In the case of Unity you can use OnDestroy. I imagine this is the exact same with UnityEvent types, though these might unsubscribe under the hood when destroyed.
It doesn't hurt to just unsubscribe it.
Why is the draw animation only playing once? Even though the active state is toggled back on?
The Awake state only runs once
So I guess your object already exists
Or are you destroying it?
But the active state is toggled off
No
yeah, no worries, I just want to ask to find out how the innerworkings of coding work, and that is it necessary to unsubscribe when the object that has the event is destroyed
The Awake state does not run when you activate a gameObject
What you're looking for is OnEnable and OnDisable
I highly suggest you don't disable an object to simulate weapon switching. Give proper states that play the animation and only disable the object if it's no longer used.
Setting object activity should only be done if you actually don't use it and you should not use it for actual behaviour because you're just limiting yourself
Elaborate please
See last message
I use animation states only to play necessary animations depedning on an event
Whether it's weapon switching or reloading
How can you swap to an entirely different game object without disabling the first game object?
This is my animation controller
Is there a "simple" guide on a functional inventory system anywhere?
I'm currently following a 24 episode YT guide with each video 10-15 minutes, most of it works, but it's so complicated I can't fix the few things that don't work 😦
How do I do that?
Depends what type of inventory you're looking to implement
Create an abstract class that has an "OnSelect" and "OnDeselect" method to implement, and play the animation in there
if it's a simple swip-swap it shouldn't be too hard to find one
But the style of Minecraft may be a little more complex
Anything basic, like runescape like inventory, you have a bunch of slots where you can put items, some are stackable, some are edible, some equipable, ...
I can extend it further myself if I have the basics
Then have a state on the weapon that indicates "UnSelected", "Raising", "Selected", "Lowering" and the OnDeselect class should specify when the state becomes "UnSelected". Then set the weapon on inactive
It's a very rough idea on what I would do
I'm terrible at animations may you please explain a little simpler?
Just do what you do currently, it will probably work fine for now
This is my hierarchy
I more or less exist to give tips and to fix bugs, not refactor projects 😛
I understand but I don't know what to do/what is recommended for weapon swapping
Why is disabling objects impractical?
I've never really worked with that type of inventory tbh
I'l try to find a tutorial
the issue with most tutorials is that they work fine the first 3-4 hours you spend on them, but then later on something doesn't and since I'm a noob I can't figure it out
https://www.youtube.com/watch?v=AoD_F1fSFFg
This doesn't look too bad
Inventory system is used in most of the games. If you need an inventory system in your game, this video is for you. In this video, I will teach you how to make an inventory system from scratch. Enjoy watching.
❤️Support me on Patreon: https://www.patreon.com/solo_gamedev
💙Subscribe to My Channel: http://www.youtube.com/c/SoloGameDev?sub_confirm...
I spend like 8 hours building this one and now some of the functionality doesn't work and I just dunno lol
@burnt vapor
It seems like your flow is to just disable the object when you switch instead of having a proper state system. Works fine as a basic system but you're very limited.
It's something you'll learn as you learn more about game development probably
I might change the system later on but for now I'd like to stick to the OnDisable/OnEnable system
Speaking of, how do I change my draw animation system to draw when it's enabked
Actually nevermind I'll try myself
I'll come back if I have any issues
I believe https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html is what you are looking for
hey
i used this video as a base for my inventory system
In this course long Unity tutorial we will explore how to create an inventory system. You will be able to create multiple items quickly, pick up items, drop items, generate inventory ui and many more. During the whole tutorial I will do my best to share as much knowledge, skills, tips and tricks as I can. This is definitely not ‘complete beginne...
this course is really good
he explains it well as well
looks really nice, i tried it myself and failed massively
so good job
Yea its so much work kind of insane to be honest, I've just got the bare minimum probably not even setup right haha, some god of a man made a outline edge asset using the same techniques t3ssel8r does which massively helped me get a start, I pretty much made the toon shaders and grass been lots of tinkering today to get the color palletes right haha
Deleted the asset link not sure if I can post haha
But I used an asset called upixelator or something like that shit was a god send to make the outline system and its well optimized
The toon shaders though have been a nightmare to setup spent hours messing around with it managed to get it mosty working other than on the grass thats another days problem for me haha
!code
📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
Can someone explain to me why the move tool is at the bottom and not at the feet or on the body of the character? 😄
It is kinda weird to work like that
It's probably related to your model you might want to adjust it's pivot in blender and reimport it
So i am creating a painting images feature in an application for children, Can anyone suggest a tested approach to move in that way, also i need to have brushing the image like effect.
Not click and paint appears
Oh, I got it from mixamo 😄
You can also create an empty gameobject as a pivot then attach your character to that empty object then align it
This should also work
what is the best class to use a static Instantiate method?
Monobehaviour.Instantiate?
oh Object is viable
UnityEngine.Object.Instantiate
Just put it inside of the class youre instantiating
yeah, you just need to have a MonoBehaviour class
https://hastebin.com/share/uduxuzidew.csharp i've got a script for enemy projectiles & and a script for my characters combat entity https://hastebin.com/share/ivesucosuh.csharp ; im trying to make the projectiles get reflected on hit but each time the character hits the projectile, rather than reversering the direction its going, the projectile just destroys itself
are they definetly getting destroyed? not like refelcted down through the grown or somthing?
are you sure it is not going inside this condition?
on the debug log if i hit the projectile whilst attacking, it tells me the bools change but i dont get a debug log saying "enemy projectile hit", also the player doesnt take any damage when the bullet gets reflected so its working half way there
let me double check this
i'm guessing this should have probs said (lethalToPlayer == true) so i've updated that but its not fixed my issue
i've added this debug line but it never shows in the console so i dont think thats what is destroying the projectiles
when you Destroy an object, it stops running its scripts
it's not going to print if you tell it to delete itself and stop running its scripts before it gets to the print statement
i've moved the new debug line to before "destroy (game object)" and its still not showing when i "reflect/attack" the projectile
im going to take out the "destroy" line and see what happens
so the first one is showing but the second one is not?
it gets destroyed anyway
both should be printing if they're right next to each other
so whats happening is that when i attack/reflect the projectile, it says "projectile reflected", tells me the bools are changing, as per the previous screenshot, but theres no messages about the enemy projectile being destroyed or hitting the player if that makes sense. even when i've taken out the "destroy(gameObject)" line, the project still gets destroyed when reflected
is there any other destroy in your code?
also you mean the object gets destroyed not the project right
.
the projectile is getting destroyed not the player
print before the destroy
yeah i've just changed that, thanks
👍
It's not true though
it's not?
"enemy projectile expired" doesnt come up when i "reflect" it
Destroy happens at the end of the frame, and there is no language feature that could stop a method from running midway through
(except throw/catch)
I'd have to test that
There is return👀
Language feature
Yeah
In fact you can't call a method from outside the running method at all.
Unless multithreading is involved.
right so the projectile isnt getting destroyed, its getting yeeted
i managed to find it after pausing the project right after i hit the proj
Sounds like what projectiles do.😬
right but the movement speed that gets set when theyre instantiated is slow af. for some reason on the reflect they get blasted the other way so quickly you cant tell it happened
ok what I think is happening is that the projectiles transform is somehow being reset because they all end up on the far left of the screen when I hit them
The answer is probably in the Movement method.
Unless there's another place where you move the object.
Note that you're subtracting the position under the first if and setting it in the second.
best way to approach this? have a second method called ReverseMovement?
Best approach would be to use physics. But if you really want to move them manually, implement a velocity vector field and just reverse it after collision.
This is 2D right?
yeah!
When I do like reflection and chain, I just change its direction
and keep on adding a speed to it
ok thats definately a much starter way to do it
The movement method doesn't track position, it just calculates how far from the spawn point it has moved
You cant just -movement…. It is not returning direction vector
So when it changes direction it just swings to the opposite side of the spawn point
You can change the spawn point to hit point and treat it as start, a bit weird but it should work
And rotate the transform too
yeah this is what im trying to do now, indeed its rotating far from its spawn point
Could someone explain this syntax to me please?
OnItemBeginDrag?.Invoke(this);
? Is checking if the reference is null and if not, runs the part on the right,
Which looks like a delegate invocation.
If OnItemBeginDrag is not null, it will call Invoke
it's from an inventory building tutorial and I just don't really get why it's done this way
at the top I have:
public event Action<InventoryItem> OnItemClicked, OnItemDroppedOn, OnItemBeginDrag, OnItemEndDrag, OnRightMouseBtnClick;
and then for each of those I have one of those invoke thingies:
{
OnItemDroppedOn?.Invoke(this);
}```
It's a very common way to invoke an event.
It is just a shortcut for:
if(OnItemDroppedOn != null)
{
OnItemDroppedOn.Invoke();
}
Might need to learn about delegates/Actions for better understanding.
It would throw an exception without it if there were no listeners
what is the difference between my OnDrop function and the OnItemDroppedOn event?
why not just directly "access" the event?
I don't really know how to explain my confusion lol
I understand what's happening, I just don't understand why it's with the extra step
One of the reason could be cleaner code, or the function OnDrop could call some other events or methods or set some values in future.
Most of the time in big projects, the author might have modified the method numerous times but forgotten to refactor the code properly.
Are these events being called outside of the class?
Yeah, it's mainly for cleaner code. You don't want every class to reference every other class in your game. Events allow you to build a hierarchy of responsibilities and reverse dependencies
Usually this approach is done on the view (UI elements) and passed into the logic portion (your inventory logic)
that's what the guy in the video said, but I don't get it lol
yeah seems like that's what is happening
it just seems so complicated to me
It is good idea to practice it in the early stages of the project. Because once the project gets big, it is really difficult to change even small things.
but I understand it a bit better now, thx 🙂
When you think about it, it's kinda weird to pass your inventory reference to every slot, but instead doing this way you just bind an event of each slot to your inventory
hi
so.... horse riding
i have been trying to implement a system for over a month now and i think like i might explode soon...
anyone has any ideas on how i could implement the system?
"horse riding" is incredibly vague. You'd need to explain exactly what you want
Nobody knows anything about your game
to be able to ride a horse using raycast when pressing f
when mounted, the player should follow the horses movement and control it
when f is pressed while being mounted, the player will get unmounted and "teleported" next to the horse
Again nobody knows anything about your game so this is still extremely vague
You'd also have to explain which part you're struggling with
what more do you need to know?
The style of the game would be a good start
Is this a 2d side scroller?
First person 3d game?
https://pastebin.com/ZfrMiQbg
this is my current script
when i mount the horse, the player stays on it and i can move in the scene view the horse and the player will move aswell
the problem is with the unmounting (will send a video in a min) but the problem is that the collider just goes wherever the frick it wants and just like deattaches from the player
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
its a 3d first person game
Is there a reason you're manually doing this?
player.position = playerMountPoint.position;
player.rotation = playerMountPoint.rotation;```
Why not just make the player object a child of the mount point
Anyway if your player uses a dynamic rigidbody you'll need to make it kinematic for the duration of being mounted if you want it to actually follow its parent
didnt work
this is the vid i said ill send
look at the scene view in the right
^^
You haven't explained yet how your player normally moves
what do you want to know?
he uses rigidbody, a collider and scripts
need the scripts? the rigidbody settings?
what do you need to know?
@wintry quarry you here?
Hey, someone is working on RTS?
Given the number of people working on games at any given moment and the breadth of genres people like to play, my guess is probably yes
was an invite to talk about rts, digiholic ahah
cause it's my first attempt and want to know how to organize scripts
Hi. I am just wondering if anyone can see an issue to why the character doesnt rotate to where the mouse is.
it was working before which is why I'm confused
Hey does anyone know how to fix this?
It was working before what?
I don't see anything in this code that would rotate a character at all
It was. yes. I was following a series and it was working. I come back today. and it isnt
Again - there is no code here at all that would rotate any object
I would guess that yesterday your code was different
I suggest following the tutorial again
^ seems something was skipped
¯_(ツ)_/¯
The error explains what's happening pretty well. You have a broken script on the prefab
you can't save it until you fix that
you also have at least one compile error
that will need to be fixed before anything else
Vector2 aimDirection = mousePosition - rb.position;
float aimAngle = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg - 90f;
This computes a vector pointing from the player position to the mouse position.
It then computes an angle from that vector.
The function then ends.
Characters are not rotated by wishful thinking.
If it was working before, then your code must have previously done something with that angle variable.
I need a vacation. fml
rb.rotation = aimAngle;
was needed. thats all
Thanks @swift crag & @wintry quarry . you're continued help is very appreciated ❤️
That will do it.
One useful thing: your IDE should be highlighting unused variables.
Notice how the second myVar is gray.
An unused variable suggests that you forgot to do something.
yup.....
in this case, it'll say "unnecessary assignment"
because, indeed, that assignment accomplished nothing
trust me. I feel like a melon. :p
I need to configure it better. I struggle seeing the different blues
Been working on creating a 3D Pixel Art system heavily inspired by t3ssel8r, Im very new to unity so pretty happy with what I've got so far, and wanted to share, struggling to get the toon lighting to apply to the grass though any tips https://youtu.be/o5xl6B5mrs0
Just wanted to share a 3D Pixel Art system heavily inspired by the all mighty t3ssel8r, I am very new to unity and kind of just threw stuff together give me any tips if you have any.
i have two 3d objects, object A is behind object B, but i need A to render above B, how to do that? if i change renderer.material.renderQueue nothing changes
maybe look into renderer features if you're in URP
i'm in URP but i have no idea what to do
A bit old but useful https://www.youtube.com/watch?v=szsWx9IQVDI
Let's learn how to render characters behind other objects using Scriptable Render Passes!
This video is sponsored by Unity
● Download Project: https://ole.unity.com/occlusiondemo
● More on Lightweight: https://ole.unity.com/lightweight
····················································································
♥ Subscribe: http://b...
^ little note on this : LWRP is now URP Universal Render Pipeline
(if name confuses u or anything)
thank you, but it is not what i need. I need some kind of render order so ~10 objects will not clip through each other while being on same z in pseudo 2d
i believe you could do that with ZTest Always and setting material renderQueue for each object in built-in renderer
why not use the order number on the sprite renderer then ?
how do i make dont destroy so music will stay playing
cannot use it with 3d, right?
I thought you said 2D
literally dont destroy on load has an example just for this usecase
pseudo 2d, navigation is 2d but 3d models on zero Z
huh if its 3D models then ur using the 3D render then look into the render feature ? i dont understand lol
it literally allows you to mess with render order so idk
you mean rendering layers? i'm complete noob so i don't understand what you mean by "render feature"
did you look at the video ?
it explain its purpose
here is another example of renderer feature and what you can do @tawdry mirage
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@12.1/manual/renderer-features/how-to-custom-effect-render-objects.html
if the objects are 3D why not just put them physically in the desired order
are you using an orthographic camera?
yes
then you are free to move the objects further/closer to the camera to achieve the desired ordering
i think point light will not look so great
Hey, why cant I invoke this function?
Thank you apologies
you invoking from wrong class
I think I found a solution to my horse problem
will update
Does the class you're calling Invoke on have a function named ChangePlayerStateToIdle?
Yes it does, I even put nameof, to make sure
and then, strings?
Show the full !code of the class
📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
player.Invoke(nameof(ChangePlayerStateToIdle
Doesnt exist in the current context then
https://hatebin.com/lywwdjdtzo idk whats wrong
is player a script / mono ?
send script #💻┃code-beginner message
Duplicate script
yes thanks
sorry because ur usingnameof instead of string, you would do instead
player.Invoke(nameof(player.MethodName
ah okay let me try it
Are there any resources to better understand how to read the profiler. I have parts of my game that drops frames but I have so many objects doing their own thing I'm not sure what I need to try and optimise, going through them one by one will take ages.
well, not really
You basically want to just look at the largest time-takers first.
wdym ? whats wrong? Just tested it and works..
Is that the tall spikes?
@delicate portal also just use a coroutine lmao
spikes imply you're looking at the chart at the top
that just tells you how long the whole frame took
I dont like the pattern
Yeah I am
when you are looking at an individual frame, the section at the bottom breaks down how much time is spent in individual scripts/functions etc
that's where you need to look to find your bottlenecks
Invokes suck because they can't be stored into variables / stopped.
also you can't yield them like coroutines can
Get over it
naa
I'm just watching the spikes while the game runs but I have so many things spawning from object pool I'm not sure which one js cause the lag
I just told you how to identify the issue
Look at the bottom part:
It's a breakdown of how much time each function is taking
the biggest/widest things are the slowest
and need to be looked at
public void Timer(float time)
{
StartCoroutine(Timed(time));
}
private IEnumerator Timed(float time)
{
yield return new WaitForSeconds(time);
//thing
}```
myscript.Timer(3);
Right so is it colour coded or is it the length that I can gauge which script is the issue
Yeah thanks
just in case someone would do something similar: default URP Lit shader lack something that Shader graph generated URP Lit has. In Shader graph window set Depth Test to Always and then you can change material.renderQueue at runtime and it will work.
Copy-pasting default URP Lit and editing ZTest there didn't work.
This can be very powerful, you can also pass functions inside as params
So you solved it?
yep. But now i need to learn shader graph lol
Nice
better than Shader code!
Where do you go to add the Nav Mesh Agent?
Are you in 2022?
Add Component
Yes
You need the AI package
then you can Add Component
no clue why they decided to extract it out of the editor 🤷 maybe its just "clutter"
or easier to update
It lets the package be updated without needing to change editor versions
yeah figured it was that , makes sense
Where can I go to see the packages I need to download?
wdym? you see the screenshot
Okay, nvm I got it
It's nice that it's finally been moved entirely into a package
it was in a weird limbo state for a while
yeah the AI "extras" was annoying have to install to get navmesh surface
glad its all unified
Hey 👋
So I imported a model from mixamo and followed a tutorial where I should extract the materials. Now I got this message in the console. The materials are in my folder though:
Will I face problems? 😅
no its just edit window bugged out you can clear it and ignore it, also not a code question
Does GameObject.Instantiate() set the relative position to 0,0,0 by default?
It has a parameter for the position
It uses whatever the position of the thing you're instantiating has, unless you specify it
yea default pos without specifying is vector3.zero world pos
wait does it?
interesting..thought it spawned at 0
Pretty sure it does. I'm not actually able to test it at the moment
Thank you! Yeah I didn't know where I should put the question into, my bad
ahh Ok I guess I did remember correctly.
cause it could've sworn was one of my first unity mistakes few years back, was wondering why it wasnt spawning by spawner 😅 ..
I suppose if you just spawning object with scripts, world 0,0,0 is no big deal
Hey, how to really use EventArgs?
I don't recommend using the EventArgs pattern in Unity
it leads to unecessary memory allocation/garbage collection
better to define your own delegate type or use Action and its derivatives
What I want is to Store the plant from the event, and that is a type of 'BasePlant'. So something like StorePlant(e.referenceToThatBasePlantFromWhereTheEventWasInvoked)
right you want to pass the plant reference through the event
do either of these:
public delegate void PlantEventHandler(Plant p);
public event PlantEventHandler OnHarvest;```
OR
```cs
public event Action<Plant> OnHarvest;```
a simple EventHandler is not the greatest approach then I assume
EventHandler is not simple
I can invoke actions the same right?
EventHandler is a catchall pattern intended for use in standard .NET application
but it creates a bunch of extraneous objects
this is simpler than eventhandler
you invoke them with whatever parameters the delegate type you are using requires
in this case, a Plant
Sure, for example like this:
I just cant figure out the correct synax with actions
you're using the wrong parameters
you passed in this
which is not in the parameter list
My bad of course
if you want to pass this in, you need to have whatever type that is as one of the parameters in the delegate type
Sorry, again, how can I liste to an action from another class and then pass it in pars?
Yeah Thank you
the other class doesn't pass in parameters
it receives them
listen to an event with theEvent += MyListener;
MyListener must also match the delegate type
so for example
void MyListener(Plant p) {
p.Whatever();
}```
how to check if two trigger collider are overlapping?
So now I can StorePlant(obj)
OnTriggerEnter or direct physics queries
oh sure
which physics method is needed?
Thank you, you helped me a lot with this Action stuff
I'm gonna use theese a lot more
Well, EventHandlers are prefereable for me but still...
what does event handler give you that you are missing?
If you want to pass the "source" object, you can do that just as easily here
public delegate void PlantHarvestHandler(Player source, BasePlant plant);
public event PlantHarvestHandler OnHarvest;
OnHarvest += HarvestCallback;
void HarvestCallback(Player source, BasePlant plant) {
// whatever
}```
Hey, I am using Visual Studio 2022 and in the IDE itself it doesn't show me errors.
I intentionally wrote some errors but it doesn't say anything. In the Unity editor I get the errors but how do I enable them in Visual Studio?
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code*
• JetBrains Rider
• Other/None
*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.
Thanks ❤️
Error is ;expected and invalid expression term '}' ... I understand what the errors mean, all my "}" are good and my ";" are good. I'm guessing it's the way the code is put together
Where the error is, you have the { and } swapped. Refer to the other if statements.
{ opens, } closes
this is where something like if(gunheat >0 ) return;
clean up those nesting
I need to read up on returns.
not too sure how to use them in something like this
just returns out of the function, in this case the function is void. so it doesnt do anything below it and doesn need to return a value
its like saying , dont do the rest of this code and leave early
that. makes sense. i'll do some reading now. Thank youu
i did this but vs code still isnt underlining code or autocompleting
you did what exactly
went on the installer clicked modify on my install and checked game development
There are more steps
You're talking about VS Code but showing screenshots of the installer for Visual Studio 2019/2022??
ohh ye mb
These are two different programs, although named similarly
im used to typing vs code
Post a full screenshot of VS, with the Solution Explorer tab visible
If it's not there, select View > Solution Explorer
Also, i didn't see earlier (just jumping in, sorry if that causes confusion), but did you get the package inside unity?
it says its incompatible
i just noticed it
Right-click and select "Reload with dependencies"
seems like that fixed it
Just curious about these errors. It'll happen. I'll comment what part of the script i think is bad. it'll work. I'll uncomment, It'll work once then spam this error again.
Select the error to reveal the stack trace in the bottom half section of the Console. This contains information on where the exception occurred.
how would i make it so each process type displays its own information?
https://hastebin.skyra.pw/ajijuwenul.csharp
this is the wood item for example
what if i didnt want like process outcomes or temperature to show on a smelt process type
I havent a clue how to debug that. I did look it up on my other project and couldnt find a solution
Look at the stack trace, as I said
restart editor?
Posting it here is an option
done that
shall i just post it or but it in hatebin or something?
Sure, if it's very long.
Here in a code block if it's less than 10 lines
Okay, reading stack traces tutorial time
It's read from top to bottom. The first two lines are the error and the message
The following lines point to where in the code it happened
UnityEditor.SerializedObject.FindProperty (System.String propertyPath) (at <fe7039efe678478d9c83e73bc6a6566d>:0)
UnityEditor.SerializedObject.FindProperty (System.String propertyPath) : method in which the error occurred
at <fe7039efe678478d9c83e73bc6a6566d>:0 location and position in the code.
This one is special because there is no file name and the line number is 0, indicating it didn't happen in your code.
If all the lines don't point to any of your code, the error is internal to Unity and can be ignored
anyone know if this is possible?
without editor scripts
Custom inspectors
oh wow. Seems straight forward if I learned the meanings in it.
could i like use SO's somehow?
like make a script called ProcessData
So does this mean that unity is having a buggy moment. aka it working once then doing that?
If it's persisting, I would suggest resetting your layout. Also, check if the error pops up when a specific object is selected
text component can run functions when clicked on right
TextMeshPro can add "links" to the text, iirc
You can also detect clicks on any UI element
if you just want to click somewhere on it
I did notice it was random.
not aimed at any specific object
When it comes from your own code, you'll get a file path and a line number, like this
(at Assets/Scripts/MyScript.cs:32)
// File 'MyScript' ^~ Line 32
every error like this I've gotten I havent gotten it like that. Even on my other project
maybe bad install of unity
You'll get them once you start creating more scripts for sure
Unless you're really good and produce flawless code
Or you managed to squeeze through all the edge cases that would cause exceptions
gotcha. So they dont happen like that if for example, too many things in scripts are public and interferring with one another. That'll show the location like you showed?
nope
you probably just dont notice when you do get the errors with your own code. try just writing something rn that'd result in an error and then look around in the console
itll always print the stack trace
why is it not coming
Thank you so much
Does the class name match the file name
?
It really depends on the exception type and the error message, but exceptions always happen when the game runs (unless you make scripts that run in the Editor).
Compiler errors happen when the game does not run, when you modified the code but there is a syntax issue, or type check issue whatever. Compiler errors will prevent you from playing the game.
Does the class name match the file name
idk what that means
Does the name of the file match the name of the class inside it
wtf
Do you have any compile errors
Thank you. It would play for half a second then crash.
if this is 2022, try to trigger a manual refresh / recompile @shadow flame
rightclick project window and hit Reimport (not all)
ah, but that suggests it is a MonoBehaviour
You may have "Error Pause" option enabled if play mode pauses when you receive an error.
ctrl-r or cmd-r will ask Unity to reload, or you can do what navarone suggested
(and make sure you've saved in the code editor, of course)
i do.
whats a better way to make the process types?
https://hastebin.skyra.pw/idavevudeq.csharp
i dont really want all of the info on the item data
i was thinking of like a scriptable object for ProcessData
but im not sure how that would work
cause this looks really messy
I have an array of vectors that needs constantly updating basically every tick. is it okay to completely clear the array and remake it each time? I am wondering if that is very intensive
Remaking it, as in doing = new Vector3[n] each frame? Yes expensive, especially if the array is large. Use the same array but replace the vectors in it instead
how can i cap a variable
like i want it so that the players first person camera can't go completely upside down so how can i make it so the X can't go over 90/-90
Use Mathf.Clamp()
thanks
i want to make my plane shoot, so i did an instantiate inside an if, and im not getting syntax errors but it doesnt work anyone got any tips
i have the bullet prefab as a child of the plane and it has a script that makes it move but it just dont work
nice CC pfp
thank you
saw them recently
Start debugging, place a log inside the if statement to ensure the code is running
im jelous
no links just events
and on regular text component
if i want only part of text to work for event i need make new component?
I've found where the lag spike happens, but how do i work out what script or object it is?
do i need to include +1 at the end?
return UnityEngine.Random.Range((int)amount.x, (int)amount.y + 1);
Vector2Int exists, btw
if my number are like 1 and 3, it wont pick 3 if i dont add 1?
and yes, if you want the range to be inclusive, add one to the upper bound
no. it would, however, get rid of those (int) casts.
At the bottom it shows you a breakdown of function calls eating performance. Player Loop represents the game itself, within it the one you have highlighted is all FixedUpdates you have
The drop-down arrow on the left will show more details
Try to reprofile with deep profiling enabled
(click the button at the top)
Shift the marker in the timeline around that little spike you're sitting on, see if there's any piece of code that's is ramping up or something
Thanks, i got 16% RenderCameraStack, is that an issue?
Hey,
Is there a way to store multiple Vector2Int's in one List but in a List in a List.
So i want to save the positions of the Tiles from the Rooms in my game in a list but want all rooms have a own list so i can edit them later on per room and not general. So is there any way to save all Vector2Int's in one List but just Seperated.
Hope you guys understand what i mean
Like a List<List<Vector2Int>>?
Yea ty i was kinda lost sorry for the question xD
it does sound like you want some class (room) to hold the list of vector2int, then another object would hold a List<Room>. If you do it this way, its a little easier to separate what a room is but would basically be a List<List<Vector2Int>>. the room class can hold extra functionality if needed too
instead of doing this```cs
FuelProcess fuelProcess = fuelItem.GetProcess(ProcessData.ProcessType.Fuel) as FuelProcess;
foreach(var outcome in fuelProcess.processOutcomes)
{
} how can i make it one line like below?cs
foreach(var outcome in fuelItem.GetProcess(ProcessData.ProcessType.Fuel).processOutcomes)
{
}```
this is GetProcess method```cs
public ProcessData GetProcess(ProcessData.ProcessType processType)
{
foreach(var processData in itemData.processDatas)
{
if(processData.processType == processType)
{
return processData;
}
}
return null;
}```
i need GetProcess to return as the process
so that i dont need to add as FuelProcess; or as CookProcess; or as SmeltProcess; and so on
any advice on how I can make a snake like boss? I started out by separating the head and body sprits.
Anyone know of a tutorial that can help maybe?
https://hastebin.com/share/tamamekefe.csharp i'm trying to adjust/use/make a turret script to find the closest enemy projectile within circle collider 2d but it never seems to find any projectiles, consequently the rest of the script doesnt progress. the turret never turns. i've tried to set the list as public to see if it comes up with any results but if i make the object and list public, it gives me the error in the first screenshot. now I think the issue may stem in the second screenshot, I dont understand how the script is meant to be giving a component to a object within its circle collider? is it meant to be working as some kind of mark/tag? the script i'm using/adapting is at the bottom of here https://gamedevacademy.org/tower-defense-tower-unity-tutorial/ ultimately i'd like turret to fire a shader graph made laser on the cool down on the closest target but i've not gotten around to making that half of the script#
this debug message appears in the console but i then get an error message that "curProjectile" has no object assigned
Where do you assign curProjectile
debug means that it reached that line, you aren't even debugging curProjectile
And can GetProjectile return null?
You should debug the curProjectilesInRange.Count
Connect your IDE to unity and throw some break points around
I think my IDE is already set up, has been for a while now
put breakpoints in GetProjectile and debug/inspect your count or the returned projectiles
They don't mean set it up. They mean use a feature of it.
Breakpoints and the debugger.
In VisualStudio, it should say "Attach to Unity" at the top, near the middle.
I also recommend that
i've clicked attach to unity and im unsure what im meant to do from here
I got some requests on how to use debugging for C# code in Unity projects and Visual Studio so here is an example project with a UI panel in which I show you how to use the debugger and breakpoints.
You can download the free community edition of Visual Studio 2019 here:
https://visualstudio.microsoft.com/de/downloads/
Debugging is essential wh...
alt f4
That's it. Now run it in the editor
You can also attach it if your program is already running which is nice AND be able to set new break points as it's running
well make sure you got some actual breakpoints lol
ok, going through this bit by bit, i want to debug log count the list of "curProjectilesInRange" but what I thought would be the right debug log message for it doesnt seem to work : Debug.Log("Projectiles Found" + curProjectilesInRange.Count.ToString());
You sure your code is reaching them? Make sure that your code flows through first because sometimes it may not print if you have errors beforehand.
i want this object to disactivate it self when touching the player and activate after a few seconds
but it never activate itself again
why is that??
When an object is destroyed or disabled all coroutines running on it stop
so how to fix this?
Don't run the coroutine on the object that's going to be disabled
anyone know why my colors randomly dissepeared?
like the class used to be red
and most items arent in color anymore
Are you using VSCode?
yup
Yeah it does that
any way to fix it?
Yes
But if you want. You can try regenerating the project files first
I actually been liking vscode
VS can do everything vs code can do, but also more
because between vs and unity, they both like to just freeze up and idle for hours and that's more than I can handle
Has anyone ever experienced when you instantiate an object it automatically turns the triggers in its colliders off?
no
maybe the object you are instantiating already has its colliders off
I've like quadruple checked everything
like what?
Show code
The prefabs colliders, my code that instantiates it, my codes within the prefab
Of which SummonEnemy is called by a button
Okay, show the inspector for enemyPrefab
Okay, now show the inspector of the one that gets spawned
Keep going until it doesn't, keep the game running when you find it
Heres one that doesnt
Those colliders aren't disabled
The trigger is
its the trigger thats the problem. It needs to be enabled on the first collider
Triggers don't just toggle. Something you're doing is toggling it
So look for anywhere in code you're changing isTrigger of anything
i've managed to add a breakpoint! its telling me theres zero projectiles in range, even tho they all have the "projectile" tag. i've added a load of text debug messages. whilst the projectiles are colliding with the circle2d collider, theyre not getting added to the list
That error looks like your problem
Seems ProjectileCurrent isn't a monobehaviour
I found a bit of code on a different object that had the same purpose of the one on the prefab, but had isTrigger. That should fix it, thanks
so i need to have a component (could be a script) in the object titled "ProjectileCurrent"?
The things you get with GetComponent have to be Components
"ProjectileCurrent" i believe is an internal class? and on trigger enter this component is being assigned to any projectile within the 2d circle collider? or is that not how its working
Show the code for ProjectileCurrent
its at the bottom of that screenshot?
np!
how do i attach a camera to a player when loading a new scene
Depends on what you mean by "attach"
It doesn't look like you have any DontDestroyOnLoads or additive scene loadings you just didn't assign a camera
This has nothing to do with the scene changing
would someone be able to explain why these two aren't the same?
(null ref exception when the latter is run)
gameObject.transform.Find("Item").GetComponent<Image>().sprite = item.Icon;
icon.sprite = item.Icon;
where
icon = gameObject.transform.Find("Item").GetComponent<Image>();```
it doesnt really matter, its just something that I stumbled into while trying to make some code look nice and cant figure out why
one is setting a sprite to something , the other just grabs the Image component from something
sorry the message is formatted weird, the first code block is the two lines that I am comparing, and the second block is context for the 2nd item in the first block
I tried to adjust it so its a bit easier to read
are they on different objects?
same object
careful with transform.find, it only looks for children objects name
yeah, this is for a item slot that is instantiated when the inventory is opened
can you show the entire error null ref
yeah, just one sec I need to rewrite the code
well after putting it back in it works just fine 
Hey,
For the past 2 hours i am trying to save my Vector2Int's from my room in the function List<List<Vector2Int>> RoomsPositionList = new List<List<Vector2Int>>(); with RoomPositionList[r].Add(position); but when i try to run the code its always saying me
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
https://gdl.space/gizuvuxoke.cs
What is the problem?
!code
📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
Sure sorry
also which line is error
correct me if I'm wrong but you are trying to call an index of an empty list
your current size for RoomsPositionList is 0 but you're trying to modify 1 ?
ohh wait this is a list of list
Okay but how could i change it than with code? Because a List<List<T>> will not get shown in the Inspetor and as is know it should work beause its a List of an List
does anyone know what im doing wrong?
not sure what you're going for you can probably do RoomsPositionList = new(roomsList.Count);
Yea i also thought about this the problem is that RoomsList is and BoundsInt and i need it in Vector2Int so i can place items later on
Could you copy the hole script in one of these?
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/
!vscode
but you only want a size from it?
what do i do after i copy it?
Copy the Link and send it in here but first save it
No i place the Tiles in the positions and than i want later on place random object of some of these positions this is why i need it in a List<List> because there should be diffrent types of Rooms
Btw you can also do this like so
[Serializable]
public struct ListOfList
{
public List<Vector2Int> MyList;
}
public class MyClass: MonoBehaviour
{
public List<ListOfList> rooms = new();
}
Try this
function = gameObject.GetComponent<PlayerMovement>();
i will try it one sec
get them to configure their IDE first
its in the #854851968446365696
i alr tried to configure it but it doesnt work
what did you try exactly, b specific ? wdym doesn't work cause it does for everyone lese
now i got these errors
i followed the !IDE instructions
If your IDE is not autocompleting code
or underlining errors, please configure it:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code*
• JetBrains Rider
• Other/None
*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.
the VSCode one?
Should this get shown in the Inspector?
it should
actually no don't use that , that will just make clones of same list
mb
yes
oh okay
You got the Unity extension from Microsoft in VS Code
and
the Visual Studio Editor package (not VS Code Editor) in the Unity package manager?
https://gdl.space/vuzokiyosi.cs
How can i now add in such a list things bc now i get the error error CS1061: 'ListOfList' does not contain a definition for 'Add' and no accessible extension method 'Add' accepting a first argument of type 'ListOfList' could be found (are you missing a using directive or an assembly reference?
i dont understand
What part? Those are the things the IDE guide tells you to do
They are required for it to work
how do i doownload the package
Go to unity's package manager
Within unity, in the Window menu
and?
And what? Get the package I said.
Visual Studio Editor version 2.0.21
when i press window what do i do next
before installing the package
Go.. to package manager....
Window > Package Manager > get the package
[Serializable]
public class ListOfList
{
public List<Vector2Int> MyList = new();
}
public class Something : MonoBehaviour
{
public List<ListOfList> rooms = new();
void Method()
{
ListOfList list1 = new();
list1.MyList.Add(new Vector2Int(3, 4));
rooms.Add(list1);
}```
k
I'm working on an FPS controller. I'm using the new input system and cinemachine. I'm noticing that when I move the mouse when I reach the edge of the screen I can't move the mouse any more in that direction so I can't rotate the view any more. Not sure if it matters but my curser is visible. I'm also using Mouse (Delta) for the mouse look input. How do I get it so I keep getting Mouse (Delta) values even if the mouse can't move any more on the screen?
You should lock your cursor
i alr have it downloaded
but i use vs code not vs
That was it, thanks!
Both editors use the Visual Studio package now, after Unity dropped support for VS Code in like May
If it still isn't working, go to Edit > Preferences > External Tools and click Regenerate Project Files
Is there any way to see a List<List<T>> in the Inspector?
this is the way lol
is this what im supposed to be seeing?
oh haha
@neon wedge No, MonoBehaviour and those other types should be a different color as far as I know...
public List<ListOfList> rooms = new();
void Method()
{
var list1 = new ListOfList();
list1.MyList.Add(new Vector2Int(3, 4));
list1.MyList.Add(new Vector2Int(3, 4));
list1.MyList.Add(new Vector2Int(8, 8));
list1.MyList.Add(new Vector2Int(7, 7));
rooms.Add(list1);
}
private void Start()
{
Method();
Debug.Log(rooms[0].MyList[2]);
}```
How could i remove all stats?
wdym by "stats"
Remove everything out of the ist
list1.MyList.Clear() //clears one list
or
rooms.Clear() //clears all
ofc just like adding you can also use indexes of list
rooms[0].MyList.Clear();
ty
can u hel me fix the error tho?
hope that clears up a little 😅
did you fix your IDE? or else you will come back later with another syntax error
Yea just one last question can i normaly check them so like "rooms[1]"?
ye i think i fixed it
like rooms[1].MyList.Count
or w/e else
I don't even know what the error was 😂
you always wanna check count before doing index
Ty you realy helped me
they fixed first syntax error but has an NRE
#💻┃code-beginner message
oh also using class instead of instance
how do i use it?
PlayerMovement.grounded == false < why are you using PlayerMovement here before the .? That's the class itself.
oh wait second error is not NRE
Shows you how to understand and diagnose nullreferenceexceptions
its Input class missing"jump" ig class is missing Jump() method being defined
OOP, I was led astray!
myb
this whole line is redundant function = gameObject.GetComponent<PlayerMovement>();
function is already public, just drag the component inside script , its on the same object
i dont understand what you mean
aand why is it called function? 😢
idk i just named it or smth
you don't want to know if "the concept of PlayerMovement" is grounded. You want to know if the particular instance of that script that is attached to your player is grounded. Adjust your code as such
do you even know what you are naming?
it's a reference to a particular instance of that script.
that's the thing you should be interacting with.
^^ name should be clear what component it is you're using
if class is called PlayerMovement then ideally you would just name it playerMovement instead of function
or player or anything reasonable
Hi! I am trying to make some walking and idle animations, but I don’t know how I can make it so that the player idle animation faces in the direction it was last moving in.
2d or 3D ?
how are you currently rotating player? do you have script you can share
Yes, I do. But let me get it first.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
Vector2 movement;
public float moveSpeed = 5f;
public Rigidbody2D rb;
public Animator animator;
private void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.sqrMagnitude);
}
private void FixedUpdate()
{
rb.MovePosition(rb.position + movement.normalized * moveSpeed * Time.fixedDeltaTime);
}
}
This rotates the player to wherever it's moving.
hey sorry to bother you again..
But how could i now get a Vector2Int out of it for example i want now a random Vector2Int
ohh you're using a blend tree or something?
int randomIndexOfRoom = rooms[0].MyList.Count;
Vector2Int randomCoordinate = rooms[0].MyList[randomIndexOfRoom];```
you can do the same thing for rooms ofc
Are blend trees not good for this?
i guess you could modify the floats only if you're moving
if(movement != Vector2.zero) { anim.SetFloat etc..
Thank you so much, the player now faces in the correct direction, and all I have to do is make the idle animations. I do have to go now, but thank you for the help.
unity is giving me a warning when writing an awake method for a button class?
'EquipmentSlot.Awake()' hides inherited member 'Selectable.Awake()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
Button inherits from mono so using Awake the same way as a mono script shouldn't be problem?
EquipmentSlot inherits from Selectable, and then THAT inherits from MonoBehaviour? Can you show the code of the two classes?
selectable is a unity script
which according to the docs none of the children override Awake so idk
I think that it is not quite the same as a MonoBehaviour Awake. Try just doing override and using base.Awake()
I mean I can but
Yeah, I saw that.
Your parent Selectable class needs to be protected virtual void Awake(){} and so your child EquipmentSlot class can:
protected override void Awake()
{
base.Awake();
// Additional things this child class does
}
thanks!
Hi, given this line Debug.Log(wheel_velocity_LS + " -> " + wheel_velocity_LS.x + " == " + Vector3.Dot(wheel_velocity_LS, transform.right));
In my basic knowledge of vectors, wheel_velocity_LS.x and Vector3.Dot(wheel_velocity_LS, transform.right) should be the same value, however I am getting this:
(5.01, 0.34, 26.74) -> 5.01121 == 13.19427
Can someone explain to me whats going on please?
The formula for dot product is easy. Given Vector3 A and Vector3 B, it's just ((A.x * B.x) + (A.y * B.y) + (A.z * B.z))
You should log the transform.right vector and see what it comes up as and just do the math to understand more fully
I would expect it to ONLY be the same if the transform.right vector lines up perfectly with the Vector3.right WORLD vector (thus zeroing out y and z)
Makes sense, thank you
!code
📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
mb
Not embarrasing at all. Thank you