#πŸ’»β”ƒcode-beginner

1 messages Β· Page 253 of 1

radiant frigate
#

true

visual hedge
#

And now read what I wrote

#

Did I write eulerAngles?

radiant frigate
#

quaternion.euler

#

dayum

visual hedge
#

Or Quaternion.Euler(0, 0, zRot...)

#

Replace whole line with what I wrote

radiant frigate
#

so what is the difference between quaternion.euler and transform.eulerAngles

teal viper
#

On is a method. The other is a property.

visual hedge
#

No idea. Probably that one works and other doesnt)

radiant frigate
#

XD

teal viper
#

Do you know what a method is?

radiant frigate
radiant frigate
#

i just forgot πŸ’€

visual hedge
#

Void Euler(float x, float y, float z)

teal viper
#

Go through the C# basics again then.

radiant frigate
#

i think it was public void start and update

visual hedge
#

Quaternion.Euler() is a method that takes 3 args if I am correct. It may take more

radiant frigate
#

or whatever void you create

radiant frigate
visual hedge
#

So does the line I wrote work?)

radiant frigate
#

yep

teal viper
visual hedge
#

Great. And it works like intended in playmode?

radiant frigate
#

like i dont know the definition exactly

teal viper
#

And how is different from a field/propetly?

radiant frigate
radiant frigate
teal viper
#

That's why you should go learn properly

radiant frigate
#

yeah i have no clue how to explain it without sounding dumb xd

visual hedge
#

Then if it works I have many questions to people who Xed my first and initial message

radiant frigate
visual hedge
#

Now that I have it deleted can't name those smarties

radiant frigate
#

im trying to think how to explain what a method was

visual hedge
radiant frigate
#

its like a void you create that you can either call from other place or just run in a loop if its update

#

thats my logic

visual hedge
#

Yeah, that is kinda correct if you ask me.

visual hedge
#

You can call it from other place if it's public or static though

#

From outside the class where it is

radiant frigate
#

i dont know the fancy words (because as i said i learn them in spanish and maybe the traduction fucks it up a bit) but thats like what a method is in my mind

#

for example a coroutine would also be a method

#

it doesnt need to start with void

#

i think

tepid summit
#

type them in spanish

#

i know it

visual hedge
#

public void YourMethod()
private void YourMethod()

tepid summit
#

ill trans

radiant frigate
#

type what

#

the words ?

tepid summit
#

ffancy words

radiant frigate
#

its not like they exist in this exact context but since i have talked a lot with dlich i mean other times where i dont understand words its due to not knowing that they are a word i know

#

for example reference or "referencia " in spanish

#

i didnt learn it with the word reference nor referencia

tepid summit
#

im sure it will be fine

radiant frigate
#

i just understood that it existed and didnt give a fancy name to it

#

in my mind they are more like concepts associated to functionalitys than associated to words like method reference value type etc etc

#

@visual hedge btw it works

#

i just need to add the force to move them i think

visual hedge
#

Knowing english on a certain level helped me a lot with unity. Most guides I watched are in english.

visual hedge
radiant frigate
#

i dont watch them in english for the same reason, they usually use more (as i like the calling them) "fancy" words

visual hedge
radiant frigate
#

i use the rigidbody for their velocity

#

idk if thats a mess since most people use rigidBodys for physics based movement tho

visual hedge
#

Sounds good to me. But I honestly have not so much knowledge in sending projectiles at desired direction

radiant frigate
#

tyler do you want to see how it works ? xD

#

it does rotate it but ig i messed up how much they rotate and what the direction is

visual hedge
#

I have one question: is it just me, or some people in this channel are so pros, that they can't give proper assistance to newbies? I've met that many times here and also with my friend who is actually unity employee ))

radiant frigate
#

it depends

#

the help i usually get is aimed towards newbies

#

and they try to explain all inside the whole thing

teal viper
#

What you call "fancy words" are actually important concepts that help understand how things work.

radiant frigate
#

for example caesar navarone aethenosity or dlich

visual hedge
radiant frigate
#

how can i record my screen again?

radiant frigate
#

alt + windows + g?

#

maybe they actually point towards the direction but since they all go up atm it gives the optical illusion of not working

visual hedge
radiant frigate
#

since its an equal triangle

#

or however its called in english

visual hedge
#

They should spawn at 180 degrees to the previous projectile?

radiant frigate
#

each time its zRotation + 60

#

so in 6 loops its 360 and it has completed a whole "rotation"

visual hedge
#

Ohh yeah, now it makes sense πŸ™‚

radiant frigate
#

i think the rotation works its just the direction at which i launch it that doesnt makes sense

eternal needle
visual hedge
#

Well you shall run them at that white pointer direction

#

So use the transform.position of that white pointer as a direction

radiant frigate
#

not towards the white pointer

visual hedge
radiant frigate
visual hedge
#

I was like 2 days in and friend said: yeeeah, for this you want to use (pseudocode further:) singleton and bunch of static methods and well maybe some non- euclydian quantum physics bullshit.

radiant frigate
#

BHAHAHAHAHAHAHA

#

i feel you

#

but nah people on here has a lot of patience really

#

im gratefull for it

#

atleast the people who i have treated with

visual hedge
#

While some will shoot lambda expressions at newbies

eternal needle
#

πŸ€·β€β™‚οΈ id consider everything except the exaggerated quantum physics to be c# basics

visual hedge
#

While all newbie needs is to mske their int FruitNumber = 1; public

radiant frigate
#

KEWK

teal viper
#

We expect you to know to do that already.

visual hedge
#

In beginners channel?

teal viper
#

Yes.

eternal needle
#

this is game dev you are talking about. The people who refuse to learn the absolute basics first will face WAY more stress than people who took maybe a week of their entire life to do the basics first

neon ivy
#

sorry I had to go over to my teacher about my project and then had to go to my next class, I'm not sure what you mean by this.
for instance I have a movement vector2(x,z) and which is at (0,1) so forward, this is under a gravity direction of (0,-1,0) so down.
then gravity is set to (1,0,0) which would be to the right.

and what I think you're saying is that I need to find the difference in rotation between (0,-1,0) and (1,0,0) and multiply the (0,1) vector by the result?

teal viper
# visual hedge In beginners channel?

Beginner is meant for people going through that learning process. And if they encounter difficulties during that time,they can turn to this channel for help. But there's not much point in helping them if they are just writing random code and don't try to learn the basics orderly.

visual hedge
# teal viper Yes.

I guess that's the reason why all newbie guides almost ALWAYS declare all the variables as public 🀣

teal viper
#

I might expect from someone in general to use private serialized fields. But it's totally fine to use public fields as a beginner.

visual hedge
#

Yeah. For sure

teal viper
#

Beginner courses are not meant to teach you good code practices. They are meant to teach you to write at least working code. And understand it.

teal viper
#

Good practices come after that.

teal viper
visual hedge
#

Oh, right

#

Till last week I had no idea what that is by tbe way

#

Then someone said that unity is oop and it made petfect sense then))

#

By the way... not a beginner topic, but... visual programming seems much more complicated than coding by hands (and brains) is?

#

From vids I saw... having hundreds of "boxes" with strings going everywhere looks bulky and complex to me

teal viper
#

It's not hard. Just takes getting used to it and a bit of learning(like everything). It's confusing for someone that's used to writing normal code, but that's about it.

visual hedge
#

Oh, yeah, makes sense

#

Kay, back to work... see you around

visual hedge
#

I guess I asked the question 2 months too early

timber tide
#

lot of how unity works kinda ruins a lot of that idea of private and public access, so it's best not to try to be a perfectionist because you really cant and this is due to the fact that you can't use constructors with monobehaviors

#

there's some methods like events and subscribing to methods to help lessen the fact that you can't bind via constructor, but even then it's a very loose implementation.

visual hedge
#

Ow, yeah. Constructors is something I have to learn also now. Soon I want to get into automatically generated skill descriptions based on what the SO is set up to. And if I get it right, I need to learn to use a string constructor

timber tide
#

so if you need your item's Use() methods to be used by your controller only, but you can't construct your controller with your inventory's reference to keep it private, then the best course of action is just make your Use() behaviour public, or bind an event after through some assignment method.

queen adder
timber tide
#

serializing on the inspector does help with binding and keeping accessors private, but sometimes you do need to instantiate independent objects which aren't prefab'd together where it causes complications

#

and then you'd do assignment usually after the constructor has been called if needed, and this is usually through some assignment method

#

meaning that you're more forced into an dependency injection (DI) approach, which is actually more ideal for something like game dev since reusing objects is always better than cleaning them up and instantiating another copy.

dark kettle
#

im trying to make an endless runner. the rigidbody on the road causes the player/ball to bounce a lot, so I made a bandaid fix to stop that, but wanna go back and fix the root of the problem so I can make obstacles that causes the player to fall through gaps if they miss a jump. that said, in this video, the left and right work perfectly fine, but as soon as I try to use the jump button, it acts out. how can I fix this? the player sphere has a rigid body, and the prefab empty containing the road has a rigid body.

visual hedge
#

Not on topic but... am I the only anxious one because of ball having cube collider and cube rigidbody?)

timber tide
#

why does the road have a rigidbody. Is this some endless runner tech

dark kettle
#

