#💻┃code-beginner

1 messages · Page 19 of 1

swift crag
#

This does not appear to be a problem with your code.

tight zenith
#

Thanks!

acoustic arch
#

what's the different with

#

EulerAngles and LocalEulerAngles

polar acorn
#

One of them is world space, one of them is relative to the parent

acoustic arch
#

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?

polar acorn
acoustic arch
#

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

polar acorn
#

Position has nothing to do with orientation

#

If your character moves forward on the x axis that has nothing to do with euler angles

acoustic arch
#

i mean where it's facing

ashen ferry
#

create 2 empty gameobjects rotate one and make second a child of it look what changes

polar acorn
# acoustic arch can you give me an example

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

acoustic arch
polar acorn
#

It's local euler angles is 0,0,0

#

it's world space euler angles is 0,90,0

acoustic arch
#

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

polar acorn
#

world space would be 0, 30, 0

acoustic arch
#

alright gotcha thanks

#

i'm on the self unity learning grind rn

gleaming steppe
#

Hi, do you think there's a way to affect meshes with code, like extruding at random positions?

#

maybe with probuilder ?

timber tide
#

usually you'd use something like a vertex shader for that, but I guess you can edit the vertex data directly

gleaming steppe
#

with HLSL ?

timber tide
#

Ye, unless you can make them with shaderlab yet]

gleaming steppe
#

ok will dig that, thx

zinc grove
#

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.

silent haven
#

how do i change the material

timber tide
#

drag it on there

brisk thicket
#

seems the most efficient

timber tide
brisk thicket
timber tide
wary sable
#

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?
timber tide
#

few draw methods in there

timber tide
wary sable
timber tide
#

You're trying to loop over a list, and for each item find a helmet?

wary sable
brisk thicket
#

is the loop looking for an item ?

timber tide
#

Like, at runtime you want a search box to filter out item names?

wary sable
#

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
timber tide
#

Probably want to look into regular expressions

#

and some parsing methods, but c# has a lot of libraries for that stuff

brisk thicket
#

or check whether you have something in ur inventory?

wary sable
#

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

ashen ferry
#

so those classes need to share something a parent or interface idk

wary sable
wary sable
#

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

brisk thicket
#

okay

#

i understand

#

i think

ashen ferry
#

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

brisk thicket
#

he cant because the inventory has subcategories he would need to loop through

wary sable
#

if you click on any of the red slots it will bring up all items of that type in the green area

timber tide
#

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

wary sable
wary sable
timber tide
#

Oh so you're trying to scan an inventory for each type of item eh

brisk thicket
#
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

timber tide
#

Yeah, what you can do is make a flag enum

#

send that into your foreach loop of the inventory

brisk thicket
#

i overcomplicated it

#

nvm

#

let me edit it rq

timber tide
#

if item enum type is any bit of this bitwise enum then you add it to a list

brisk thicket
wary sable
timber tide
brisk thicket
#

this isnt correct code

timber tide
#

good utility if you havent used bit enums before

brisk thicket
#

its more of the way to do it

#

enums will work yeah

wary sable
brisk thicket
#

enums like , armour, gauntlet, weapon

wary sable
#

would you suggest against using linq?

timber tide
#

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

wary sable
#

I just remember seeing someone say that its slow, especially for games but idk

ashen ferry
#

if u plan to have item to be helmet and chestplate at the same time that is kekW

timber tide
#

They don't need to be a combination, each bit would be what's required to be added to the list

ashen ferry
#

how would that work Ive used flagged enums like twice in my life

timber tide
#

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

ashen ferry
timber tide
#

there's this too

#

when you don't want to use bitoperations lol

ashen ferry
#

is ur profile pic from transformice btw? kekW

timber tide
#

ye

#

YE

timber tide
ashen ferry
#

I see

zinc grove
timber tide
#

Actually need to test it but there is different operations

#

rusty

ashen ferry
#

whats up with microsoft using food examples tho its always bread eggs or dessert

timber tide
#

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

timber tide
livid jacinth
#

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?

timber tide
#

It will run each other's code I would assume

#

what order? Depends what one you collide with first.

livid jacinth
#

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?

timber tide
#

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

livid jacinth
#

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

timber tide
#

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

ashen ferry
#

upon pressing interact button box cast ahead of player and whatever is hit first with interactable script do stuff with it should be good

livid jacinth
#