thats what the tutorial told me to do

#

if it doesnt have rigidbody, it doesnt get destroyed

timber tide
#

so it's a rigidbody but you do position by transform

#

im confused

dark kettle
#

im a newb, so im also confused lol

#

not a newb newb, but essentially a newb

visual hedge
#

I think they imply that you have to use velocity for rigidbody

#

or something liek that

dark kettle
teal viper
timber tide
#

I don't know too much endless runners so I don't know the best way to move ground if the player is the one who is stationary, but usually when you use rigidbodies you are using rigidbodies' movement methods over directly changing the transform position.

rich adder
#

always best to keep player stationary and move obstacles/roads towards player

#

this way you dont get a huge amount of position and get weird jank

dark kettle
# teal viper What exactly is the issue? I don't see anything wrong in the video. Is it that t...

there are 2 inherent issues. 1 is that without an invisible collider, this happens, but i would like to not have to worry about that so I can get creative with obstacles and have the player fall. the second is that jump that you saw. when you press the button, it just goes wonky, like flying off the screen and falling and what not. not to mention it gives more height/force than id like on the lift up

visual hedge
#

btw this looks like the one of those fake games from ads πŸ˜„

dark kettle
#

yea I know lol. I have an interactive game design class starting next week where I thought wed be making an endless runner, so I wanted to start toying around with the idea. now I realize we dont have to, but i still wanna mess with this lol

teal viper
dark kettle
#

the video. without the collider with no rigid body keeping the ball smooth/stable, the ball jumps and bounces every time it hits the floor, and thats not intended

visual hedge
dark kettle
#

the ball has a sphere collider?

visual hedge
#

oh, okay, my bad

timber tide
#

I would try using rb.moveposition

#

two rigidbodies acting on each other seems like something you want to stick to rb only methods

dark kettle
#

heres the jump code

#

rb?

#

whats that

teal viper
dark kettle
#

and whats rb.moveposition

visual hedge
#

rigidbody

#

rigidbody.MoveToPosition() I guess

dark kettle
#

at the moment, Id like it to only jump when the player wants to jump

#

where do i put rigidbody.MoveToPosition(), what do I put in the brackets, and what does it do?

visual hedge
#

idk, ask them πŸ™‚

native seal
#

seems odd

#

for a jump script

dark kettle
#

im clicking buttons

#

the jump button on screen

native seal
#

kk

#

thought it was a script on the player

visual hedge
#

I see everything is working for you and instead of helping with jump issue we got to discussing why the road moves like it moves damn

#

share code related to jumping please

dark kettle
#

its an on screen button

visual hedge
#

okay

#

that's the problem

visual hedge
#

I mean... I'm not an expert but I would do that thru simple if GetKeyDown.Keycode

#

the road is moving now?

dark kettle
#

im messing with mobile friendly stuff

#

the road was always moving

visual hedge
#

so it's fixed? πŸ˜„

dark kettle
#

not really. i have an invisible collider with no rigidbody working as a bandaid, but i dont want it there so the player has a risk of falling. also, the jump is still messed up

#

falling due to intended reasons, not this hot mess

#

one thought is I could just perma-bandaid this and when I get around to adding obstacles, just mold colliders around it

timber tide
#

again, you're using transform positional logic when you should be using rigidbody methods in fixedupdate

dark kettle
#

idk what that means

timber tide
#

go through the docs

dark kettle
#

I also dont get how that would fix my problem. would the platforms still be the thing moving? can you please explain why I should be using rigidbody methods in fixedupdate over what I am currently doing

timber tide
#

because rigidbody uses physics which happens in a fixed time step

#

not only that, but movement is evaluated differently as there's a lot more to it than simply changing the position (interpolation, prediction, ect)

teal viper
# dark kettle

Currently, aside from moving it in update sometimes, you let the rb move freely. Imagine a real life ball filled with air dropped from one meter height. Of course it would bounce.

#

If you want a completely controlled movement, you'll need to set it's velocity manually every frame.

dark kettle
#

im guessing that isnt advised cus its computationally expensive

teal viper
#

What is?

dark kettle
#

manually updating velocity every frame

#

im guessing, since its every frame

teal viper
#

No, it's totally fine. You're just changing a value that unity physics works with.

dark kettle
#

how would I do this then?

teal viper
#

In fact, it's one of the most common ways.

#

Set rb.velocity in fixed update.

dark kettle
#

id like the player to be grounded unless they choose to jump, or they fall through an obstacle. how would I go about doing that?

#

with your velocity suggestion, I mean

teal viper
#

Actually, instead of setting the velocity, maybe applying force and using a non bouncy material would be better.
There are many ways to go about it.

timber tide
#

yeah, there's like 5 ways to move rb, but you've chosen the one way to not move it ;p

dark kettle
#

i just did what the tutorial told me to do

#

I lowered the force variable from 10 to 5 to see what happens

#

thats what this video shows

#

so what, I would replace Player.transform.Translate(0, ForceTime.deltaTime, 0); with RigidBody.Move(0, ForceTime.deltaTime, 0); ? im not really following the syntax. im more familiar with unreal blueprints syntax and my coding is rusty lol

timber tide
visual hedge
#

@dark kettle just a random idea: in rigidbody try to lock some axis

dark kettle
#

I did that with both the player and the road

visual hedge
#

In inspectpr

#

Oh okay

timber tide
#

actually, sometimes the docs won't throw you the exact right code as seen in AddForce there, but you don't want to be taking input in fixedupdate either

#

the velocity code does it right though

teal viper
teal viper
teal viper
# dark kettle

Btw, what's with that crazy mass? I wouldn't be surprised if it's contributing to the issue.

timber tide
#

regardless of the mass, if you're changing transform position directly, physics will be trying to fight it because it doesn't respect velocity

teal viper
#

Still, that shouldn't cause such a specific behavior

timber tide
#

well, it wouldnt leave the ground regardless

teal viper
#

I think I know what the issue is

dark kettle
#

Hey friends! Let's learn how to generate infinite levels and platforms in Unity with Procedural Generation! This is a follow-up to a video I made about Subway Surfer, and I thought this would be a good overview on how procedural generation works.

πŸ‘Ύ Join the Discord! https://discord.gg/MYAujpE4xG

🫢 Access Code Files and Projects! [patreon.com/...

β–Ά Play video

This Video shows that Movement using Button in Unity3D. This video contains Left, Right and Jump Movement Using Button

Image Link : https://www.pngwing.com/en/free-png-vvvlx
#unity#unity3D#movement

β–Ά Play video
timber tide
#

physics is like you belong on the ground, but translating it upwards is like saying no u

teal viper
#

Can you take a screenshot of your ball inspector with constraints on the rb expanded?

dark kettle
#

i tried to follow a different tutorial on jumping and accidentally gave my jump button a directional pull that i cant get rid of. lollll

radiant frigate
dark kettle
radiant frigate
#

πŸ’€

#

dlich!

#

i managed to do something

teal viper
radiant frigate
#

yay

dark kettle
#

oh I see, even though I deleted code, my jump button had a rigidbody on it

radiant frigate
#

i did some beautifull work for figuring out how to impulse it

modest dust
radiant frigate
neon ivy
# neon ivy sorry I had to go over to my teacher about my project and then had to go to my n...

omg I made this work, not sure if this is the best way to do it but now I just need to rotate based on the camera's forward I think UnityChanClever

Vector3 crossProd = Vector3.Cross(Physics.gravity.normalized, GetGravityDirection().normalized);
float angle = Vector3.Angle(Physics.gravity.normalized,  GetGravityDirection().normalized);
Quaternion rot = Quaternion.AngleAxis(angle, crossProd);

Vector3 transMove = rot * absMove;

InputVector =  transMove.normalized * magnitude;
``` does this make sense?
radiant frigate
#

iΒ΄ve been coding nonstop for the las 10 hours (except a mini break for having breakfast) and all for this, even tho its not much im still so proud

#

the joy im feeling right now is something from other reality

#

(imma stop yapping now, srry but im so excited)

dark kettle
#

im back to square one, my jump button no longer has gravity, and my ball acts weird with its jump, and im using a collision box to bandaid the rigidbody issue

dark kettle
# teal viper Hmm... Okay, maybe that's not it.

here are the other constraints, for reference. I noticed when I was working on the first tutorial that the roads were bumping into each other and these constraints, plus adjusting the number in the code fixed it. heres a screenshot of the code as it is right now, for reference

#

lowering the number from -57 as the tutorial says to do (then later lowers it herself) to -10 fixed the collision issue, along with the constraints

timber tide
#

I suggest getting your sphere to jump in place using addforce first

dark kettle
#

also, pushing left/right against the wall leads to it bouncing off the wall

#

how do I do that

timber tide
#

try some physics material to prevent it from bouncing if that's intended behaviour

dark kettle
#

I dont want it to bounce

#

and how do I do physics material?

timber tide
#

could really be a few things honestly because you've two rigidbodies acting on each other

#

if I'd attempted this, I'd probably wouldn't use rigidbodies and just do most of the logic directly through transform updates

#

this way you have more control of the behaviour and it seems like that's a requirement for you

dark kettle
#

how could I go about doing this? that tutorial I shared earlier used rigidbodies because the platforms wouldnt move otherwise, and I guess it worked perfectly fine for her. I could see if she has a video going over movement on her channel

timber tide
#

probably the hardest problem with that would be smoothly interpolating ramps but not impossible

dark kettle
#

what does that do

timber tide
#

look up kinematic character controllers, that's probably what you would want to use

#

ah, I guess you would also add some velocity to ramps in that case too

dark kettle
#

looks like she doesnt have a movement tutorial for the endless runner. I may look at a different procedural generation video and kinda do a partial reset on this project, since im not really far into it anyways

timber tide
#

her video doesnt explain anything for the player

#

she slaps on a rigidbody and moves it incorrectly

dark kettle
#

yea i was looking to see if she does a player tutorial and she didnt

#

in her videos

#

so im gonna find someone else to learn about procedural generation from

timber tide
#

theres probably a bunch of tutorials on this stuff so yeah, look around

dark kettle
#

this guy hasnt posted in ages, but has a 3 video series on the subject. im running version 2020.3 anyways, so should work for me

visual hedge
radiant frigate
#

yes

#

and i can even modify it

dark kettle
#

his procedural generation looks cooler anyways lol. I am thankful I followed the first tutorial though, because it got my toes wet in the world of procedural generation, which Ive never messed with in any game engine before

visual hedge
timber tide
#

unity does have an endless runner template you should consider digging into

#

just to see how they're doing it

visual hedge
radiant frigate
#

but i dont control him since discord only allows 25 mb and didnt want to overexted the video

visual hedge
#

And the thing that shoots is enemy?

radiant frigate
#

and small cubes that appear on top also are enemies

visual hedge
#

Okay, so Galaga you have πŸ™‚

radiant frigate
#

what is galaga?

visual hedge
#

Oldschool 8bit space game with spaceship shooting

#

That's what I am working on πŸ™‚

#

Assumingly the only game genre that the market is not oversaturated with. Or maybe I'm just not so aware

#

Or maybe noone plays turn-based games 🀣

crimson ibex
#

Hello, I have not been able to find a good solution to very simple thing 😦 please help

  1. 3d game with only x and z axis. y axiz = 0 always
  2. Mobile Touch game
  3. Player gameobject moves to location where touched
  4. if Box gameobject is in the way of Player movement, Player goes around box
  5. if Player clicks on Box gameobject, Player stands next to Box with a maxdistance 0.6f ( any edge )
    I can not make 4. and 5. work
    I have tried
    A. AI agent - can not make 5 work
    B. Vector3.MoveTowards - can not make 4 work
    C. use targetPosition.normalized and write algorithm for every delta movement ( tough algo)

please suggest, it seems a simple task, but I am not able to catch it

formal bolt
#

How to make my camera can't look all way down.
https://gdl.space/ixajokikov.cpp - The Camera Script Attach to Character
I want my player can't look all the way down to make its doesn't break the game. Please help.

neon ivy
#

is there a way to rotate the orbits from the freelook cinemachine camera?

#

I tried all the binding modes but they don't seem to work. maybe I'm not using them properly

dim brook
#

how do i make it not readonly

#

i tried changing the folder attribute but it keeps reverting back

left marsh
#

Hi, got a Cache related question. Got a FSM on my player, each state will need to get reference of components to do things.
Is it better to cache my components at their first access in a collection and then my states will access this collection to get refs, or each state must cache it's needed components at it's start?

radiant frigate
visual hedge
quartz mural
#

how do you fix a _unity_self null error?

radiant sail
#

AFTER 6 HOURS I HAVE DONE IT!!!
heres the code that i needed πŸ’€

targetrotation = new Vector3(-Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0f);
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(targetrotation), 5 * Time.deltaTime);
parent.transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(targetrotation), 5 * Time.deltaTime);```
this code it prob breaking like 70 laws of c# but idc. it has given me the behavior i want.
quartz mural
#

when i click it doesnt take me to the error

slender nymph
#

show the stack trace

quartz mural
#

sorry?

#

explain...

#

please

slender nymph
quartz mural
#

πŸ‘

#

doesnt show?

slender nymph
#

yes it does. that's the stack trace at the bottom

#

and it is from editor code, so unless you have been writing editor code or you have an asset that has editor code then you can clear it and move on

quartz mural
#

ok...

quartz mural
#

πŸ‘

gilded verge
#

how do i get a relative direction of an object? wasent it gameObject.transform.right? somereason that doesnt work...

slender nymph
#

it's transform.forward is the direction it is facing

gilded verge
#

if you get what i mean

slender nymph
tired gulch
gaunt ice
frosty hound
gaunt ice
#

also if you dont have a gameobject with tag audio then NRE or it returns a gameobject without this component and NRE again

tired gulch
quartz mural
#

any ideas?

slender nymph
#

what is line 86

frosty hound
quartz mural
tired gulch
gaunt ice
#

the list not null how about the elements?

slender nymph
# quartz mural

then whatever in that index of the list may be null, or its Base property is null. or its text property is null.

quartz mural
#

ok

frosty hound
tired gulch
#

This is what I do:

AudioManager.instance.gameOverMusic.Play();
AudioManager.instance.levelMusic.Stop();

the gameOverMusic and levelMusic is an AudioSource.

frosty hound
#

Sure, that works

tired gulch
#

Okay, now I know this way is better than FindGameObjectWithTag. But is this singleton way of playing music and sfx is good in terms of performance?

quartz mural
#

@slender nymph

slender nymph
#

bro what

timber tide
quartz mural
slender nymph
#

if you think that is anywhere close to valid code, you should go through the beginner courses pinned in this channel

quartz mural
#

how do i make it valid

frosty hound
slender nymph
# quartz mural how do i make it valid

start by learning wtf you are doing instead of just taking random guesses at what you think the code should look like. you're going to take longer to fix your issues than it will take to learn if you have no idea what you are doing

tired gulch
loud python
#

Hey everyone im having some issues here with the List Variable. https://paste.ofcode.org/ixgXps6H58ruk5pW6smJN4 when I call RemoveChest, it always leaves 1 left in the list. How do I combat this? (I think it has something to do with list starting at 0 maybe?)

#

so whenener I spawn another ChestSlotPrefab it always doubles the item in the list because it wont be deleted for some reason.

visual hedge
dim brook
#

im watching that tutorial as well

#

are you missing the script thingy in the inspector

visual hedge
#

moveText != null && moves != null I guess was the first mistake where mistake was & instead of &&.

#

second one, list is declared, you don't want to see if it's not not null, but if it has any elements in it, so you have to check element count

visual hedge
# quartz mural

also I think that if you are watching a tutorial... you do it terribly wrong since I am pretty sure Brackeys wasn't writing it that way

#

@hidden sleet you writing a poem there? πŸ˜„ Sorry... could not resist to @ you )

#

so you answer me and then write the whole poem anew after πŸ˜„

hidden sleet
visual hedge
# quartz mural

this one will work a tiny bit better if you put 3rd string before the last curly bracket

hidden sleet
#