alright, thanks for the help guys!

timber tide
#

That sounds like a good idea, if by chance it hit both, then do a distance check perhaps

ashen ferry
#

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

rich adder
#

show setup for player/camera

violet topaz
#

Ok I’m on my way home 15 minutes

violet topaz
#

@rich adder

crisp token
#

If I have a variable that is being assigned a new struct every x frames, is that also changing the variable

#

variable's reference?

rich adder
violet topaz
#

i spawn it in the player select and put it in a DDOL

rich adder
violet topaz
#

What would be the easiest way

rich adder
violet topaz
#

How would i carry over the camera

violet topaz
#

?

rich adder
#

idk

queen adder
#

at line 1

wintry quarry
#

But it's pretty unclear what you're asking

#

So you'd have to give a concrete example

rich adder
crisp token
#

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?

crisp token
queen adder
rich adder
queen adder
#

if that's what you meant by close

rich adder
#

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?

queen adder
#

for some reason, my editor folder cant communicate with other scripts outside it

#

ig cause of assemblies

rich adder
queen adder
#

yea

rich adder
#

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

teal viper
queen adder
#

maybe may be

crisp token
queen adder
#

anyway, this doesnt usually happen in normal build, ig it only exist in the devt build

wintry quarry
#

Because it's a value type, not a reference type

crisp token
#

ok, ty!

swift crag
#

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)

crisp token
swift crag
#

whoever called the method

#
void Foo() {
  StartCoroutine(MyCoroutine(anArgument));
}
#

Foo called MyCoroutine

eager oasis
#

Comparing Types

flint ruin
#

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

teal viper
#

They would be reset as soon as the object is reloaded from disk(deserialized).

ebon helm
#

How do I do 2D STG-type movement with the visual script editor?

gaunt ice
#

I think you should ask it in visual scripting channel (server)

ebon helm
#

Ok, thanks.

cunning rapids
#

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

graceful flicker
#

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

gaunt ice
#

I cant see your json but gameobject is not serializable

graceful flicker
#

Don't look at gameobject, I will delete it later. I'm having problems with tileList

gaunt ice
#

What is tilescript

#

Monobehaviour?

graceful flicker
#

Yes

#

Oh wait

#

So I have to create a class that will store only values and then load values into tilescript script?

gaunt ice
#

Yes

graceful flicker
#

Ohh

#

Yeah now it sounds logical

#

I will try

#

Can I save scriptable object or do I have to create a new class?

gaunt ice
#

So is already saved in secondary memory?

graceful flicker
#

Can you explain?

gaunt ice
#

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

slate ingot
#

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

burnt vapor
#

It doesn't hurt to just unsubscribe it.

cunning rapids
burnt vapor
#

So I guess your object already exists

#

Or are you destroying it?

cunning rapids
#

But the active state is toggled off

cunning rapids
slate ingot
#

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

burnt vapor
#

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

burnt vapor
#

See last message

cunning rapids
#

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?

cunning rapids
topaz mortar
#

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 😦

cunning rapids
burnt vapor
#

Create an abstract class that has an "OnSelect" and "OnDeselect" method to implement, and play the animation in there

cunning rapids
#

But the style of Minecraft may be a little more complex

topaz mortar
burnt vapor
#

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

cunning rapids
burnt vapor
#

Just do what you do currently, it will probably work fine for now

cunning rapids
#

This is my hierarchy

burnt vapor
#

I more or less exist to give tips and to fix bugs, not refactor projects 😛

cunning rapids
#

Why is disabling objects impractical?

cunning rapids
#

I'l try to find a tutorial

topaz mortar
#

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

cunning rapids
#

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...

▶ Play video
topaz mortar
#

I spend like 8 hours building this one and now some of the functionality doesn't work and I just dunno lol

cunning rapids
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

cunning rapids
#

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

charred spoke
brisk thicket
#

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...

▶ Play video
#

this course is really good

#

he explains it well as well

#

looks really nice, i tried it myself and failed massively

#

so good job

noble rover
# brisk thicket looks really nice, i tried it myself and failed massively

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

brisk thicket
#

yeah cba to do all of it haha

#

i would pay tessel8r to give me his shader tho

noble rover
#

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

brisk thicket
#

!code

eternal falconBOT
#
Posting 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.

vital gust
#

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

restive badger
#

It's probably related to your model you might want to adjust it's pivot in blender and reimport it