For this inventory system of mine I've got it set up so that said inventory will hold a list of InventoryItems. ```cs
public class InventorySO : ScriptableObject
{
[SerializeField]
private List<InventoryItem> inventoryContainer;

This inventoryItem class then holds a scriptable object representing an item, as well as a quantity.
```cs
public class InventoryItem
{
    public int quantity;
    public ItemSO item;

When the Ui is clicked, it will pass the index of the slot that was clicked, which matches the inventory's indexes, and I'd like to be able to spawn the item into the world from here. However each type of item has different rules for when and how it spawns.

private void HandleItemSpawnRequest(int itemIndex)
{
    InventoryItem inventoryItem = inventoryData.GetItemAt(itemIndex);
        inventoryItem.Spawn() // Wont work
    
}```
I figured I could try an interface, ```cs
public interface ISpawnable
{
    public void Spawn();
}```
And put it into the item that can be spawned ```cs
public class RawItemSO : ItemSO, ISpawnable
{
    public string[] labels;
    public void Spawn()
    {
        //Spawn into the world            
    }

    
}``` But I believe my understanding was off, as I can't call the spawn method since the inventoryItem is just an itemSo, which doesn't have the method on it.

So given that I will have different classes extend this raw item, each with different spawn logic, what would I have to change up here so that I can just call that spawn method in my HandleSpawnRequest method?
visual hedge
#

haa! I knew it will be a poem!

hidden sleet
#

indeed X/

visual hedge
#

even a novel

hidden sleet
#

tried to cut out unecessary stuff but in essence it's just that I don't know how I'd go from a list that holds the superclass, to then calling the method located within the subclasses

visual hedge
#

may I suggest one thing? That you use Kryzarel's inventory system?

hidden sleet
#

I initially thought that if I have ItemSO as the type, then anything that extends that could fit and I'd be able to just call that method from the interface, but I'm not sure about that now

swift crag
#

If every kind of ItemSO can be spawned, it should implement the interface.

#

But if there's no specific definition, you can implement it abstractly.

#

Derived classes will then have to provide an implementation of the method.

visual hedge
#

I cant' really help you sadly, but when you spawn item... you better spawn an unique item and not copy of your initial item... because that will cause some troubles I am afraid

hidden sleet
#

yeah in this case everything will be spawnable in one way or another

#

So if I make ItemSO abstract, and put a RawItemSO in that inventory slot, would doing inventoryItem.item.Spawn work?

swift crag
#

if ItemSO also implemented ISpawnable, yes

#

that's the part you are missing

hidden sleet
#

right

swift crag
#

ItemSO is not ISpawnable, so it doesn't have to have a Spawn method.

hidden sleet
#

so if I go and make the itemSO abstract, and put the interface in there, would subclasses of that also need to implement the interface or just override what the base ItemSO does?

swift crag
#

They will need to override the abstract Spawn method.

#

They only need to inherit from ItemSO.

hidden sleet
#

Right then, so I've got ```cs
[CreateAssetMenu]
public abstract class ItemSO : ScriptableObject, ISpawnable
{
public bool isStackable;
public int Id;
public string Name;

public abstract void Spawn();

} with that spawn method as abstract. Raw item so overrides that.cs
[CreateAssetMenu]
public class RawItemSO : ItemSO
{
public string[] labels;

public override void Spawn()
{
    Debug.Log("Spawned");
}

}Then in the controller I just need to call spawncs
private void HandleItemSpawnRequest(int itemIndex)
{
InventoryItem inventoryItem = inventoryData.GetItemAt(itemIndex);
inventoryItem.item.Spawn();
}```

swift crag
#

Correct.

hidden sleet
#

fantastic!

hidden sleet
#

that's going to make my life so much easier

swift crag
#

you should also see

#

this describes what you're trying to do

hidden sleet
#

Good good

#

will do some extra research

#

There just seems to be so many ways to extend, override and manipulate classes and whatnot that figuring out the correct way to do what I want feels rather tough

#

but this seems to solve that

timber tide
#

constructing it in the SO is fine

swift crag
#

This is roughly how I've done items in the past

timber tide
#

if Item is a plain c# class you can use that with a constructor

swift crag
swift crag
timber tide
#

The item as new Item(ItemSO)

swift crag
#

i'm not sure what you're referring to here

#

there is no Item class anywhere

hidden sleet
#

well I'll see if I can apply this in other places, had a mess before where I had multiple inventories of different types, with spawn logic all over the place. basicallt rewriting it all now

timber tide
#

Oh, what's this spawn method do?

#

It has no return so that's interesting

swift crag
#

If you ever find yourself doing this, you probably need polymorphism:

if (thing is Foo fooThing)
  fooThing.Work();
if (thing is Bar barThing)
  barThing.Work();
#

ironically, one place I wound up having to do that was...an inventory system

#

i wanted to keep separate lists of each kind of item

hidden sleet
swift crag
#

It feels very easy to wind up with this kind of code in an inventory system

swift crag
#

I guess each class could have a Type property that returns an enum

#

but then you'd still need to downcast to access functionality that only some items have

#
Parent parent = new Child();
Child downcasted = (Child) parent;
#

in case you haven't seen that term before

#
Child child = new Child();
Parent upcasted = (Parent) child;
#

upcasting goes to a parent type; downcasting goes to a child type

#

upcasting always works; downcasting can fail if you have the wrong type at runtime

hidden sleet
#

Like, i had this for an inventory where the contents are just simple items. cs public class Inventory : ScriptableObject, ISerializationCallbackReceiver { public ItemDatabase database; public List<InventoryItemSlot> invContainer = new List<InventoryItemSlot>(); public string inventoryType;
Then a separate one for structures... ```cs
public class StructuresInventory : ScriptableObject
{
public List<InventoryStructureSlot> invContainer = new List<InventoryStructureSlot>();

One for raw stuff... ```cs
public class RawItemInventory : ScriptableObject, ISerializationCallbackReceiver
{
    
    public List<NewInventoryItemSlot> invContainer = new List<NewInventoryItemSlot>();
    public string inventoryType = "RawMaterial";
    public GameObject spawnPrefab;

And one for processed items.... An absolute mess cs public class NewProcessedItemInventory : ScriptableObject, ISerializationCallbackReceiver { public ItemDatabase database; public List<NewDatabaseInvItemSlot> invContainer = new List<NewDatabaseInvItemSlot>(); public string inventoryType = "ProcessedMaterial";

swift crag
hidden sleet
#

Then I had all these trying to display the items for each

#

so I'm trying one where I can just have a generic item and hopefully it'll figure the rest out

swift crag
#

I have yet to implement an inventory system that I really like 🫠

hidden sleet
#

this is only for a small uni project but it's already giving me headaches

timber tide
#

everytime I try to be witty I end up with generics and then hate myself for it

#

I just dislike casting

unborn sinew
#

I'm making a game in which the number of characters could go up to the hundreds during runtime. Would it be feasible to have a script attached to each of them which controls their pathfinding? They also have different "jobs". What's a better way of doing this?

hidden sleet
#

Although thinking about it now, Spawn is currently in the item class itself. If I intend for this to just instantiate an object and attach this item as a component, should that spawn logic be in the item at all?

swift crag
#

The item definition should be able to instantiate an actual item for you when needed

#

(that's how I've done it)

#

so my inventory isn't a huge pile of deactivated game objects floating below the player

hidden sleet
#

not too sure how I'd go about that

lapis yew
#

Use scriptables

timber tide
lapis yew
#

Use scriptable objects for your items

hidden sleet
#

I am

#

just shown the code above

lapis yew
#

I joined 2 seconds ago lol

timber tide
#

I was saying, it can work both ways. You can construct it in the item, or instantiate the item in the SO and do the logic there.

lapis yew
#

Wait

swift crag
lapis yew
#

Your inventory is a scriptable?

swift crag
#

you need to be specific, especially when you have 10 different item classes floating around (:

lapis yew
#

What I would do is have a inventory component that is basically a dictionary of itemScriptableObjects

timber tide
#

your pathfinding logic

hidden sleet
# swift crag go about what in particular?

Not too sure what you really mean by splitting the definition from the item.
Currently I've got all the possible items set up as scriptable objects, and the slots just reference those ones. Is that somewhat similar?

unborn sinew
swift crag
#

Or do they only exist in your inventory?

swift crag
hidden sleet
#

Yes, but they don't always exist. Essentially, when you start the items are scattered on the floor. You pick them up, and go into this ethereal inventory. But in some scenes you can click them and I'd want them to spawn as a prefab in the world to then use for some other purpose

timber tide
#

Personally, I like to have a ItemConstructor singleton that spawns the items into the scene, but mostly more network related instead of independent item instantiating.

swift crag
#

"I have 500 sheets of metal" means you have an InventoryItem with a count of 500 and the "metal sheet" ItemSO

#

The actual metal sheet prefab is the real item.

#

If you have the "metal sheet" ItemSO, you should be able to instantiate the "metal sheet" prefab.

hidden sleet
swift crag
#

thus, its ItemSO (which will actually be a ProcessedItemSO or something) needs a reference to the metal sheet prefab.

pseudo swan
#

How do you guys find the object that throws a null reference? The console shows me which line in which script it is, but it doesn't tell me which object in my scene is missing the reference. It's really hard to figure out when you have many objects, hundreds, that could be the culprit.

hidden sleet
#

Would that prefab end up in that scriptable object to be assigned in the editor?

swift crag
#

Log entries can include a unity object as context

timber tide
swift crag
#

You'll need to do this while the game is running.

#

If the error is coming out of a prefab (rather than an instance of the prefab!), clicking the error may highlight something in the Project window

pseudo swan
#

Thanks, @swift crag and @timber tide , it's probably in the prefab.

swift crag
#

Drag the console window out separately from the project window and try clicking the error.

#

If that doesn't work, then consider just doing something like Debug.Log(this.name, this); right before the line that errors

#

The second argument to Debug.Log is the context.

pseudo swan
#

Oh, ok.

hidden sleet
hidden sleet
#

gotcha

swift crag
#

It could even assign itself to the newly spawned item, so that the item can get things like its name from the RawItemSO

hidden sleet
#

I think that's roughly what I aim to do

#

if I get you right

swift crag
#
public class ActualItem : MonoBehaviour {
  public ItemSO definition;
}

public class RawItemSO : ItemSO {
  [SerializeField] ActualItem prefab;
  public override void Spawn() {
    var spawned = Instantiate(prefab);
    spawned.definition = this;
  }
}
timber tide
#

Oh, you got different prefabs for different items eh

swift crag
#

something like this

hidden sleet
#

Cause once it's spawned, I want to put the item on the object, since some physics interactions later will do something based on what type the object is

swift crag
#

This will be useful if you reuse the same prefab for many things

#

ActualItem can ask ItemSO for its name

#

If you have one class for each kind of actual item, then I'd consider doing something like this

hidden sleet
#

although quantity shouldn't be there

swift crag
#
public abstract class ActualItem : MonoBehaviour {
  public abstract ItemSO Definition { get; }
  public string Name => ItemSO.ItemName;
}

public class RawItem : ActualItem {
  public RawItemSO rawItemSO;
  public override ItemSO Definition => rawItemSO;
}
#

The concrete RawItem class actually holds on to a RawItemSO

#

the Definition property lets it return its RawItemSO as an ItemSO.

#

Thus, ActualItem can access it and read stuff from it.

#

Alternatively, you could do something more like this

timber tide
#

Yeah, this is one problem I dislike but I guess that's just oop, but the return type is still the same in the child.

hidden sleet
#

Was wondering actually, I know about the concept of getters and setters as a way to control how private variables are retrieved and set, but with the {get;} notation, does that just essentially allow you to do definition.Get?

swift crag
#
public abstract class ActualItem : MonoBehaviour {
  private ItemSO itemSO;
  public string Name => ItemSO.ItemName;

  public virtual void Setup(ItemSO itemSO) => this.itemSO = itemSO;
}

public class RawItem : ActualItem {
  private RawItemSO rawItemSO;
  public bool Smeltable => rawItemSO.Smeltable;

  public override void Setup(RawItemSO rawItemSO) {
    base.Setup(rawItemSO);
    this.rawItemSO = rawItemSO;
  }
}
timber tide
#

Which is why I'm always drawn into doing something like Item<RawItemSO>

swift crag
#

This is a bootleg constructor, really

#

You call RawItem.Setup(), and it calls ActualItem.Setup() to pass the definition along

swift crag
#
public abstract int GiveMeANumber { get; }
#

You must implement a property that has a public getter

hidden sleet
#

how is that different to just leaving it public and doing an =

swift crag
#

Properties look like fields, but they actually call methods.

swift crag
#

notably, since there's no set accessor here, you can't try to set the property

#
public string Name => ItemSO.ItemName;

So, if you have an ActualItem, you can do this:

#
Debug.Log(item.Name);
#

it will ask its ItemSO for its own Name field or property

hidden sleet
#

so you don't have to say GiveMeANumber.get, but rather whenever you try to get it like you would a normal public variable it runs through that method instead

swift crag
#

Correct.

hidden sleet
#

right

#

Did some stuff in java and I kept making specific methods for getting and setting, so is that essentially just a shortcut

pseudo swan
#

So weird, yesterday I got 4 errors and a trigger wasn't working, today I open the project and run it - no errors and trigger works fine. How weird!

swift crag
#
private float myField;
public float ReadOnlyForYou
{
  get => myField;
  private set => myField = value;
}
#

this property can only be set by its own class

#

I use a lot of get-only properties in my code.

visual hedge
#

can I express this line here Tesst.trueDamage = Mathf.Round(Tesst.trueDamage * unit.Stats.critDamage);
as:
Mathf.Round(Tesst.trueDamage *= unit.Stats.critDamage);?

swift crag
#

Tesst.trueDamage *= unit.Stats.critDamage returns the value that got assigned to Tesst.trueDamage

#

Mathf.Round rounds it, and then the result is discarded

visual hedge
#

so better to leave it this way, right? Tesst.trueDamage = Mathf.Round(Tesst.trueDamage * unit.Stats.critDamage);

hidden sleet
#

gotta get some lunch now, hopefully all goes well but I may be back later if more issues arise

timber tide
#

vs should really warn you on discarding the returns

swift crag
#

note that ref wouldn't be usable here, since there's no variable -- just the value returned by the *= opreator

timber tide
#

because you can totally ignore TryGet methods

#

I meant, wrap the round method and use your own ref parameter

swift crag
timber tide
#

ah, hmm. I guess you'd have to make it a pointer then

earnest basalt
#

can I access/edit these two values via code ?

#

i think i can

#

i think its these two

#

that are X and Y poses respectively

#

but i dont see the third parameter

swift crag
#

those are the actual names of the X and Y parameters

#

not the individual values

earnest basalt
#

oh ye =/

swift crag
#

I've never manipulated those before

#

but one thing to note for sure

#

A copy of the list of the blend tree child motions.

#

Try getting the children property and storing it into a variable

#

Modify that variable, then store it back into children

#

Otherwise, you'll just be modifying a copy that gets immediately thrown out

earnest basalt
#

i see

#

thanks

#

will look into it

quartz mural
wintry quarry
quartz mural
#

yes

#

it got deleted cuz i ddint provide enough detail mb

#

how can i fix it

wintry quarry
#

Is there something that needs fixing?

quartz mural
#

index is out range?

wintry quarry
#

Doesn't seem like a problem

#

you have 4 move texts

#

and less than 4 moves

#

that's expected in pokemon

quartz mural
#

i mean how to fix it

#

ik what the problem is now

wintry quarry
#

Is something actually broken?

quartz mural
#

so it shoudl just show - instead

#

but for some reason

#

all of them are -

wintry quarry
#

you don't have any moves in the moves list

#

or you have null moves in the list

quartz mural
#

oh i set it in the inspector

#

allow me to show u

wintry quarry
#

what does the inspector have to do with the list of Moves that is passed into this function?

quartz mural
wintry quarry
# quartz mural

this doesn't look like anything relevant to the cdoe above

#

Where does the list of moves come from

wintry quarry
#

where does that come from

oak mist
#

This may be a dumb question:

quartz mural
#

it coems from there

wintry quarry
quartz mural
#

then it comes form the other one

wintry quarry
#

It comes from the Pokemon

quartz mural
#

same class name

quartz mural
wintry quarry
#

playerUnit.Pokemon.Moves

quartz mural
#

ok

low tide
wintry quarry
quartz mural
#

shall i start debuggine in the poekmon class

wintry quarry
#

You should definitely start debugging this moves list Β―_(ツ)_/Β―

#

and figure out why it's not populated properly

quartz mural
wintry quarry
eternal falconBOT
quartz mural
wintry quarry
#

use paste sites

#

but none of the code matters all that much atm

#

you need to look at the data

oak mist
#

I have this screen on unity for a cockpit im using for a game in creating, there is also an image of it in game. I want to actually animate this to show current health and enemy positions, but not sure of a way to do it. Is there any way i can edit this to make the movement, or find a way to replicate this?

#

Again im aware this is a dumb question

#

but just incase i can

wintry quarry
#

you would need like a "base" image without the populated text and values in it

#

then you could animate the stuff inside it

#

but - if you just have that specific image it will be annoying. You need to photosho out the "cutrrent" values on it

quartz mural
#

can i dm u

wintry quarry
quartz mural
#

message is too long

#

im in class rn

#

and bit short on time

frosty hound
#

So start by sharing your code in a bin site

polar acorn
eternal falconBOT
quartz mural
#

!code

public class Pokemon
{
    public PokemonBase Base {  get; set; }
    public int Level {  get; set; }

    public int HP {  get; set; }

    public List<Move> Moves {  get; set; }

    public Pokemon(PokemonBase pBase, int pLevel)
    {
        Base = pBase;
        Level = pLevel;
        HP = MaxHp;

        // Generate Moves
        Moves = new List<Move>();
        foreach (var move in Base.LearnableMoves)
        {
            if (move.Level <= Level)
                Moves.Add(new Move(move.Base));

            if (Moves.Count >= 4)
                break;
        }
    }
eternal falconBOT
frosty hound
strong moth
#

does anyone know why this instantiates 2 objects instead of 1cs GameObject output = Instantiate(new GameObject());

polar acorn
slender nymph
#

because new GameObject creates a new object in the scene. then you pass that to Instantiate which creates a clone of it

strong moth
quartz mural
#
public class Pokemon
{
    public PokemonBase Base {  get; set; }
    public int Level {  get; set; }

    public int HP {  get; set; }

    public List<Move> Moves {  get; set; }

    public Pokemon(PokemonBase pBase, int pLevel)
    {
        Base = pBase;
        Level = pLevel;
        HP = MaxHp;

        // Generate Moves
        Moves = new List<Move>();
        foreach (var move in Base.LearnableMoves)
        {
            if (move.Level <= Level)
                Moves.Add(new Move(move.Base));

            if (Moves.Count >= 4)
                break;
        }
    }
strong moth
#

jokes aside whats the problem

quartz mural
#

ik what the problem is

#

ive located it

#

but dont know how to fix

strong moth
#
  public List<Move> Moves {  get; set; } = new List<Move>();``` Moves was null so there was no list to write data to
polar acorn
strong moth
polar acorn
#

It does seem l ike a sort of ghetto inheritance

quartz mural
#

gimme a second

#

@polar acorn

polar acorn
sterile wraith
#

What is the best way of setting a rotation. There are many ways, so I wanted to hear ur opinion on the best.

tired gulch
#

Hello, so I have an object that damages the Player. In the future I want to add more than 1 trap objects, should I only make one script that damage the player or make one script for each object? Because I kinda want to diferentiate the nature of each traps.

What is the best solution for this? Thank you!

quartz mural
#

is that what u emant

polar acorn
#

What is in the list

strong moth
#

post the pokemon base code

#

the problem probably lies there

quartz mural
#

ok

polar acorn
#

Whether that's dealing 5 piercing for a spike or 30 fire damage for a puddle of lava, doesn't matter, it's the same basic concept

quartz mural
#

ill remove the stats

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "Pokemon", menuName = "Pokemon/Create new Pokemon")]
public class PokemonBase : ScriptableObject
{
    [SerializeField] string name;

    [TextArea]
    [SerializeField] string description;

    [SerializeField] Sprite frontSprite;
    [SerializeField] Sprite backSprite;

    [SerializeField] PokemonType type1;
    [SerializeField] PokemonType type2;

    // Base Stats
    [SerializeField] int maxHp;
    [SerializeField] int attack;
    [SerializeField] int defense;
    [SerializeField] int spAttack;
    [SerializeField] int spDefense;
    [SerializeField] int speed;

    [SerializeField] List<LearnableMove> learnableMoves;
    public string Name
    {
        get { return name; }
    }

    public string Description
    {
        get { return description; } 
    }

    public Sprite FrontSprite
    {
        get { return frontSprite; }
    }

    public Sprite BackSprite
    {
        get { return backSprite; }
    }

    public PokemonType Type1
    {
        get { return type1; }
    }

    public PokemonType Type2
    {
        get { return type2; }
    }

    public List<LearnableMove> LearnableMoves
    {
        get { return learnableMoves; }
    }
}

[System.Serializable]
public class LearnableMove
{
    [SerializeField] MoveBase moveBase;
    [SerializeField] int level;

    public int Level { get; internal set; }
    public MoveBase Base { get; internal set; }
}
strong moth
tired gulch
tired gulch
polar acorn
sterile wraith
#