late sinew
#

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

restive badger
#

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

queen adder
#

what is the best class to use a static Instantiate method?

#

Monobehaviour.Instantiate?

#

oh Object is viable

worn egret
#

UnityEngine.Object.Instantiate

timber tide
#

Just put it inside of the class youre instantiating

worn egret
#

yeah, you just need to have a MonoBehaviour class

zealous oxide
#

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

vast yoke
worn egret
zealous oxide
#

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

zealous oxide
zealous oxide
#

i've added this debug line but it never shows in the console so i dont think thats what is destroying the projectiles

spare mountain
zealous oxide
#

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

spare mountain
zealous oxide
#

it gets destroyed anyway

spare mountain
#

both should be printing if they're right next to each other

zealous oxide
# spare mountain so the first one is showing but the second one is not?

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

spare mountain
#

is there any other destroy in your code?

#

also you mean the object gets destroyed not the project right

zealous oxide
spare mountain
#

could that be destroying it

#

also you did it again

zealous oxide
#

the projectile is getting destroyed not the player

spare mountain
#

print before the destroy

zealous oxide
#

yeah i've just changed that, thanks

spare mountain
#

👍

keen dew
#

It's not true though

spare mountain
#

it's not?

zealous oxide
#

"enemy projectile expired" doesnt come up when i "reflect" it

keen dew
#

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)

spare mountain
#

I'd have to test that

teal viper
#

There is return👀

Language feature

keen dew
#

Touche

#

But you can't call another method that would stop the calling method

teal viper
#

Yeah

#

In fact you can't call a method from outside the running method at all.
Unless multithreading is involved.

zealous oxide
#

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

teal viper
#

Sounds like what projectiles do.😬

zealous oxide
#

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

teal viper
#

The answer is probably in the Movement method.

#

Unless there's another place where you move the object.

zealous oxide
teal viper
#

Note that you're subtracting the position under the first if and setting it in the second.

zealous oxide
#

best way to approach this? have a second method called ReverseMovement?

teal viper
#

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.

timber tide
#

This is 2D right?

zealous oxide
#

yeah!

timber tide
#

When I do like reflection and chain, I just change its direction

#

and keep on adding a speed to it

zealous oxide
#

ok thats definately a much starter way to do it

keen dew
#

The movement method doesn't track position, it just calculates how far from the spawn point it has moved

gaunt ice
#

You cant just -movement…. It is not returning direction vector

keen dew
#

So when it changes direction it just swings to the opposite side of the spawn point

gaunt ice
#

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

zealous oxide
topaz mortar
#

Could someone explain this syntax to me please?
OnItemBeginDrag?.Invoke(this);

teal viper
worn egret
#

If OnItemBeginDrag is not null, it will call Invoke