Do all ultility methods have to be in the script that inherits monobehaviour? Or can i have a separate script just for utilities?

polar acorn
#

And stop worrying about performance until you actually profile it

strong moth
tired gulch
polar acorn
tired gulch
#

Now I know what I should do

polar acorn
quartz mural
#

can i dm soemone

polar acorn
#

It literally does not matter where the code is it gets run one line at a time like always. The same content embedded in a function multiple times versus a function of its own literally makes no difference

quartz mural
#

so i can contact them later when there free

strong moth
polar acorn
polar acorn
strong moth
tired gulch
strong moth
quartz mural
#
public Pokemon(PokemonBase pBase, int pLevel)
{
    Base = pBase;
    Level = pLevel;
    HP = MaxHp;

    // Generate Moves
    Moves = new List<Move>();
    foreach (var move in Base.LearnableMoves)
    {
        if (move.Level <= Level)
            Moves.Add(new Move(move.Base));

        if (Moves.Count >= 4)
            break;
    }
}
strong moth
swift crag
tired gulch
#

there may be many traps, but not simultaneously pop up

tired gulch
polar acorn
quartz mural
#

sorry mb

#

i set the moves in the inspector

polar acorn
#

Okay, show it

quartz mural
sterile wraith
ivory bobcat
polar acorn
# quartz mural

Okay, so, now that we have the information let's follow the chain backwards from the error. Your first two moves in the list are throwing an error, the other two are throwing a warning because there's only two in the list. That would make sense since this list has two elements in it, so there's likely a problem with this list. Since the if statement checks if the move is null or the move's base is null, we can now say that one of two things is happening. Either:

A) The moves inside the list are becoming null, either by being set to that or being destroyed, or
B) The move's base property is or becomes null

Try logging moves[i] and moves[i].base instead of just saying "MoveText or Moves at index i is null"

#

Find out which case it is

polar acorn
sterile wraith
#

unrelated math that doesnt actually effect components

#

the result of the methods are used

polar acorn
#

It seems like you can easily do this in a static class. I'd say just try and if anything says it needs a reference then move that to a monobehaviour

swift crag
#

Do you need to remember data between function calls?

#

Or is this just a pile of formulas?

ivory bobcat
timber tide
# tired gulch Hello, so I have an object that damages the Player. In the future I want to add ...
[CreateAssetMenu(fileName = "New Trap Object", menuName = "Trap")]
public class TrapScriptableObject : ScriptableObject
{
  [field: SerializeField] public Damage { get; private set; }
  [field: SerializeField] public DamageInterval { get; private set; }
  [field: SerializeField] public List<Effect> EffectApplications { get; private set; }
  [field: SerializeField] public Sprite sprite { get; private set; }
}

public class Trap : Monobehaviour
{
  TrapScriptableObject SO;

  //runtime assignment
  public AssignTrap(TrapScriptableObject SO)
  {
    this.SO = SO;
    //set sprite and stuff
  }

  //editor assignment
  public OnValidate()
  {
    //set sprite and stuff
  }

  void OnCollisionEnter(Collision collision)
  {
    //Apply SO.Damage every SO.DamageInterval to player
  }
}```
Some ideas. You can also just use multiple prefabs if you want to just have specific gameobjects with set sprite and collider radius ect without sticking that info into the SO. This idea shines more when you have more than a couple of traps with different degrees of damage, otherwise making multiple prefabs and setting values directly in the editor works fine.
ivory bobcat
#

If there aren't instances of data, you'll not need an instance.

hidden sleet
#

I've got these SOs on my inventory now, but I'd like to view each item as a drop down. Is there something I'm missing to do so? ```cs
[CreateAssetMenu]
public class RawItemSO : ItemSO
{
public string[] labels;

public override void Spawn()
{
    Debug.Log("Spawned raw");
}

}```

[CreateAssetMenu]    
public class StructureSO : ItemSO
{
    
    public StructureSerialised structure;

    public override void Spawn()
    {
        Debug.Log("Spawned structure");
    }
}```
#

Is it because the inventory slot is just a base ItemSO type?```cs
public class InventoryItem
{
public int quantity;
public ItemSO item;

public InventoryItem(ItemSO Item, int quantity) 
{
    this.item = Item;
    this.quantity = quantity;
}

public void ChangeQuantity(int newQuantity)
{
    quantity = newQuantity;
}

}```

timber tide
#

You mean you want to see more derived items in the drop down?

hidden sleet
#

Yeah

strong moth
timber tide
#

As it is, yeah it'll show you everything that's derived from ItemSO

zinc warren
#
RenderTextureToRawImage(obj, newFeature.transform.Find("FeatureIcon").GetComponent < RawImage > (), renderCamera, renderTexture);
private void RenderTextureToRawImage(GameObject objPrefab, RawImage rawImage, Camera renderCamera, RenderTexture renderTexture)
{
    GameObject obj = Instantiate(objPrefab);
    obj.transform.position = renderCamera.transform.position + renderCamera.transform.forward * 2 f;
    obj.transform.LookAt(renderCamera.transform);
    obj.layer = LayerMask.NameToLayer("UiItems");
    foreach(Transform child in obj.transform)
    {
        child.gameObject.layer = LayerMask.NameToLayer("UiItems");
    }
    renderCamera.Render();
    Texture2D texture = new(renderTexture.width, renderTexture.height, TextureFormat.RGBA32, false);
    RenderTexture.active = renderTexture;
    texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
    texture.Apply();
    RenderTexture.active = null;
    DestroyImmediate(obj);
    rawImage.texture = texture;
}
private(Camera, RenderTexture) CreateComponents()
{
    RenderTexture renderTexture = new(256, 256, 24);
    GameObject cameraObject = new("RenderCamera");
    Camera renderCamera = cameraObject.AddComponent < Camera > ();
    renderCamera.targetTexture = renderTexture;
    renderCamera.enabled = false;
    renderCamera.clearFlags = CameraClearFlags.SolidColor;
    renderCamera.backgroundColor = new Color(0, 0, 0, 0);
    renderCamera.cullingMask = 1 << LayerMask.NameToLayer("UiItems");
    return (renderCamera, renderTexture);
}

why isn't it rendering the children of the obj?

hidden sleet
timber tide
#

Yeah, maybe naughty attributes can help you out, but as it is you've no constraints on the class so it'll always show what's insertable

edgy canyon
#

Hello, can you explain me what does the currentVelocity parameter in Vector2.SmoothDamp do?

strong moth
ivory bobcat
burnt vapor
#

The issue is Discord's lack of syntax highlighting, not the code

timber tide
hidden sleet
visual hedge
#

pseudocode:

int totalCount = PassiveSkills.Count + ActiveSkills.Count;

if one of those lists has 0 elements, will it throw an error?

strong moth
burnt vapor
#

Otherwise no

zinc warren
strong moth
ivory bobcat
visual hedge
#

so even if both have 0 elements, int totalCount will be 0, right?

tired gulch
burnt vapor
visual hedge
burnt vapor
#

Glad to help

hidden sleet
#

So like, these processed items are one from a pool, but each structure will be different

ivory bobcat
hidden sleet
#

I think I might have built this up wrong

#

blast

strong moth
visual hedge
#

stupid noob question, what would be else for this one:

if (someInt >= 0)
  //blah blah
else
 // blah blah

else would be like someInt < 0 or someInt <= 0?
Or I better use else if?

polar acorn
#

So, if the condition someInt >= 0 is not true, it runs else

#

Due to literally the definition of a boolean, a number can only be >= 0 or not

visual hedge
#

oh, yeah, silly me. So if it's = 0 or > 0, so else would be left only with <. PErfect, thank you. Brainfarts are such a brainfarts

burnt vapor
visual hedge
burnt vapor
#

Unless this truly is just a massive brainfart, then ignore it

#

Alrighty

visual hedge
#

I am pretty confident in that topic just had some strange brainfart really πŸ™‚

sterile wraith
#

What would you say is the best way to rotate just on one axis. there are multiple options like dealing with eulars or quaternions, etc. what is the optimal option rotating by a certain degree?

hidden sleet
#

It seems then the issue I've got then is that my inventoryItem class takes an SO only, but in my case I might actually need it to be a custom class that isn't an SO. ```cs
public class InventorySO : ScriptableObject
{
[SerializeField]
private List<InventoryItem> inventoryContainer;

```cs
public class InventoryItem
{
    public int quantity;
    public ItemSO item; 

If I want to keep the same code for the InventorySO class, but just have inventoryItem use a different type, say

public class InventoryItemStructure
{
  public int quantity;
  public Structure structure;

What could I potentially do to avoid having to duplicate and rewrite my whole inventory?

sterile wraith
languid spire
sterile wraith
#

i havne tused unity inawhile so im trying to remember this stuff do u multiply them?

languid spire
#

A great aid to memory is the unity docs

sterile wraith
languid spire
#

you have not even said what kind of rotation you want

frigid sequoia
#

I am guessing what you want is to change one of the axis of the eulerAngles, then copy that to quaternions and apply that

shadow rain
#

hi, could someone please give me an idea on how to make a sprite follow the mouse? (2D game)

sterile wraith
sterile wraith
languid spire
#

but is it going to be setting a rotation, or rotating an existing rotation

languid spire
#

he means gimbal lock

timber tide
#

oh no he said the g word

frigid sequoia
# shadow rain hi, could someone please give me an idea on how to make a sprite follow the mous...

Learn how to convert the mouse position on the screen to a real position in the game world in Unity

p.s. if you're using Unity's new Input System: instead of Input.mousePosition, type Mouse.current.position.ReadValue();

00:00 Intro
00:36 Get the mouse's screen position
01:50 Screen to World Point
05:30 Screen Point to Ray
09:10 Using a Layer ...

β–Ά Play video
shadow rain
#

ty

sterile wraith
#

an existing rotation

timber tide
frigid sequoia
hidden sleet
#

although there's still more to do before I can test it

languid spire
hidden sleet
#

But I have this at the moment ```cs
public abstract class InventoryItem
{
public int quantity;

public abstract void ChangeQuantity(int newQuantity);

}```

public class InventoryPlainItem : InventoryItem
{
    public ItemSO item;