topaz mortar
#

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);
}```
teal viper
worn egret
#

It is just a shortcut for:

if(OnItemDroppedOn != null)
{
  OnItemDroppedOn.Invoke();
}
teal viper
strong wren
topaz mortar
#

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

worn egret
#

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.

timber tide
teal viper
#

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

timber tide
#

Usually this approach is done on the view (UI elements) and passed into the logic portion (your inventory logic)

topaz mortar
#

yeah seems like that's what is happening

#

it just seems so complicated to me

worn egret
#

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.

topaz mortar
#

but I understand it a bit better now, thx 🙂

timber tide
#

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

keen musk
#

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?

wintry quarry
#

Nobody knows anything about your game

keen musk
#

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

wintry quarry
#

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

keen musk
#

what more do you need to know?

wintry quarry
#

The style of the game would be a good start

#

Is this a 2d side scroller?

#

First person 3d game?

keen musk
#

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

#

its a 3d first person game

wintry quarry
#

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

keen musk
#

this is the vid i said ill send

#

look at the scene view in the right

wintry quarry
#

You haven't explained yet how your player normally moves

keen musk
#

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?

gloomy timber
#

Hey, someone is working on RTS?

polar acorn
gloomy timber
#

was an invite to talk about rts, digiholic ahah

#

cause it's my first attempt and want to know how to organize scripts

silent valley
#

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

hard yarrow
#

Hey does anyone know how to fix this?

wintry quarry
silent valley
#

It was. yes. I was following a series and it was working. I come back today. and it isnt

wintry quarry
#

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

silent valley
#

I have. So many times

#

without skipping

wintry quarry
#

¯_(ツ)_/¯

wintry quarry
#

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

swift crag
#
        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.

silent valley
#

I need a vacation. fml

#

rb.rotation = aimAngle;

#

was needed. thats all

#

Thanks @swift crag & @wintry quarry . you're continued help is very appreciated ❤️

swift crag
#

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.

silent valley
#

yup.....

swift crag
#

in this case, it'll say "unnecessary assignment"

#

because, indeed, that assignment accomplished nothing

silent valley
#

trust me. I feel like a melon. :p

#

I need to configure it better. I struggle seeing the different blues

noble rover
#

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.

▶ Play video
tawdry mirage
#

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

rich adder
#

maybe look into renderer features if you're in URP

tawdry mirage
wintry quarry
# tawdry mirage i'm in URP but i have no idea what to do

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...

▶ Play video
rich adder
#

^ little note on this : LWRP is now URP Universal Render Pipeline

#

(if name confuses u or anything)

tawdry mirage
rich adder
#

why not use the order number on the sprite renderer then ?

shadow flame
#

how do i make dont destroy so music will stay playing

tawdry mirage
rich adder
#

I thought you said 2D

rich adder
tawdry mirage
#

pseudo 2d, navigation is 2d but 3d models on zero Z

rich adder
#

it literally allows you to mess with render order so idk

tawdry mirage
#

you mean rendering layers? i'm complete noob so i don't understand what you mean by "render feature"

rich adder
#

it explain its purpose

wintry quarry
#

are you using an orthographic camera?

tawdry mirage
wintry quarry
#

then you are free to move the objects further/closer to the camera to achieve the desired ordering

tawdry mirage
delicate portal
#

Hey, why cant I invoke this function?

timber tide
noble rover
#

Thank you apologies

rich adder
keen musk
#

I think I found a solution to my horse problem
will update

rich adder
#

you would need to do player.Invoke()

#

Invoke looks for method on monobehavior

polar acorn
delicate portal
delicate portal
polar acorn
eternal falconBOT
#
Posting 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.

rich adder
delicate portal
shadow flame
rich adder
polar acorn
shadow flame
#

yes thanks

rich adder
gray crest
#

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.

wintry quarry
rich adder
gray crest
rich adder
#

@delicate portal also just use a coroutine lmao

wintry quarry
#

that just tells you how long the whole frame took

delicate portal
wintry quarry
# gray crest 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

rich adder
polar acorn
delicate portal
#

Thats true yes

#

Maybe Ican use a tiemr

#

With update

rich adder
#

naa

gray crest
wintry quarry
wintry quarry
#

the biggest/widest things are the slowest

#

and need to be looked at

rich adder
# delicate portal With update
public void Timer(float time)
    {
        StartCoroutine(Timed(time));
    }
    private IEnumerator Timed(float time)
    {
        yield return new WaitForSeconds(time);
        //thing
    }```
#

myscript.Timer(3);

gray crest
tawdry mirage
rich adder
tawdry mirage
rich adder
manic shore
#

Where do you go to add the Nav Mesh Agent?

rich adder
polar acorn
manic shore
rich adder
#

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

polar acorn
#

It lets the package be updated without needing to change editor versions

rich adder
#

yeah figured it was that , makes sense

manic shore
#

Where can I go to see the packages I need to download?

rich adder
manic shore
#

Okay, nvm I got it

swift crag
#

It's nice that it's finally been moved entirely into a package

#

it was in a weird limbo state for a while

rich adder
#

yeah the AI "extras" was annoying have to install to get navmesh surface

#

glad its all unified

sterile river
#

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? 😅

rich adder
small otter
#

Does GameObject.Instantiate() set the relative position to 0,0,0 by default?

wintry quarry
polar acorn
rich adder
rich adder
#

interesting..thought it spawned at 0

polar acorn
#

Pretty sure it does. I'm not actually able to test it at the moment

sterile river
rich adder
#

I suppose if you just spawning object with scripts, world 0,0,0 is no big deal

delicate portal
#

Hey, how to really use EventArgs?

wintry quarry
#

it leads to unecessary memory allocation/garbage collection

#

better to define your own delegate type or use Action and its derivatives

delicate portal
#

What I want is to Store the plant from the event, and that is a type of 'BasePlant'. So something like StorePlant(e.referenceToThatBasePlantFromWhereTheEventWasInvoked)