    public override void ChangeQuantity(int newQuantity)
    {
        quantity = newQuantity;
    }
}
public class InventoryStructureItem : InventoryItem
{
    public StructureSerialised structureSerialised;
    public override void ChangeQuantity(int newQuantity)
    {
        
    }

}``` Which I assume will work
slow lily
#

how do i fix this?

timber tide
#

somewhere in your code #endregion is expected

#

figure out where #startregion is and what you're trying to collapse

hidden sleet
#

However I'm trying to rewrite this section now. It's very messy, and is just supposed to convert an inputted item into another, but currently the output items are stored in this dictionary. Is there a better solution than this? ```cs
public class CraftingManager : MonoBehaviour
{
//Handles turning one object into another and holds the process to perform
public InventoryManager inventoryManager;
public RawItemInventory rawInventory;
public NewProcessedItemInventory processedInventory;
public List<SOItem> outputItems = new List<SOItem>();
public Dictionary<CraftMethod, SOItem> craftToItem = new Dictionary<CraftMethod, SOItem>();
public static CraftMethod craftMethod;

// Start is called before the first frame update
void Start()
{
    rawInventory = inventoryManager.getRawInventory();
    processedInventory = inventoryManager.getProcessedInventory();
    craftToItem.Add(CraftMethod.RodCraft, outputItems[1]);
    craftToItem.Add(CraftMethod.CuboidCraft, outputItems[0]);
    craftToItem.Add(CraftMethod.PlateCraft, outputItems[2]);
}

public void ProcessInput(GameObject inputObject)
{
    if (inputObject.CompareTag("RawMaterial"))
    {
        switch (craftMethod)
        {
            case CraftMethod.RodCraft:
                processedInventory.AddStackableItem(craftToItem[CraftMethod.RodCraft], 1);
                rawInventory.RemoveRawItem(inputObject.GetComponent<ItemController>().item);

                Destroy(inputObject);
                break;
            case CraftMethod.CuboidCraft:
                processedInventory.AddStackableItem(craftToItem[CraftMethod.CuboidCraft], 1);
                rawInventory.RemoveRawItem(inputObject.GetComponent<ItemController>().item);

                Destroy(inputObject);
                break;
            case CraftMethod.PlateCraft:
                processedInventory.AddStackableItem(craftToItem[CraftMethod.PlateCraft], 1);
                rawInventory.RemoveRawItem(inputObject.GetComponent<ItemController>().item);

                Destroy(inputObject);
                break;
            default:

                Destroy(inputObject);
                break;
        }
    }

}

}```

#

is there a way to make these code blocks that we type expandable so it doesn't take up so much space. I feel like I blot out most of chat when I send something

frigid sequoia
slow lily
ivory bobcat
eternal falconBOT
swift crag
sterile wraith
slow lily
swift crag
#

Use one of those paste sites.

timber tide
#

need 2x end regions probably

swift crag
#

You have two #region directives and only one #endregion directive

#

They are unbalanced.

slow lily
#

ah i see, thanks

desert iris
#

Anyone need any help? Ping me if you need anything

visual hedge
# desert iris Anyone need any help? Ping me if you need anything
                for (int i = 0; i < Tesst.endTargetList.Count; i++)
                {
                    for (int j = 0; j < Tesst.strikeCount; j++)
                    {
                        ui.animator.Play("Attack");
                        ui.audioSource.Play();
                        yield return new WaitForSeconds(0.7f);

                        if (Tesst.canCrit && Random.Range(0, 100) <= unit.Stats.curCRIT)
                        {
                            isCritical = true;
                            Tesst.TrueDamage = Mathf.Round(Tesst.TrueDamage * unit.Stats.critDamage);
                        }
                        //stop striking the target if it's already dead
                        if (Tesst.endTargetList[i].currentState != TurnState.DEAD)
                            Tesst.endTargetList[i].TakeDamage(this, Tesst.TrueDamage, Tesst.isDodgeable, isCritical, Tesst.ignoreDefense, Tesst.targetStat, Tesst.isHeal, Tesst.applyStatusEffects);
                        yield return new WaitForSeconds(0.7f);
                    }
                }

I need to implement the passive skill that would add +1 strikeCount while doing attacks.
So in the code above, where do I fire the passive skill code?
My thoughts were: Checking for any passive skill that is related to exactly between those: for (int i = 0; i < Tesst.endTargetList.Count; i++) { for (int j = 0; j < Tesst.strikeCount; j++) { and then then running their effects. right?

#

oh, yeah, btw, that Tesst was successful, so I better rename that struct πŸ™‚

hidden sleet
shadow rain
#

with instantiate how could i make more effects appear instead of just one

polar acorn
#

Instantiate more than one

shadow rain
#

like but how

polar acorn
#

Call Instantiate more than once

shadow rain
#

would that work for making a pen?

polar acorn
#

I have no idea what that means in relation to the previous question

shadow rain
#

nvm

shadow rain
polar acorn
#

sure, why not

shadow rain
#

so how could i use it in a script if u dont mind

polar acorn
#

If you want to have a sort of drawing thing it's probably better to use a single line renderer and add points as you move the mouse anyway rather than instantiating anything

shadow rain
#

i would rather it instantiate atm

hidden sleet
#

Just realised that after making these classes abstract, my inventory has broken. ```cs
public abstract class InventoryItem
{
public int quantity;

public abstract void ChangeQuantity(int newQuantity);

}

```cs
public class InventoryPlainItem : InventoryItem
{
    public ItemSO item;

    public InventoryPlainItem(ItemSO item)
    {
        this.item = item;
    }
    public override void ChangeQuantity(int newQuantity)
    {
        quantity = newQuantity;
    }

    public void SetItem(ItemSO item)
    {
        this.item = item;
    }
}

more specifically, this line doesn't work anymore since the InventoryItem is abstract now. From this, how can I then add a new item

private List<InventoryItem> inventoryContainer;

inventoryContainer.Add(new InventoryItem(item, quantity));
hidden sleet
strong moth
#
 cells[x, y].walkable = colliders.Length == 0 || new Func<bool>(() =>
 {
     foreach (var collider in colliders)
         if (collider.gameObject.layer == LayerMask.NameToLayer("Level"))
             return false;

     return true;
 }).Invoke();``` how bad of a practice is inlining functions like this
shadow rain
swift crag
#

you don't need to construct a new Func<bool>

#

you can just write () => true or whatever

#

and it's pretty reasonable to do this when you only use that exact code once

#

If you use it many times, consider extracting it into a method

lapis yew
#

Abstract classes cannot be instatiated

strong moth
shadow rain
#

can u make a pen with instantiate?

lapis yew
polar acorn
swift crag
#
(() => true)()

kinda funny looking

#

oh wait, that's wrong

hidden sleet
#

unless I am misunderstanding

shadow rain
swift crag
lapis yew
#

Besides

hidden sleet
swift crag
#

You usually use an anonymous function when you want to pass it to someone else

swift crag
polar acorn
wintry quarry
swift crag
#

Otherwise, you have a design problem here. You don't know what kind of inventory item you even need to create.

lapis yew
#

And have a single item baseclass

strong moth
timber tide
#

you can pass them around as thebase abstract type, but you need an idea what the more derived type is for when you need to call those polymorphic methods. (at least on construction of the item)

strong moth
#

i had no idea that function existed

lapis yew
#

Why do you set the quantity in the item class itself?

hidden sleet
wintry quarry
strong moth
slow lily
#

does anyone know how i can fix this?\

polar acorn
#

they either both need to be doubles or both need to be floats

lapis yew
timber tide
#

cant down cast from double to float, no?

lapis yew
#

Oh

timber tide
#

not that you should anyway

polar acorn
#

The real question is why use doubles at all

timber tide
#

cookie clicker :)

polar acorn
#

All of unity's internals use floats, you should use floats when dealing with numbers

polar acorn
# timber tide cookie clicker :)

You're gonna need a specific data structure for numbers that big. Doubles don't give you more numbers, just more precise numbers

lapis yew
slow lily
timber tide
#

yeah true, that sounds like a fun project to add to my backlog of projects

eternal needle
#

You dont even get more precision by mixing the 2. Your precision is as precise as your weakest link, which is the float.

polar acorn
polar acorn
lapis yew
hidden sleet
#

So, still wrapping my head around this, but if I have these ```cs
public abstract class ItemComponent : MonoBehaviour
{

public int quantity;


public void DestroyItem()
{
    Destroy(gameObject);
}

}

```cs
public class ProcessedItemComponent : ItemComponent
{
    public ProcessedItemSO item;
}

And here I want to look at the component of the object, get that SO and remove it from the inventory,

private void ProcessInput(ItemComponent itemComponent)
{
    craftingMethod.CraftItem();
    rawInventoryController.inventoryData.AddItem(new ProcessedItemSO(), 1);
    rawInventoryController.inventoryData.RemoveItem(itemComponent //WANT TO GET THE ITEM HERE);
``` Would I need some kind of abstract method for GetItem in that abstract itemComponent class?
polar acorn
#

Mathf is literally named for the fact that it deals exclusively with floats

slow lily
# polar acorn Show the tutorial

https://www.youtube.com/watch?v=A5f_uuL11Xg he starts with this at 5:51

Show your Support & Get Exclusive Benefits on Patreon (Including Access to this project's Source Files + Code) - https://www.patreon.com/sasquatchbgames
Join our Discord Community! - https://discord.com/invite/aHjTSBz3jH

Make cookie clicker with this quick Unity tutorial. We'll even set it up so that it's SUPER easy for you to add your own upg...

β–Ά Play video
lapis yew
slender nymph
#

you missed the part where the property is also a double

polar acorn
eternal needle
lapis yew
polar acorn
slender nymph
polar acorn
#
"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 148
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2024-3-14
slow lily
lapis yew
#

@hidden sleet so what are you doing with your inventory right now?
It seems to me that you're making it unnecessarily complicated

eternal needle
hidden sleet
# lapis yew <@372070829992837130> so what are you doing with your inventory right now? It s...

In summary, I've got an inventory script with a container. There are three types of items that can exist in an inventory. An inventory can only have one type, so there are three in total. I wanted, if possible, to only have one inventory script and design it so that it works the same no matter what kind of item is in it. But the issue I have now is that by doing so with abstract classes, I can't get the information I need.

hidden sleet
#

each inventory is a different SO asset, but I wanted them to have the same script contents as to now have as much duplicate code

faint osprey
#
    {
        StartCoroutine(CameraShake("GravitySlam"));
        while(true)
        {
            if(gameObject.transform.position.y >= 13.4)
            {
                gameObject.transform.position = new Vector3(gameObject.transform.position.x, 13.5f, gameObject.transform.position.z);
                break;
            }

            if(onBotWall == true)
            {
                Debug.Log("working0");
                gameObject.transform.Translate(gameObject.transform.up * Time.deltaTime * 30);
            }

            if (onTopWall == true)
            {
                Debug.Log("working1");
                gameObject.transform.Translate(-gameObject.transform.up * Time.deltaTime * 30);
            }

            yield return new WaitForSeconds(0.00001f);
        }

        if(onBotWall == true)
        {
            onBotWall = false;
            onTopWall = true;
        }
        else if (onTopWall == true)
        {
            onBotWall = true;
            onTopWall = false;
        }
    }``` I dont understand why the first time this coroutine is called working0 gets printed like normal but then the if with working 1 on the second time its called doesnt get printed even tho onTopWall is true
hidden sleet
#

But now I can't do this for instance ```cs
InventoryItem inventoryItem = inventoryData.GetItemAt(itemIndex);
inventoryItem.item.Spawn();

Because now it uses abstract classes, I don't know how to retrieve the item in order to spawn it and it's prefab
eternal needle
# hidden sleet In this case that is basically what's happening. In this scenario, you click on ...

Yes still in that case, the actual Item in your inventory still does not need to be a gameobject. You can still do it I guess but itll be more annoying. I would have a prefab specifically for items which are dropped, since you dont interact with them the same way you do if its in the inventory.
And im not entirely sure what your question is asking, but you are presumably removing a specific item, which you might wanna get by index or search through your collection of items for. This is stored in some array/list right?

lapis yew
#

My suggestion
Have a baseItemclass
This contains the icon and name
Then have derived classes for the specific item types
Then have an inventory class with a dictionary that contains one item type (alternatively have a list of dictionaries, this wall you'll basically have 3 inventories)

This way you can expand the item typed by deriving then again and adding more fields

#

No gameobjects involved

eternal needle
#

A list of dictionaries, god no

lapis yew
#

Or make a value pair class

#

Who cares

#

It's basically the same

eternal needle
lapis yew
hidden sleet
# eternal needle Yes still in that case, the actual Item in your inventory still does not need to...

That's what I'm doing at the moment. I've got an asset for each possible item type with a prefab attached, and any of my inventory items that reference an SO will therefore have this. Got the whole thing here anyways to make it clearer. https://hastebin.com/share/xuyetufadi.csharp

lapis yew
#

Why is your actual inventory a scriptable?

hidden sleet
#

just found it useful to do. Maintains data between scenes, didn't see anything wrong with it

lapis yew
#

The actual inventory should be a monobehaviour

Unless someone more knowledge than me thinks otherwise

past cloud
#

How come my vscode doesn't have IntelliSense like this guys video does

eternal falconBOT
eternal needle
hidden sleet
#

I think for the time being if I was able to have a method in this abstract class that let me get the item, override that in the ones above, and return the correct type, that might fix the errors I've got

eternal needle
past cloud
slender nymph
#

then you should have intellisense. if not you missed something or you need to regenerate project files

lapis yew
hidden sleet
#

I was thinking if I could do something like this, that might fix it. But I've got no clue what the return type should be if it will end up returning either a SerialisedStructure or an ItemSO

 public abstract class InventoryItem
 {
     public int quantity;     
           

     public abstract void ChangeQuantity(int newQuantity);

     
     public abstract ### getItem();
    
 }```
shadow rain
#

could someone please explain too me on how to instantiate multiple objects if the mouse is held down

slender nymph
#

do you know how to check if the mouse is held down?

rich adder
shadow rain
#

kinda

slender nymph
#

do you know how to instantiate an object?

shadow rain
past cloud
slender nymph
rich adder
shadow rain
#

its just idk how to do it multiple times

#

like im making a pen so like drawing

#

but its only making little dots rn

timber tide
rich adder
shadow rain
#

!code

eternal falconBOT
rich adder
#

pretty much

lapis yew
#

@hidden sleet this describes it

Tldr
Use static keywords for non Monobehaviour object and Gameobjects
Use DontdestroyOnLoad for components and Gameobjects
Use Xml or json files to save data on the computer

https://stackoverflow.com/questions/32306704/how-to-pass-data-and-references-between-scenes-in-unity

slender nymph
timber tide
#

the idea is try to keep as much behaviour polymorphic, but when it comes needing to know the type, you need to start doing comparison or manage a way to keep track of the type

shadow rain
#
    // Update is called once per frame
    void Update()
    {
        if(Input.GetMouseButtonDown(0))
        {
            drawing = true;
            if(drawing == true)
            {
                Instantiate(effect, pen.transform.position, Quaternion.identity);
            }
        }

        if(Input.GetMouseButtonUp(0))
        {
            drawing = false;
        }
    }
#

i had that

#

do i not need that then?

hidden sleet
shadow rain
eternal needle
hidden sleet
#

might do to be honest

#

where would it be best to?

rich adder
eternal needle
shadow rain
rich adder
#

GetMouseButton and GetMouseButtonDown are pretty different

slender nymph
rich adder
#

you can hold GetMouseButtonDown as long as you want, its not gonna do anything after it ran that 1 frame

lapis yew
#

GetButton is every frame
GetButtonDown is called 1 frame when pressed

shadow rain
#

so wouldnt i be better using getbutton?

timber tide
rich adder
#

how else will you learn

lapis yew
#

fuck around and find out

rich adder
#

ye

shadow rain
#

ok

hidden sleet
timber tide
#

you can't override return types

hidden sleet
#

right, so I can't just override the method and have it return the correct type

timber tide
#

this is where generics can help, but honestly not worth the hassle

hidden sleet
#

I don't really know of any other way I can achieve this

lapis yew
#

well if you put BaseClass as return type then you can Put DerivedClass as returned object

hidden sleet
timber tide
#

it sounds like you eventually need to do some type comparison so if there is specific methods that only exist on the most derived type, then it will require you to do those operations

lapis yew
shadow rain
#

I GOT IT WORKING

#

WOOOO