wintry quarry
polar acorn
wintry quarry
delicate portal
#

a simple EventHandler is not the greatest approach then I assume

wintry quarry
#

EventHandler is not simple

delicate portal
#

I can invoke actions the same right?

wintry quarry
#

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

wintry quarry
#

in this case, a Plant

delicate portal
#

Sure, for example like this:
I just cant figure out the correct synax with actions

wintry quarry
#

you passed in this

#

which is not in the parameter list

delicate portal
#

My bad of course

wintry quarry
#

if you want to pass this in, you need to have whatever type that is as one of the parameters in the delegate type

delicate portal
#

Sorry, again, how can I liste to an action from another class and then pass it in pars?

wintry quarry
#

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();
}```
stiff stump
#

how to check if two trigger collider are overlapping?

delicate portal
#

So now I can StorePlant(obj)

wintry quarry
delicate portal
#

or p, whatever

#

obj is the plant

wintry quarry
#

oh sure

stiff stump
delicate portal
wintry quarry
#

inside the listener you mean?

#

yeah

delicate portal
#

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...

wintry quarry
#

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

wintry quarry
#
public delegate void PlantHarvestHandler(Player source, BasePlant plant);
public event PlantHarvestHandler OnHarvest;

OnHarvest += HarvestCallback;

void HarvestCallback(Player source, BasePlant plant) {
  // whatever
}```
sterile river
#

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?

eternal falconBOT
#
💡 IDE Configuration

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.

sterile river
silent valley
#

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

short hazel
#

{ opens, } closes

silent valley
#

fml

#

Cry Not embarrasing at all. Thank you

rich adder
#

clean up those nesting

silent valley
#

not too sure how to use them in something like this

rich adder
#

its like saying , dont do the rest of this code and leave early

silent valley
dusky finch
# eternal falcon

i did this but vs code still isnt underlining code or autocompleting

dusky finch
#

went on the installer clicked modify on my install and checked game development

short hazel
#

You're talking about VS Code but showing screenshots of the installer for Visual Studio 2019/2022??

dusky finch
#

ohh ye mb

short hazel
#

These are two different programs, although named similarly

dusky finch
#

im used to typing vs code

short hazel
#

Post a full screenshot of VS, with the Solution Explorer tab visible

#

If it's not there, select View > Solution Explorer

summer stump
#

Also, i didn't see earlier (just jumping in, sorry if that causes confusion), but did you get the package inside unity?

dusky finch
#

i just noticed it

short hazel
#

Right-click and select "Reload with dependencies"

dusky finch
#

seems like that fixed it

silent valley
#

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.

short hazel
tender stag
#

this is the wood item for example

#

what if i didnt want like process outcomes or temperature to show on a smelt process type

silent valley
short hazel
#

Look at the stack trace, as I said

short hazel
#

Posting it here is an option

silent valley
silent valley
swift crag
#

Sure, if it's very long.

short hazel
#

Here in a code block if it's less than 10 lines

silent valley
short hazel
#

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

tender stag
#

without editor scripts

silent valley
tender stag
#

like make a script called ProcessData

silent valley
#

So does this mean that unity is having a buggy moment. aka it working once then doing that?

swift crag
#

If it's persisting, I would suggest resetting your layout. Also, check if the error pops up when a specific object is selected

late burrow
#

text component can run functions when clicked on right

swift crag
#

You can also detect clicks on any UI element

#

if you just want to click somewhere on it

silent valley
#

not aimed at any specific object

short hazel
silent valley
#

maybe bad install of unity

short hazel
#

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

silent valley
eternal needle
#

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

shadow flame
#

why is it not coming

silent valley
#

Thank you so much

polar acorn
shadow flame
short hazel
polar acorn
shadow flame
polar acorn
rich adder
#

oh nvm my discord didn't update

rich adder
#

wtf

polar acorn
shadow flame
silent valley
swift crag
#

Show the entire declaration of the class.

#

Perhaps it's not a MonoBehaviour.

rich adder
#

if this is 2022, try to trigger a manual refresh / recompile @shadow flame

#

rightclick project window and hit Reimport (not all)

shadow flame
swift crag
#

ah, but that suggests it is a MonoBehaviour

short hazel
swift crag
#

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)

shadow flame
#

i;ll try that

#

fixed

#

thanks

tender stag
#

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

quaint lynx
#

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

short hazel
#

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

acoustic arch
#

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

short hazel
#

Use Mathf.Clamp()

acoustic arch
#

thanks

empty juniper
#

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

empty juniper
rich adder
#

saw them recently

short hazel
#

Start debugging, place a log inside the if statement to ensure the code is running

late burrow
#

and on regular text component

late burrow
swift crag
#

no idea about the legacy Text component.

#

why not just use TextMeshPro?

gray crest
#

I've found where the lag spike happens, but how do i work out what script or object it is?

tender stag
#

do i need to include +1 at the end?

#

return UnityEngine.Random.Range((int)amount.x, (int)amount.y + 1);

swift crag
#

Vector2Int exists, btw

tender stag
#

if my number are like 1 and 3, it wont pick 3 if i dont add 1?

swift crag
#

and yes, if you want the range to be inclusive, add one to the upper bound

tender stag
#

i wont have to add 1 with that?

swift crag
#

no. it would, however, get rid of those (int) casts.

tender stag
#

oh alright

#

thanks

fossil harness
#

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

gray crest
crisp pollen
#

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

polar acorn
#

Like a List<List<Vector2Int>>?

crisp pollen
eternal needle
tender stag
#

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

timber pelican
#

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?

zealous oxide
#

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#

GameDev Academy

There's no question tower defense games are insanely popular - whether we're talking about the PC market, console market, or mobile game market. Defending a

timber tide
#

Why is your IDE greying out unity's methods there

#

You sure they are being called?

zealous oxide
#

this debug message appears in the console but i then get an error message that "curProjectile" has no object assigned

polar acorn
rich adder
zealous oxide
polar acorn
summer stump
timber tide
#

Connect your IDE to unity and throw some break points around

zealous oxide
#

I think my IDE is already set up, has been for a while now

rich adder
summer stump
zealous oxide
#

i've clicked attach to unity and im unsure what im meant to do from here

polar acorn
# zealous oxide 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...

▶ Play video
timber tide
#

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

rich adder
#

well make sure you got some actual breakpoints lol

zealous oxide
#

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());

timber tide
#

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.

queen adder
#

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??

polar acorn
queen adder
#

so how to fix this?

polar acorn
#

Don't run the coroutine on the object that's going to be disabled

queen adder
#

ig this would kinda fix it

tender stag
#

anyone know why my colors randomly dissepeared?

#

like the class used to be red

#

and most items arent in color anymore

polar acorn
#

Are you using VSCode?

tender stag
#

yup

polar acorn
#

Yeah it does that

tender stag
#

any way to fix it?

polar acorn
#

¯_(ツ)_/¯

#

I'd suggest just using VS

tender stag
#

but themeeesss

#

can u get themes on vs?

summer stump
tender stag
#

what about the like smooth typing and that

#

like smooth scrolling

summer stump
#

But if you want. You can try regenerating the project files first

timber tide
#

I actually been liking vscode

summer stump
tender stag
#

oh

#

i didnt know that

timber tide
#

because between vs and unity, they both like to just freeze up and idle for hours and that's more than I can handle

ruby elk
#

Has anyone ever experienced when you instantiate an object it automatically turns the triggers in its colliders off?

rich adder
#

no

tender stag
#

maybe the object you are instantiating already has its colliders off

ruby elk
#

I've like quadruple checked everything

rich adder
#

like what?

polar acorn
ruby elk
#

The prefabs colliders, my code that instantiates it, my codes within the prefab

#

Of which SummonEnemy is called by a button

polar acorn
#

Okay, show the inspector for enemyPrefab

ruby elk
#

And the trigger is correct, 1 on, 1 off.

polar acorn
#

Okay, now show the inspector of the one that gets spawned

ruby elk
#

Sometimes it works sometimes it doesnt

#

This time it did

polar acorn
#

Keep going until it doesn't, keep the game running when you find it

ruby elk
#

Heres one that doesnt

polar acorn
#

Those colliders aren't disabled

ruby elk
#

The trigger is

#

its the trigger thats the problem. It needs to be enabled on the first collider

polar acorn
#

Triggers don't just toggle. Something you're doing is toggling it

#

So look for anywhere in code you're changing isTrigger of anything

zealous oxide
#

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

polar acorn
#

Seems ProjectileCurrent isn't a monobehaviour

ruby elk
zealous oxide
polar acorn
zealous oxide
#

"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

polar acorn
#

Show the code for ProjectileCurrent

zealous oxide
#

its at the bottom of that screenshot?

polar acorn
#

Ah, didn't see that

#

So that is definitely not a component

zealous oxide
#

np!

polar acorn
#

So GetComponent isn't going to get it

#

because it's not a component

violet topaz
#

how do i attach a camera to a player when loading a new scene

polar acorn
polar acorn
# violet topaz

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

wary sable
#

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

rich adder
wary sable
#

I tried to adjust it so its a bit easier to read

rich adder
wary sable
#

same object

rich adder
#

careful with transform.find, it only looks for children objects name

wary sable
#

yeah, this is for a item slot that is instantiated when the inventory is opened

rich adder
wary sable
wary sable
crisp pollen
#

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?

eternal falconBOT
#
Posting 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.

crisp pollen
#

Sure sorry

rich adder
crisp pollen
#

Oh sorry the line "RoomPositionList[r].Add(position);"
So line 23 in GDL

wary sable
#

correct me if I'm wrong but you are trying to call an index of an empty list

rich adder
#

ohh wait this is a list of list

crisp pollen
#

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

neon wedge
#

does anyone know what im doing wrong?

rich adder
crisp pollen
rich adder
eternal falconBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

rich adder
crisp pollen
crisp pollen
# rich adder but you only want a size from 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

rich adder
crisp pollen
rich adder
neon wedge
rich adder
neon wedge
neon wedge
eternal falconBOT
#
💡 IDE Configuration

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.

rich adder
crisp pollen
rich adder
#

actually no don't use that , that will just make clones of same list

#

mb

neon wedge
summer stump
# neon wedge yes

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?

crisp pollen
summer stump
summer stump
#

Within unity, in the Window menu

neon wedge
#

and?

summer stump
#

Visual Studio Editor version 2.0.21

neon wedge
#

before installing the package

summer stump
#

Window > Package Manager > get the package

rich adder
deep stream
#

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?

neon wedge
#

but i use vs code not vs

deep stream
summer stump
#

If it still isn't working, go to Edit > Preferences > External Tools and click Regenerate Project Files

crisp pollen
rich adder
neon wedge
crisp pollen
summer stump
#

@neon wedge No, MonoBehaviour and those other types should be a different color as far as I know...

rich adder
# crisp pollen oh haha
    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]);
    }```
crisp pollen
#

How could i remove all stats?

rich adder
crisp pollen
#

Remove everything out of the ist

rich adder
#

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();

crisp pollen
#

ty

neon wedge
rich adder
rich adder
crisp pollen
#

Yea just one last question can i normaly check them so like "rooms[1]"?

rich adder
#

or w/e else

summer stump
rich adder
crisp pollen
rich adder
rich adder
#

oh also using class instead of instance

wintry quarry
rich adder
#

oh wait second error is not NRE

summer stump
rich adder
#

its Input class missing"jump" ig class is missing Jump() method being defined

summer stump
#

OOP, I was led astray!

rich adder
#

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

wintry quarry
#

aand why is it called function? 😢

neon wedge
#

idk i just named it or smth

wintry quarry
# neon wedge i dont understand what you mean

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

wintry quarry
#

it's a reference to a particular instance of that script.

#

that's the thing you should be interacting with.

rich adder
#

^^ 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

wintry quarry
#

or player or anything reasonable

lunar root
#

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.

lunar root
#

2d

#

It’s a simple 2d top down game.

rich adder
lunar root
#

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.

crisp pollen
rich adder
lunar root
#

Yep

#

Should I be changing my method?

rich adder
#

you can do the same thing for rooms ofc

lunar root
rich adder
#

if(movement != Vector2.zero) { anim.SetFloat etc..

lunar root
#

Ok

#

I will try this

lunar root
wary sable
#

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?

summer stump
wary sable
#

selectable is a unity script

#

which according to the docs none of the children override Awake so idk

summer stump
#

I think that it is not quite the same as a MonoBehaviour Awake. Try just doing override and using base.Awake()

wary sable
#

I mean I can but

summer stump
frosty hound
#

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
}
wary sable
#

thanks!

sacred zenith
#

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?

summer stump
sacred zenith
#

Makes sense, thank you

cosmic dagger
#

!code

eternal falconBOT
#
Posting 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.

random sand
#

mb