#💻┃code-beginner

1 messages · Page 433 of 1

slate haven
#

Thank you!!

#

needed something like this

halcyon dagger
#

np! literally watched it a few days ago to solve a problem, just ignore the part where he links the turret rotation to the crosshair

rich adder
#

you can make a list of functions . Though I have no idea what you want to do with the switch, you can just use a switch if anything

atomic holly
rich adder
#

enum is just a number

#

what are you trying to do exactly..

atomic holly
#

I do a scriptableObject to create my weapons and I want to can choose what function of the weapon we will use it with, like the bowattack or the magicspells

waxen adder
#

Having a tough time understanding the difference between Move and SimpleMove for character controllers, despite having looked at the documentation. Can anyone help paint a better picture?

rare socket
#

Hi all! I'm currently attempting to create a first person camera. Though it functions, I find that in-scene objects suffer from a sort of jitter movement. I've looked through different tutorials posted on Youtube, however none seem to work. If anyone could link a video or suggest a solution, that would be awesome!!

My camera's code: https://gdl.space/ekupenuxag.cpp
My player movement script: https://gdl.space/ahacequkox.cpp

rare socket
#

However, move takes more effort to code. :D

rocky canyon
#

Move() is the best.. coding in ur gravity isnt hard

#

u just add a simulatedGravity to the vector

waxen adder
#

Gotcha, appreciate it!

Also, I went and made my camera a child of my player and I also get the jitteriness you're getting @rare socket

rare socket
#

Ooooh. Thanks for the heads up!

waxen adder
#

What are some good ways to check if a player is on the ground (assuming character controller is being used)?

rocky canyon
#

CC has its own built in Grounded

#

most people like to make their own

#

raycasts, trigger colliders, checksphere etc

#

the builtin one is good enough for basic stuff

waxen adder
#

Huh, I never knew that. Any idea why people would make their own? Any undesirable things about the built in one?

rocky canyon
#

i haven't found anything that stops me from using it

#

some say its less than accurate

waxen adder
#

Hmmm. Will take a look at that

rocky canyon
#

basic characterContoller.isGrounded

#

there was an issue.. my headBob.CameraRebound() method shuld get called when the player lands.. in my head it made sense to set the wasGrounded bool @ the end of hte update loop.. but that didn't work.. so i had to set wasGrounded on the first of the frame.. (which in my mind didnt feel right) but it works out just fine..

#

could be issues like that that cause ppl to code in their own groundCheck.. but as long as i can work around little issues like that i'll keep using the cc's ground check

waxen adder
#

Interesting. Yeah, looks like I have some playing around to do

rocky canyon
#

have fun 🍀

#
    private void OnDrawGizmos()
    {
        if (Application.isPlaying)
        {
                var gizmoColor = characterController.isGrounded ? Color.green : Color.red;
                Debug.DrawRay(transform.position, -transform.up * (characterController.height/2 + 0.2f), gizmoColor, .1f);
        }
    }``` i also use some Gizmo's DrawRay to visualize it
#

(green w/ its grounded and red when its not)

#

helped me when working on it (my jumps and slopes especially)

#

characterController.height/2 + 0.2f i just guessed the length..

scenic saffron
#

how do i round floats

scenic saffron
#

thx

#

but how can i round to a different decimal? (fixed)

rocky canyon
#

are u actually rounding the float? or do u just want to display the float as text (with a certain number of decimals)

ionic zephyr
#

If I have an Inventory and in one of the UIs I only want to show ONLY slots that contain specific types of objects is it okay if I instantiate the maximum number of slots in my inventory in each UI and then setActive ones and others no???

#

or is it a better way to do It?

#

I have an abstract inventory which holds ALL the objects but I want specific UIs that show specific types of objects

#

suggestions are accepted

ionic zephyr
eternal needle
#

You should really just show code or what you're specifically trying to display. A lot of this doesnt make sense.

#

All I got from this was you're trying to display stuff and are asking if you should use setactive. Which yea would let you show objects by setting them active

ionic zephyr
#

And I want them to be expandable, for example, if I have 2 tools I want it to show 2 slots that contain tools, same for 1, 4, 6, 2...

eternal needle
#

You can use setactive I guess if your UI automatically adjusts based on active UI elements.

ionic zephyr
rocky canyon
#

a UI manager.. thats controlling what gets enabled /disabled

#

thats my go-to.. id like to see other suggestions tho

ionic zephyr
rocky canyon
#

for UI ? sure

ionic zephyr
shell matrix
#

I find the concept of state machine very difficult, if you know any sites that explain it well, I watched a course on Udemy

#

and i don t understand nothing

slate haven
#

Folks I have participated in the 48 hour game jam. I worked for 12 hours till now and all I have completed is Player Input, Idle Run Jump Animations and little bit of Rigging, Movement, Aiming, Crosshair for a 3D game

How would you judge my speed?

rocky canyon
#

the logic and stuff remains on the Component

#

shouldnt affect the logic any.. unless u need it to

ionic zephyr
#

okay, thanks a lot

rocky canyon
#

i recycle stuff for game-jams.. i'd have most of that in my backpocket

slate haven
rocky canyon
#

no worries.. its good to even try out gamejams

slate haven
#

from kenney

eternal needle
slate haven
rocky canyon
#

game-jams aren't gonna end up perfect

half egret
#

Keep doing things over and over and eventually you'll get faster, keep at it and good job

rocky canyon
#

best to just try to get ur mechanics.. and bulk of the game..

#

polish the last few hours

summer stump
rocky canyon
#

facts lol

slate haven
half egret
rocky canyon
#

source: land-fill

half egret
#

perfect for trash

rocky canyon
#

helps motivate me tbh

#

i know they had technical hurdles to cross

#

i just like to think they gave it their best.. with Good tech

#

and im just a better developer 😈

half egret
#

To be fair to them! Resources are far more abundant today 😄

rocky canyon
#

🤫

#

i kinda miss when everything was awe-inspiring no matter how simple

#

now its like "meh, thats been done before.. nothing special"

slate haven
#

Imagine creating something unique to you but you see the whole world already way ahead of it

dim yew
#

i'm having issues with singletons, what am i doing wrong?

#

i didn't know it was possible to have a nullreference for this

slender nymph
#

this is not the file your error originates from. what is line 12 of TileColor.cs

dim yew
#

forgot to send that oops

slender nymph
#

so the reason you are getting a NRE here is because you are trying to access the singleton before it has been fully set up. Don't access GameManager.instance before its awake method has run, to ensure you don't you should not access the instance property until Start at the earliest

rocky canyon
#

yup, sounds accurate

dim yew
#

ahhh i see

#

thanks a lot

copper python
#

Why is the short hand for null pointer exception NRE and not NPE 💀

summer stump
slender nymph
copper python
#

Oh yeah that's right haha, I'm used to work with C

languid spire
slender nymph
#

yes I am aware of the similarities of pointers to references, but references are not pointers, though they use them under the hood. i would think you of all people would be super pedantic about that sort of fact

languid spire
shell matrix
#

I don't understand the logic of this code, I watched a course on Udemy, I can barely keep up. That's all I wrote and apart from the fact that I didn't understand anything, the code doesn't work anymore, my status doesn't change https://paste.ofcode.org/bLWE285Hz85PbcCtwEann3. if somebody help me to the code and make a logical explication. Thx

atomic holly
#

Hi, I develop my weapons system and I do this script for the ScriptableObject (Item is a ScriptableObject)
And I call it in a script on my Player gameobject
Scripts :
https://gdl.space/obonoboret.cs
But when I click on my right click, I have this error :

Weapon+BowAttackBehavior.Attack () (at Assets/Code/Scripts/Items/Weapons/Weapon.cs:61)
PlayerDamage.Update () (at Assets/Code/Scripts/Player/PlayerDamage.cs:32)```
Why ?
atomic holly
slender nymph
#

BowSystem.instance is null. are you certain it has been assigned to?

atomic holly
slender nymph
#

it likely needs to be assigned an instance of BowSystem because i'm assuming it is part of the singleton pattern. if it is null then trying to access any of its members, like that ThrowArrow method is going to throw a NullReferenceException

atomic holly
slender nymph
#

huh?

atomic holly
#

Maybe I don't understand your question 😭

eternal needle
slender nymph
#

just like you are for your other singleton the PlayerDamage class

summer stump
eternal needle
atomic holly
#

What I need to assign to instance of the class BowSystem ?

slender nymph
#

BowSystem is clearly meant to be a singleton (this is extremely clear even though you haven't bothered to show its code). you have another singleton that you have shown called PlayerDamage. look at how you set that up and do the same for the BowSystem

summer stump
atomic holly
atomic holly
summer stump
jaunty wedge
#

Hey, could someone help me out please? I have a button which covers whole screen horizontally, and when I click it a create function is called, which takes the mouse position, and creates an object (action) with that value. Then a line is created, which takes the same position, and is spawned right under my cursor. The thing I'm having trouble with is that I want to connect each object with each line, so that I could change the position in the object, and the position of the line would change respectfully. The initial idea was that when a line is created, I could click on it, a "settings" menu would pop up, and I could change each value manually through there, but I can't figure out a way to parse the values between an instance of an object (action) and a game object.

atomic holly
#

But I don't see it's against the rules to suggest use an IA for it in the rules of the server

rocky canyon
#

problem w/ AI and learning is you don't know when its wrong.. or telling u some stupid ridicilous thing.. then they'll end up back here trying to fix something the AI can't anymore

kind stratus
#

Hey

rocky canyon
#

and you may not be around to help fix it.. (then guys that never suggested using it are stuck trying to help them sort it all back out)

half egret
rocky canyon
#

lol. trash it 😄

languid spire
#

nah, we'll just ping Magico every time someone posts AI code

rocky canyon
#

🤣 saucy..

atomic holly
rocky canyon
#

who would? 😄

atomic holly
#

I just started a month ago so for me, AI for it was good

languid spire
rocky canyon
atomic holly
#

But now, I know it's not very good 🙂

ivory saffron
#

I have a list items. I want to make a method that takes a value and adds it to the list, then returns it's reference, so that you can delete that item later. How would i do that?

languid spire
ivory saffron
#

a simplier case is when it returns void, and i just delete by value. But there could be problems with that

languid spire
#

you mean return the index

ivory saffron
#

if it returns the index, and then some items are deleted from the list elsewhere, wouldnt it become wrong?

languid spire
#

yes indeed

#

but you alread have the value so why return it?

waxen adder
#

How bad would it be to spam approximately 360 raycasts to check all around a player?

ivory saffron
#

I need to add the value to the list then delete it.

waxen adder
#

Gotcha, will do box/sphere then

languid spire
ivory saffron
#

right, i just overcomplicated things. i know how to do it now

jaunty wedge
#

the yellow line is the one created by clicking on the button, all the red lines are there just for the reference of position I needed when creating this, and the second picture is the function ran by clicking the said button

#

if there's any more info I need to provide please let me know, because I'm really stuck here

languid spire
#

you probably want worldPositionStays=true on your SetParent

#

and, please dont use classes like Action, they confuse with System.Action

jaunty wedge
#

I need a better name but I cant come up with it lol

jaunty wedge
languid spire
jaunty wedge
#

yea ik, I mean like how would that help me connect the object to a game object

languid spire
#

sorry, I just thought you were having a problem with the position

jaunty wedge
#

oh

#

well sorry if I my description confused you lol, I was just trying to explain everything in a single message

tardy needle
#

could someone help me out with rotating 2d objects, im new and it seems confusing for me. Thanks

chrome cobalt
#

why is my text so choppy

rocky canyon
#

i just use AngleAxis w/ transform.forward

rocky canyon
chrome cobalt
#

text mesh pro

rocky canyon
#

is this in gameview? is ur scaling set to 1x?

#

any bit of zoom will cause jagginess

chrome cobalt
#

i just spawned it and it was choppy

#

and whenever i mess with the settings it doesnt help

chrome cobalt
#

this all i got

#

no rendering tab either

rocky canyon
#

the other settings mentioned down the page are on the actual TMP material

#

TMP is typically pretty smooth everytime ive used it...

#

unless it was a bad font.. or a low quality atlas texture

#

but i see ur using the built-in LiberationSans font.. (that font isn't as smooth as the others i tend to use.. but i dont think ive seen it as jaggy as the example you shown)

ivory bobcat
rocky canyon
#

i changed mine to /Mobile/ shader to test.. and that doesn't make mine jaggy either.. soo not that either..

#

ya, possibly something im not seeing

queen adder
#

Why are my tree's like this when built and ran but not in the unity editor

rocky canyon
#

something something shader keyword

ivory bobcat
#

Is this code related?

queen adder
rocky canyon
#

my guess would be lighting would be the best place for it

queen adder
#

alright thanks

ivory bobcat
rocky canyon
#

may get a faster response in there ^

#

less refined.. but quicker

ivory bobcat
#

But definitely where spawn has suggested

rocky canyon
#

my guess is the terrain shader u use for the tree's isn't being built over to the standalone correctly

#

looks like they're using an unlit shader or something (hence why all the tree's are the same color) no shadows*

#

w/ some PPFX grain/dither on top 🙂

chrome cobalt
pearl temple
#

question about how serialized fields can be set.
I am using a dear imgui package for unity and it needs a script attached to objects in order to render. That script has several serialized fields to setup the rendering.
If I attach this dear imgui script to an object in the scene some of these fields are prefilled with defaults. Yet when I search in the code for references to the field there are none. So I am guessing there must be some other thing going on? The reason is because I don't want to have to setup this component in every scene myself, I would rather just do it once from code

ivory bobcat
pearl temple
#

they are all private yes

eager spindle
#

along with the script that has the setup

#

using external IMGUI with unity in 2024 is quite frankly a strange choice

#

but go ahead

pearl temple
#

yeah but e.g I want my managers which are singletons spawned when they are called to render imgui stuff for debugging. There is nothing for me to setup

#

I have been using imgui for a long time and have no desire to switch to something else

eager spindle
#

unity already has imgui too, if it hasnt been deprecated yet

ivory bobcat
#

You wouldn't be able to access the members through code if they're private - assuming you're attempting to do so through a different script.

eager spindle
#

see Unity's OnGUI, you can use stuff like GUI.DrawTexture

#

even less setup required

#

should follow imgui standards too

pearl temple
#

I am just trying to create the script on an singleton object using AddComponent<DearImGui>()
I fill those first two fields after I created the object. But those other three fields at the bottom are empty when I just create it from code. Yet when I drag and drop the thing they are filled.

grave cipher
#

how do i check if a rigidbody has stopped?

steep rose
shell herald
#

how can i check if currently no children selectable objects are selected?

half egret
shell herald
scenic saffron
#

How do I change the Position of my Player without them loosing there momentum? (2D)

half egret
#

This might help

#

In your movement controller, sync your transforms before moving

pine aspen
#

Is it possible to acess a Script from another Scene?

half egret
#

Actually hrm, I don't think it will. It'll flush the momentum.

scenic saffron
pearl temple
# pearl temple

well to answer my own question. I just load a prefab for my singleton that already has the imgui script configured. Works like a charm and I don't have to setup things in the scene

shell herald
pine aspen
#

just asking, incase i need it somewhen

shell herald
#

you can take objects with scripts into another scene with dontdestroyonload

#

but you cant directly call a monobehaviour that is in another scene

pine aspen
#

wait thats actually smart

#

ty

summer stump
#

@pine aspen @shell herald
To be clear. No, you cannot load an object from a scene that is not loaded, because it simply will not exist. Everything in a scene is destroyed when unloading the scene.
However, you can have multiple scenes loaded at the same time, and you can access a gameobject from another loaded scene the EXACT SAME WAY you access on from the same scene
DontDestroyOnLoad IS a scene. It is a special scene that doesn't destroy everything in it when a new scene is loaded non-addively.
It works nearly the same as additive scene loading.

grave furnace
#

why i can't see the camera limits?

strong wren
grave furnace
#

thxx!!

#

is that disabled by default now?

#

idk if im crazy but i can remember old versions not being like this

frigid schooner
#

hello im new to unity, can someone teach me how to move rigidbodies?

#

currently I have a character controller and rigidbody attached to an empty called the FPScontroller, and the main camera is a child of this empty. I have another sphere with rigidbody attached to it, but I cant seem to push the sphere by walking towards it.

#

I think the main reason would be that I dont have a 3D object attached to the FPS, I trial and errored adding a capsule+rigidbody as a child of fps, but weird stuff happens even if I lock the rotation of the capsule

eternal needle
frigid schooner
#

sorry can you explain more

#

I am like new new to unity, I just followed youtube tutorials to get to this point.

radiant frigate
#

just realized this isnt code related

eternal needle
steel stirrup
radiant frigate
#

nope

#

i think i dont even have one

#

does one come by default?

steel stirrup
#

So the issue is that you're trying to edit a collider on an object right?

radiant frigate
#

or do i need to add something somehow manually?

#

on a tile map specifically

#

i want to change its collider type´s effect to grid based instead of sprite based

frigid schooner
#

explain why rb and cc cant coexist
and what specifically should I do now to be able to push stuff. If you are saying rb and cc cant coexist, can I move stuff with player using code? How exactly would that look like

steel stirrup
#

Basically, it's self defeating and combining them means you have a design issue

#

if you want physics based movement, you shouldn't want the features a character controller provides because they're simply out of scope, and vice versa

summer stump
summer stump
eternal needle
eternal needle
steel stirrup
#

If it's present, all you need is to get a reference to it (either by drag/dropping to your script in the inspector (preferable) or finding with one of the appropriate methods (slower)

radiant frigate
#

i want to access this

#

but it isnt showing nowhere

steel stirrup
radiant frigate
#

the thing is i dont have this on my editor

#

i cant find it

#

i know how to acces via code but i do not have this component/asset

#

or if i have it im blind

steel stirrup
#

zoom out a bit, is this still about trying to change the collider type?

radiant frigate
#

that screenshot is from the unity manual

next bolt
#

Im having a problem. In my player theres a variable. public TMP_Text popup; and in unity i assing the script with the text but as soon as a start the scene my script unassigns it.

radiant frigate
#

i do not have that in my project, or if i have it i do not find it

steel stirrup
radiant frigate
#

but i do not know how to add one like that

eternal needle
steel stirrup
next bolt
radiant frigate
#

!code

eternal needle
#

!code

eternal falconBOT
radiant frigate
radiant frigate
eternal needle
steel stirrup
#

if you're assigning it in the inspector, then only call GetComponent if its null

steel stirrup
#

wild guess, it's probably in a child

radiant frigate
#

i figured out my problem

steel stirrup
#

GetComponent will only get the component if its on the same gameobject as the script, if you want to get a component on a different object you need to call getcomponent in that scope instead

radiant frigate
#

it was as simple and dumb as one can think

#

i forgot to add a collider to the player

#

💀

steel stirrup
# next bolt Thank you very much

Also, ignore this if you don't care, but I'd strongly recommend using a standardized naming scheme for your code, it will make things MUCH easier to maintain and read at a glance in the future.

next bolt
steel stirrup
somber herald
#

vector3.magnitude can't be negative, right?

steel stirrup
green ledge
#

worst case scenario is to just try it with a quick test script and find out

steel stirrup
#

The length of the vector is square root of (x*x+y*y+z*z).

steel stirrup
mint remnant
#

been messing with mesh generation, started with simple a voxel, I keep seeing videos where people have like double or even tripple verticies on the corners. I'm guessing here that the GPU just don't give a shit about that and only cares where's the triangle I need to draw one.

next bolt
steel stirrup
#

It's important to focus on details, these aren't small things

#

Someone looking at your code (or you when you're tired) can easily confuse your 'carrying' gameobject with a bool, since you named your bool 'holding'

#

Inconsistency creates spaghetti down the line

steel stirrup
#

Also, this public bool holding, nearFurnace =false; isn't doing what you think it is

steel stirrup
#

false is the default value of a bool, so the assignment is pointless (though totally fine) but when you do it this way it's ONLY assigning nearFurnace to false, not holding. holding is only false because that's the default value, not because you're assigning it

steel stirrup
#

if you want both to be false then you should either not declare anything or (if you want to visualize it) do public bool IsHolding = false, IsNearFurnace = false;

next bolt
steel stirrup
#

Try doing it with true and you'll see what I mean

#

the bool will be false even if you don't include = false

#

because all bools are false unless set otherwise

#

bool isHolding = false; is exactly the same as bool isHolding;

#

The way you have them set up atm, you also can't trust them to actually be false

next bolt
#

oh so putting it as set to false is pointless and accoplishes the same thing if i did set them to false in seperate lines. ok thank you

steel stirrup
#

Since they're public, their actual value will depend on what you set in the editor

next bolt
#

which is false i see

steel stirrup
#

if you need these to be false, you should either be setting them as private/protected, setting a DoNotSerialize attribute or using a property

#

For example, let's say today you edit the prefab this script is used on and tick the bool as 'true' in the inspector. When you go to debug later, you're going to probably just look at the script and see that it's set 'false', not realizing that in actual gameplay it's going to be true.

next bolt
#

noted. Thank you

steel stirrup
#

In general, everything should be private unless it needs to be accessed from another class or inherited

#

it'll save you a ton of time later

#

You can make your update much less stressful to manage as well by using a coroutine

mint lodge
#

Hey guys

#

I have this Camera and the Boxes you see are the borders of my level.
I can't scale the camera to display the entire level for some reason, it becomes larger. Do you guys know a way?

mint lodge
#

I have a Following Camera script but I would also like a Fixed Camera

raw token
#

Have you tried modifying the camera's "Size" field in the inspector/.orthographicSize in script?

#

(assuming you're using an orthographic camera, that is)

thorny basalt
mint lodge
thorny basalt
#

Like scale?

mint lodge
#

No

#

ortho size

mint lodge
thorny basalt
#

Ah.

mint lodge
# thorny basalt Ah.

Anyway, I think I'll go with the following camera. May I ask your opinion on something?

final trellis
#

is there a https://docs.unity3d.com/ScriptReference/Texture2D.SetPixels.html equivalent for 2d float arrays? trying apply a 2d float array of numbers 0.0f to 1.0f to a Texture2D

thorny basalt
radiant frigate
#

is there a more optimized way of doing bullets "hit you" than Collider? because im doing a bullet hell and there are a lot of bullets, dont know if the game will be able to render it

steel stirrup
thorny basalt
radiant frigate
#

so i should use .translate or something like that?

steel stirrup
#

They’re fine, don’t over complicate it

#

Use an object pool for instantiation

#

And set all the bullets in a layer that ignores itself

radiant frigate
#

what is an object pool?

shell herald
#

im a bit confused by this. this always returns true even if i dont have any of the required materials exept 1.

summer stump
steel stirrup
summer stump
steel stirrup
#

Instantiation is incredibly expensive relative to nearly anything else

thorny basalt
raw token
steel stirrup
#

You can use OnEnable and OnDisable to handle state if you want to be quick about it, otherwise you should set up a generic object pool class + an interface for poolables so you can recycle it throughout your projects going forward

mint lodge
#

Which one looks better? A Fixed Camera like this? Or a zoomed in Following Camera like this? Your feedback is greatly appreciated 🙏

radiant frigate
summer stump
rocky canyon
raw token
radiant frigate
#

i want to make a very simple bullet hell

mint lodge
steel stirrup
#

Just think through the problem and take a stab at coding out a simple solution. it's not terribly complicated if you break it down piece by piece

radiant frigate
raw token
steel stirrup
#

you're going to have a collection of disabled gameobjects. Other classes can request an object, in which case you enable and return one if one is in your collection or you create a new one and return it. Other classes can also return an object to you, in which case you disable it and store it.

steel stirrup
steel stirrup
radiant frigate
#

which i know are like nothing

#

but it seems to much to my eyes

#

lmao

steel stirrup
#

You have to get over it.

#

Overoptimization causes more problems than it solves

#

it's better to get something down and working, then iterate on it

summer stump
#

Don't worry about optimizing

steel stirrup
#

Obviously don't throw caution to the wind and do something absurd, but don't get action paralysis from worrying about a few nanoseconds here and there

summer stump
rocky canyon
#

i use tonnes

summer stump
radiant frigate
summer stump
# radiant frigate i know, thats the sad part

Well, get over it then. Easy as that. You need things like that. Optimizing always should come last
Some simple things, sure, consider at first, but as we said, raycasts are basically free, so limiting them is NOT EVEN optimizing

steel stirrup
#

Something you really need to ingrain is that there is no virtue in having hyperoptimized code if you don't have an actual product to show for it

radiant frigate
#

i want to learn that

steel stirrup
#

But no, you could easily get by that without

final trellis
#

how do i make this function run whenever the values of a specific AnimationCurve or an int changes
plan is to get this to run in the editor btw

thorny basalt
#

Do you need physics in your game? I mistake I see from beginners is them using Unity’s physics engine when making a game that doesn’t need it

radiant frigate
summer stump
steel stirrup
radiant frigate
steel stirrup
#

Yes

#

it's literally just doing all your instantiation in one go instead of spreading it out

radiant frigate
#

so i could learn it in under 10 min ?

steel stirrup
#

yes

radiant frigate
#

oh

summer stump
radiant frigate
#

i didnt know about object pool before hyunahri told me about it

thorny basalt
summer stump
rocky canyon
#

can u learn it in under 10 min? probably not.. can u understand it w/in 10 min sure..

radiant frigate
#

nope i didnt

#

on my way

thorny basalt
rocky canyon
#

u were suggested using unity's builtin pooling stuff.. u should look into that

#

or u could go completely custom if u wanted

steel stirrup
#

Oh just a headsup, a lot of versions are probably going to use delegates if you aren't familiar with those. If you don't want to learn that now, just use OnEnable and OnDisable and enable or disable objects when they enter/leave the pool

thorny basalt
#

Unity had there own api for running things in the inspector but that is a whole can of worms

radiant frigate
#

oh

#

it was indeed that simple

radiant frigate
#

maybe its the same tho

#

what is an ObjectPool type?

rocky canyon
#

a class

radiant frigate
#

so im basically making a reference to the class itself?

rocky canyon
#

ObjectPool is anything u want it to be

radiant frigate
#

oh true

rocky canyon
#

then theres a static instance of it called instance

radiant frigate
#

its like if i do: private MovementScript movementScript;

#

right?

#

like obviously not the same

rocky canyon
#

more like if u did ```cs
public class MovementScript : Monobehaviour{

}```

radiant frigate
#

so the static ObjectPool creates a class instead of a reference?

steel stirrup
#

If you design it this way, you’ll only be able to have 1 pool because any new instance will wipe out the static reference to the last

radiant frigate
steel stirrup
#

Instead use a static dictionary of instances with the key as the gameobject name

rocky canyon
#

ur only pooling bullets right?

teal viper
radiant frigate
#

no im also spawning waves that are randomly generated

radiant frigate
rocky canyon
radiant frigate
#

lol the image

#

kewk

radiant frigate
#

programmer humour at its finest

steel stirrup
#

And static methods for getting the needed pool or creating it if it’s not yet created

rocky canyon
#

basically it'd be a static instance or Instance that u could call

#

to get ur particles /gameobjects when not being used

#

rcycled

radiant frigate
#

poolManager is the object, instance is the class and despawnEnemy is the method?

steel stirrup
#

PoolManager is the class, Instance is an object of PoolManager and DespawnEnemy is a method of the instance

rocky canyon
#

like this example u had earlier

#

ObjectPool.instance.Function();

radiant frigate
#

so the first one is the class, the second is the gameobject and the 3rd is a method

#

but what i dont get is what does method of the instance mean

rocky canyon
#

thats how Singletons work too

#

myGameManager.instance.LoadGameWithData(data);

radiant frigate
#

i do not know what singletons are srry

rocky canyon
#

no worries, a different thing, different use-case.. same underlying principle

teal viper
radiant frigate
#

so it basically creates a new instance of the class each time?

teal viper
#

I feel like you need to go over some C# basics. Specifically, the Type system and the difference between types and instances/objects.

fading mountain
#

Hey guys. I am trying to play a crossfade animation when a new scene is loaded. I have a button that will wait a certain amount of time before loading a new scene, say 5 seconds. I also have an animation which is 3 seconds long. When the button is pressed, my game manager script should wait 2 seconds before starting the animation, and then continue to wait another 3 seconds before loading the next scene. I've tried to do this in code with two different Coroutines, the effect that I'm getting though is that the animation is not playing until after the scene has loaded. In other words its waiting 5 seconds. Here is my script as well as the crossfade animator controller:
https://gdl.space/oxofadakug.cs

radiant frigate
teal viper
steel stirrup
radiant frigate
#

but as i said im currently in a bit of a rush, and even if i know that this is not the optimal way to procceed( which i know isnt) i would love to finish this game since everything left is the colliders/triggers and the ui

radiant frigate
rocky canyon
#

then go for it.. but if u run into any performance stuff u wanna change you'll know where to look

steel stirrup
#

the static vs instance is the point

radiant frigate
#

i do not understand that code

#

ty for the code but my current level is like nearly non existent

steel stirrup
#

Nothing external ever interacts with object pool instances, instead object pool instances only register themselves and handle actually creating and handing off their objects. Everything flows through the static methods, allowing for easy debugging

radiant frigate
#

what is string doing here= static GameObject getObject(String objectName)

steel stirrup
radiant frigate
#

we use the name of the object to check in which pool it is?

steel stirrup
#

Dictionaries map the first type to the second type, so in this case string -> pool

teal viper
steel stirrup
#

so when we put in a string, it gives us a pool (hopefully)

#

If you changed string everywhere to just be GameObject you could instead pass the prefab itself, or if you wanted to use hashes or enums or whatever, it wouldn't matter as long as its 1 to 1

radiant frigate
#

i also need to learn Dictionaries

steel stirrup
#

practically name is probably the worst possible way to do this lol, but I figured it would be more legible that way

radiant frigate
#

god damn im a newbie to this lol

fading mountain
steel stirrup
radiant frigate
#

unique pairs?

teal viper
steel stirrup
#

In a dictionary, all keys are unique. Every key must map to one and only one value

#

ie, if a key "name" maps to "bob", it cannot possibly also map to "john"

#

however two keys can map to the same value. ie "age" and "wealth" can both be 50

radiant frigate
#

im getting a bit confused over all these new things that i dont understand completely

steel stirrup
#

The main advantage is that a dictionary is a good collection when you want to be ablet o access specific things very quickly, rather than iterate over an entire list

radiant frigate
#

with the object pooling, the type of classes,dictionaries, etc, my mind is becoming a rollercoaster

#

im a bit slow if i may say it

#

so its a bit hard

radiant frigate
steel stirrup
#

tl;dr version. I have a lot of stuff and I want to act on all of it -> list. I have a lot of stuff, and I want to access specific ones individually -> Dictinoary

steel stirrup
teal viper
steel stirrup
#

just know that it's fast and it stays fast even at very large sizes

radiant frigate
#

is it bad if i: do it as i know, and once my friends an i finish this mini game jam, learn it the correct way?

steel stirrup
#

Take half an hour and just read up on the basic collections in C#, it will make EVERYTHING easier going forward

#

tons of issues can be completely sidestepped by using the right collection type

radiant frigate
#

okay im going to take a look into that

steel stirrup
#

Like you don't need to dig into big o notation and 'why' they work the way they work, just know which one to pull out in a pinch

teal viper
radiant frigate
#

okay let me rephrase then

#

could it still be "not
harmful" if i do it that way

steel stirrup
#

In general, I'd say look at List<T>, HashSet<T> and Dictionary<TKey,TVal>. Later on you'll want to also learn Queue, Stack and LinkedList, but those can wait

teal viper
#

Wdym by "harmful"? Is it gonna explode someone's head if they play a game with bad code? Probably not.

radiant frigate
#

no

teal viper
#

Are they gonna experience lag/ performance issues? Maybe. It depends

#

Are you gonna experience issues with extending on the project? Probably yes. Is it bad? It's up to you to decide.

steel stirrup
#

Go and read up, then try to implement one collection of each type into your project and come back here to review

#

you'll learn alot more that way rather than overthinking it

radiant frigate
#

i really dont have the time for that at this precise moment

teal viper
#

Then I really don't get what that conversation is about

steel stirrup
#

you've spent more time talking here than it would take to learn any of these things

teal viper
#

If you don't have time to learn, do it the way you know.

steel stirrup
#

It's like a bike, once you get it going a few times it'll become second nature

radiant frigate
steel stirrup
#

Learning to use your tools saves you time, usually even in the relatively short term

#

the classic example being new programmers accidentally creating a bunch of duplicates in a list fo what are supposed to be unique objects

radiant frigate
steel stirrup
teal viper
radiant frigate
#

neither the <T>. what does t even mean?

radiant frigate
#

i feel like im acting childish for some reason

steel stirrup
steel stirrup
radiant frigate
#

but im just currently under a lot of preasure because of time and circumstances (which is also sort of an excuse)

steel stirrup
#

It's okay to have questions, but you need to actively help yourself instead of making excuses. Learning sucked for all of us

teal viper
#

It's so annoying to see people say here "I just suck at coding/learning". Then freaking learn. There's no easy way. Everyone went through that. Don't deny their effort.

fading mountain
steel stirrup
#

It's a game, you're not going to sell it. No one outside of your friendgroup (and most in it) will not care about it at all after about 5 minutes. Learning to do things properly will let you create things that you're proud of and make the entire process easier. The better your foundation the easier it is to build on it

radiant frigate
#

okay

#

fresh start

#

what should my plan be now

teal viper
steel stirrup
#

I think you know List already, but just lookup hashset, if you want to skip dictionary for now that's fine

radiant frigate
#

yes i think i do

#

list is an array that can get its lenght modified

#

right?

steel stirrup
#

at a super simple level, hashset is just a collection where every item is unique

#

ie if you use a list and add 0 twice, you now have a list with two zeros in it

teal viper
# radiant frigate what should my plan be now

I say: if you're in the middle of a game jam and have to submit it soon, do it first. Even if it's weird and has bad code, it's fine. It's a valuable experience as well. After done with that, go through proper learning though.

radiant frigate
steel stirrup
#

if you do the same with a hashet, it has one zero no matter how many times you try to add more

steel stirrup
#

for example

radiant frigate
#

ive seen people write that a lot of times

#

oh

teal viper
#

I think lists and hashsets are the last of their issues. There are many more basic things that they need to learn first

summer stump
radiant frigate
#

i did not understand it

#

i think i need to correctly learn what types are

steel stirrup
#

You’re already using them, dw about it

#

You’ll get to it later, it’s a weird concept

radiant frigate
#

for what i know its: bool, int, float, etc etc etc

summer stump
radiant frigate
#

gameobject, and so on

summer stump
#

Every class, struct, and enum are all types

radiant frigate
#

i want to learn about class types( i dont know if its called like that)

summer stump
#

public class Enemy : MonoBehaviour

Enemy is a type

radiant frigate
#

but i mean: what is monobehaviour, abstract

#

etc

steel stirrup
#

Monobehavior is just a class

summer stump
steel stirrup
#

It’s already defined in Unity, you’re just inheriting from it, it’s not part of c#

radiant frigate
#

what am i inheriting from it?

summer stump
#

MonoBehaviour inherits from Behaviour, which inherits from Unity.Object I think

summer stump
#

Like .gameObject, .transform, .tag, etc

steel stirrup
radiant frigate
radiant frigate
teal viper
radiant frigate
#

i dont like to use int for example, i like to know what an int means and then use it

summer stump
radiant frigate
#

makes sense

teal viper
summer stump
teal viper
#

I mean, practice is important of course. But you can't grasp the whole thing without the theory

radiant frigate
summer stump
radiant frigate
# teal viper All of that is covered in the documentation. It depends on some other knowledge ...

i think you were the one that said to follow this path to me variables

data types

conditional statements

switch statements

collections (arrays, linked-lists, lists)

loops(for, while, do)

functions/methods

references

scope(global, local, parameter)

LINQ

sorting algorithms

inheritance

composition

classes

abstract classes

interfaces

polymorphism

SOLID

namespaces

events

exception handling

Debugging

break points

algebra

calculus

basic trigonometry

teal viper
#

I think we're all confusing them. Speaking about concepts that are too early for them...

summer stump
radiant frigate
#

oh

teal viper
radiant frigate
# summer stump Not sure what you are asking here. It is binary

i thought that you meant that when i declare an int( and dont assign any value) its value is "that amount of zeros" and not one 0, and the way int works is it changes the zero needed(or other number if already changed) to the number that we want, therefore having a limit of "that amount of zeros", but instead of a zero a 9

summer stump
steel stirrup
summer stump
#

It is a 32 bit value

radiant frigate
#

yes i didnt think about it being bits

teal viper
radiant frigate
#

before anything,

#

will it have a big performance issue if i use( lets say 3000) rigidbodys and colliders?

summer stump
#

Yeah sorry. You just said you don't know what an int is. I just wanted to point out that it is extremely simply just 32 0's until you assign a number

radiant frigate
#

i know what an int is

radiant frigate
#

a whole number

steel stirrup
#

Try and find out

radiant frigate
#

i think

#

i hope it is

teal viper
steel stirrup
#

How you use them is going to matter a lot more than the actual amount

radiant frigate
#

well they will be flying across the screen

steel stirrup
#

Yes, and how you decide where they fly and spawn is going to probably be the important part

radiant frigate
#

how would that perform?

steel stirrup
#

You have the answer already

#

No one knows

#

Go make it

radiant frigate
#

on my way

#

ill report how it went

steel stirrup
#

How it would perform if I coded it is very different than if you do or anyone else, we all have different approaches and different system specs

#

I will guarantee you don’t need 3000 bullets though lol

#

Even tohou and the like doesn’t hit anywhere near that

dusty ember
#
        if (Input.GetKey(KeyCode.LeftShift))
        {
            shiftHeld = true;
            Debug.Log("ShiftDown");
            if (shiftHeld == true)
            {
                if (speedAcceleration < 15)
                {
                    speedAcceleration += 0.01f;
                }
                else if ((speedAcceleration > 15))
                {
                    //nothing lol
                }
            }

          if (Input.GetKeyUp(KeyCode.LeftShift))
          {
                shiftHeld = false;
                Debug.Log("ShiftUp");
                if (shiftHeld == false)
                {
                    if (speedAcceleration > 1)
                    {
                        speedAcceleration -= 0.1f;
                    }
                    else if (speedAcceleration < 1)
                    {
                        //nothing lol
                    }
                }


            }```

So basically when I hold left shift DOWN it will send the message and increase acceleration
but when i put it up it doesnt send a debug message and doesnt accelerate
steel stirrup
radiant frigate
steel stirrup
radiant frigate
#

okay

summer stump
radiant frigate
dusty ember
#

OH

steel stirrup
radiant frigate
#

at what point

#

at 3000?

#

or at the ones i have?

steel stirrup
#

Why do you think you need 3000

radiant frigate
#

i do not think i need 3000

#

im just using that number as an example

steel stirrup
#

Then just go make the system, don’t use hypotheticals unless they relate to your actual requirements. This is just over optimizing lol

#

If you need a car to go 60mph, plan to make that car, not a Ferrari

radiant frigate
#

i need to ignore my thoughts about it

steel stirrup
#

Then just solve it

radiant frigate
#

i overcomplicate systems that could be solved so much easier but i try to use weird equations

radiant frigate
gaunt cypress
#

Made some progress on making the character walk/run using an animator, but I am still having an issue.
I don't know why, but when I try to run forward, it executes the Walk animation, even though the speed and position matches the criteria to execute the run animation. There are other animations that are not executing as intended, even when the numbers are matching in the inspector. Any ideas? Thank you very much!

native hill
#

for some reason the gliding isnt working correctly, it doesnt stop gliding and the jumps dont reset im pretty sure ```using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Jumping : MonoBehaviour
{
private Rigidbody rb;
// to count down to five seconds
private float TimePassed = 0;
private bool CanJump = true;
private float JumpsRemaining = 2;
private float JumpCooldown = 5;
private bool Gliding = false;

void Start()
{
    rb = GetComponent<Rigidbody>();
}

void Update()
{       // jumping
    if (Input.GetKeyDown(KeyCode.Space) && CanJump)
    {
        Jump();
        JumpsRemaining -= 1;


        Debug.Log(JumpsRemaining);
        Gliding = false;


        if (JumpsRemaining <= 0)
        {
            CanJump = false;
            Gliding = true;
            Debug.Log("hello");
        }
    }

    // making the cooldown
    if (!CanJump)
    {  
        TimePassed += Time.deltaTime;

        if (TimePassed >= JumpCooldown)
        {
            CanJump = true;
            JumpsRemaining = 2;
            TimePassed = 0;
        }
    }
    // starts gliding 
    if(Input.GetKey(KeyCode.Space) && Gliding == true){
        rb.AddForce(Vector3.up * 10, ForceMode.Force);
        Debug.Log("Im gliding");
        

    }
}

void Jump()
{
    rb.AddForce(Vector3.up * 5f, ForceMode.Impulse);
}

}```

somber herald
#

Hiya! I'm making a character controller where the character is looking towards the golden vector, and I have the vector of movement working in the normal directions, but I want it to be relative to where the character is facing, how do I do this?

#

For example the green line would be like me pressing A and W but the character isn't facing that way.

#

My question is how to make it work based on where the character is facing

raw token
raw token
raw token
native hill
#

alright, thank you I appreciate you a lot

somber herald
#

took a while to understand transform.TransformDirection

raw token
somber herald
#

omg got it working you saved me so much time ty

#

no dw at times like these its better to learn to research yourself

loud mango
#

is there any better way to use


 if(!Mathf.Approximately(movementJoystick.Direction.x, 0)){
            animControl.SetBool("isMoving", true);
            animControl.SetBool("isFlying", true);
        } ```

to write 

``` if direction.x is approx. 0 and direction.y is not approx. 0 then do #code ``` so its not spaghetti
slate haven
#

im making a unity 3D game, My Character player looks in direction of cursor/mouse. It also has a gun in his right hand. So the problem is when the gun shoots, it doesnt shoot in the direction of the cursor because cursor is making the player look on it. I want such that the cursor gets binded to my gun's direction

    {
        mousePos = Mouse.current.position.ReadValue();
        Ray ray = mainCam.ScreenPointToRay(mousePos);

        if (Physics.Raycast(ray, out RaycastHit hitInfo))
            {

            Vector3 targetPoint = hitInfo.point;
           Vector3 direction = (targetPoint - player.position).normalized;
           
            
            direction.y = 0f;
          

            if(direction != Vector3.zero && direction.magnitude > minDistance)
            {
                Quaternion targetRotation = Quaternion.LookRotation(direction);
               
                
                
                player.rotation = Quaternion.Slerp(player.rotation, targetRotation, Time.deltaTime * 10f);

               Cursor.position = Input.mousePosition;
            }
           
        }
    }
cosmic dagger
fringe plover
modest dust
#

And is Inventory a MonoBehaviour?

#

Or anything deriving from Object

fringe plover
#

Its class

#

its in other class which is monoBeh

cosmic dagger
modest dust
#

Instantiate is a static method defined in the Object class, if you don't derive from it you have to call it like you do there.

fringe plover
#

the thing is, IDE says that i can call it without MonoBehaviour.

#

nvm, it says that its better to call it with Object.

void thicket
#

UnityEngine.Object.Instantiate doesn't look so good tho

topaz mortar
#

So I have a working combat script but now I want to add spells to my combat.
Each spell has a unique effect.
When a spell is cast in combat, how do I find and execute it's effect?
My game will have 50-100+ spells, do I just huge a giant switch statement?

#

I guess I could also make a new class for each spell that extends Spell and just call Spell.Cast or something
But that seems like a ton of work, might be more future proof though?

teal viper
# topaz mortar So I have a working combat script but now I want to add spells to my combat. Eac...

There are many ways to organize it.
One way is composition. Have a set of minimal components of a spell and combine them in a sequence or graph. You could have several types of components, like a base(projectile/touch/ares), effect(damage, heal, whatever), modifiers(repeat over time, condition, etc).
Then creating new spells would be just a matter of combining all these components into a spell instance and only write new components if you really need something new that the existing components don't allow you to do).

topaz mortar
copper orbit
#

i have a script that loops and instantiates an Enemy gameobject instance. What would be the best way to keep track of enemy1, enemy2 and so forth? Aren't they all Enemy(Clone)?

cosmic dagger
copper orbit
#

if I place into a list or an array, wouldnt it be just Enemy(Clone) for all of the enemies

cosmic dagger
#

that is just the name of the instantiated GameObject. when instantiated in the scene, the GameObject will add " (Clone)" to their name . . .

copper orbit
#

what would be the best way to differentiate if not, name?

willow scroll
willow scroll
cosmic dagger
copper orbit
#

i think it could be as simple as what sashok said

#

i guess i would just make the list or the array public so other class can see it.

fringe plover
#

Guys i need help...
I did inventory system for items, and make them dropable and etc, but not i have no idea how to make items usable, they are currently ScriptableObject's with prefabs.
I want to make different prefab with script that will instantiate when player use item, is it good idea or there is any other way? i just dont have any other ideas.

#

or i could add method to interface and use same prefab and script, and just call different method in it

muted narwhal
fringe plover
#

I will have to make different SO for every item type?

muted narwhal
fringe plover
#

maybe ill stick to using prefab with interface..?

#

I dont think its good idea to have script to do smth.. isnt its same as spawning prefab?

muted narwhal
fringe plover
#

I dont understand what public MonoBehaviour itemUseScript will do, what its even for? am i creating object with this script or what?

muted narwhal
#

You assigning script to add item use logic.

fringe plover
#

Hmm.. It means there is no diff with just having an Interface and script that will handle dropping object, using it and etc?

muted narwhal
#

I'm not sure, I'm not that one ultra-smart game dev, that's just my implementation :clueless:

modest dust
muted narwhal
#

You can test every way of implementing this and choose the best way for you

fringe plover
#

Okay, ill try.
Anyway, thanks for helping 👍

modest dust
#

And how do you want to use an item

#

From inventory-level? While holding it?

fringe plover
fringe plover
languid spire
#

It does sound to me that an Interface (IUsable) is a better option here

fringe plover
modest dust
languid spire
#

you can have more than one on an object

fringe plover
fringe plover
languid spire
#

so
public class Potion : IItem, IUsable, IDrinkable
public class Cake : IItem, IUsable, IEatable
etc, etc

modest dust
fringe plover
#

Im also going to add weapons... i want to make separate inventory for them, like, there is gonna be a lot of guns and i want them to be stored separatly and not as items

muted narwhal
#

How can I fix this? I have a vertical layout group, it works with messages that >1 line, but if it's more than 1 line... I'm getting this.

languid spire
#

not a good plan, a Weapon IS an Item

fringe plover
#

Yeah, but its gonna be equipable in hands and player wont be able to use them like items

languid spire
fringe plover
muted narwhal
#

Oh, I have CSF on content-

#

lemme try

fringe plover
languid spire
muted narwhal
fringe plover
muted narwhal
#

Oh, wait-

#

It works

#

I just need a little bit more characters

#

Alright, it's works... but not

fringe plover
muted narwhal
#

What "minimum"?

fringe plover
muted narwhal
#

It made it better, but didn't fixed it

fringe plover
#

I have no idea, does other/small message size fit text or not?

muted narwhal
fringe plover
#

Never did thing like this before

boreal root
#

why am i getting NA in the place of high score

languid spire
#

Because that is what your code is doing

opaque ibex
#

Hi guys

#

Can I ask something?

#

I have this model I made in blender and it comes with armature (bones) and I imported it to unity. After that I created a script that has addforce but somehow the model is not affected. I already added mesh collider(convex), rigidbody, and navmesh. Meanwhile Imported the model again but without the armatures and the addforce work on it. What might be the cause of it?

boreal root
#

what

boreal root
languid spire
boreal root
#

I want to display the high score of the player in the place of N/A

languid spire
#

I know what you want, I asked how can anyone help you using the information you have supplied

#

!code

eternal falconBOT
boreal root
#

could you say what kind of information you need

#

the lowest time taken by a player to complete the particular level should be the high score

languid spire
#

#854851968446365696 tells you how to ask questions.
The first thing I see is you have made no attempt to debug this code. Do you even know if it is running?

boreal root
#

ok

#

Yeah it is running if i click on the button it is redirecting

fierce geode
#

Is there an alternative to the static keyword that still allows to be edited in the inspector but has the same effect of having the static variable be the same across every version of the script?

wintry quarry
languid spire
# boreal root ok

This
if (time == float.MaxValue) return "N/A"; // Handle uninitialized time
is obviously where the N/A is coming from. So debug time

fierce geode
#

heard of singletons before. same with factory's. Some kind of software design patterns

boreal root
#

Ok thank you but how to do that

languid spire
boreal root
#

yeah ok

fierce geode
# wintry quarry No. But sounds like you want a Singleton basically.

Yeah, I'm using a script to keep track of all the items in the game. Currently I just have two lists, one being a static and one being not static and exposed to the inspector. and in the start the static list just becomes a copy of the non-static list. Which is prob a bad practice.

languid spire
fierce geode
#

hope you have a nice day

raw robin
#

Hi all, Im using a few prefabs with just a sprite renderer and initiating them as "splatter" once a character jumped. It looks good, but can't help but notice the overall large amount of gameobjects sitting in the Hierarchy and wondering if it could potentially cause lag. Is there a better way to go about it?

languid spire
raw robin
languid spire
#

you are correct on your assesment of object pooling.
No, there is no way to have a gameobject without a gameobject.
You can mitigate the runtime impact of a gameobject by making it static, not sure if that applies to your use case

steel stirrup
#

you can have thousands of gameobjects without any significant performance cost if most of them are disabled at any given point

steel stirrup
fierce geode
steel stirrup
#

Why is that being exposed inthe inspector?

#

It should be generated at runtime

fierce geode
#

at the current point, my items are scriptable objects. So I need to assign them somehow into the database.

steel stirrup
#

Dump them all in a directory in Resources and Resources.LoadAll<your object type>

#

Although in general I'd also strongly caution against using scriptable objects that way, it's personal preference I'd suppose

fierce geode
#

Why would you caution against it?

steel stirrup
#

SOs are, imo, a noob trap and kind of crap

#

They provide absolutely no benefit, are very easy to lose data with if you change the class, overcomplicate editing the data of individual instances and make it impossible to separate your data from your game

languid spire
steel stirrup
#

What does using a scriptable object provide that you wouldn't get more easily by simply using a CSV file?

steel stirrup
languid spire
steel stirrup
#

That way non-programmers can also work on your data without needing the entire project, and it's easy to add modding support later'

#

If you need references to individual objects rather than the just the type itself then something has gone horribly wrong with the design

languid spire
#

if you need string format data something has gone wrong with your design

steel stirrup
#

That doesn't even make sense but go off

#

External data files allow you to have multiple contributors who don't need unity, easily share data files and edit together using any collaboration tool and with appropriate parsing logic can handle essentially any datatype. It also means that if you update Unity or have bad luck with the editor or need to rewrite your data structures you don't need to worry about references or data actually being lost.

languid spire
#

rofl, there is no way I would ever allow anyone to edit raw data if I want to guarantee data integrity

steel stirrup
#

You're completely missing the point

#

If you don't trust your team members, then you probably shouldn't have any

#

This is a lot easier to understand at a glance and balance/edit than having 14 separate scriptable objects sitting around a folder in unity

#

All you would do to make references in Unity is store these into a static dictionary when loaded and use a key that you can write in the inspector, I usually prefer strings but anything would work.

languid spire
#

man, it takes an hour or so to write a custom editor AND you then have data validation to boot

steel stirrup
#

Data validation just goes into the map class or your factory. I'm not sure what you mean by a custom editor

#

Pretty much any modern IDE already supports all markdown formats by default

#

and the actual IO is handled by CSVHelper or Json.NET or whatever you prefer

#

Scriptable Objects are great if you have a singleton and don't want to just use a static class for whatever reason, but using them for classes where there are many instances (like items in most games) almost guarantees that your project will grow massively in complexity as data is added, which is always something to avoid

#

Another trap ofc is people using them as 'item' and not 'item blueprint' lol

#

but that's just a structural thing

fierce geode
#

off-topic question here. Is it possible to initialize the length of the arrays inside a jagged array
like "private int[][] levels = new int[30][8];"
making it so that there's 30 arrays that have 8 elements in it?

languid spire
fierce geode
#

oh my bad, I just thought jagged array meant an array with arrays inside it

#

this is what I get for coding at midnight, pretty sure I'm looking for a 2D array.

languid spire
#

indeed

half egret
# steel stirrup This is a lot easier to understand at a glance and balance/edit than having 14 s...

We did something similar for the aurora engine. All strings and game-class data were stored in binary formats which were difficult for contributors to update/modify, so we converted it to JSON. Then when they submit the edited JSONs, our build pipeline validates the entries and if something is off we tell them "You made an oopsie".

To be fair though, it was kind of necessary because of how old the engine was. But I do see the use-case for this kind of design

languid spire
#

but then you are using a data pre processor which is absolutely essencial because string format data is extremely easy to bork

half egret
#

Yeah, it has actually caused some major crashes because our pre-processor missed some problems early on in development

languid spire
#

does not surprise me

half egret
#

Very difficult to consider ALL the possibilities strings can bork, it will undoubtedly fuck up somewhere

languid spire
#

yep, which is why I would NEVER do it

half egret
#

We were in a corner and the alternative was an extremely high barrier to entry for writers on an engine that was extremely unintuitive to setup for our dev environment, so it was a necessary evil.

steel stirrup
#

Meh, it's pretty straightforward to check if the incoming string parses to the correct type, particularly if you standardize your formats so you can disregard capitalization and trim all extra whitespace

languid spire
#

It is so simple to knock up a GUI based custom editor, I cannot see why you would not do so

steel stirrup
#

Because spreadsheets have been perfected over the past couple decades, so why reinvent the wheel

#

By all means, ship a custom editor with the project for endusers, that's a great idea

#

I'd definitely do that over having them go at the raw csv, but it's overkill for developer use and probably less efficient overall

languid spire
steel stirrup
#

in what world

#

And why would you use winforms anyway, just toss it at GPT4 and have it generate a webapp based on the CSV format, ime it pretty much nails it

languid spire
languid spire
steel stirrup
#

Are you twelve?

half egret
#

Using GPT to generate csvs is so much riskier and prone to errors than writing a straightforward generator

steel stirrup
#

Personally I'd toss it together by hand since it takes about 10-20 minutes depending on how complex we're talking, but it's an option for someone not familiar with any languages besides C# and it's very straightforward to edit whatever code it spits out to fix up the output since really we're just talking about a set of rules for each output type + an end result string

#

I don't really see the point in having an editor aside from your IDE at all aside from maybe as a modding tool, but ymmv

naive pawn
fierce geode
#

Hope you have a nice day

atomic holly
#

Hi,
I write this program because I want to call the function of this class from an another override function. I see we can't use directly Coroutine in an override function. Can I optimised it or I have the obligation to do like this ? (I call ThrowArrow() in the other override function)

public void ThrowArrow()
{
    StartCoroutine(DelayThrowArrow(2));
}

private IEnumerator DelayThrowArrow(float seconds)
{
    Debug.Log("Arrow throws");
    Vector3 position = SingletonManager.instance.playerObject.transform.position;
    position.x += offsetX;
    position.y += offsetY;
    //Create the arrow in front of the player gameobject
    //Quaternion.identity don't change the rotation of the object
    _ = Instantiate(arrowPrefab, position, Quaternion.identity);
    yield return new WaitForSeconds(seconds);
}
half egret
#

Why can't you use a coroutine in an override function?

atomic holly
#

When I write this, the IDE tell me that StartCoroutine doesn't exist in the current context

public class BowAttackBehavior : AttackBehavior
{
    public override void Attack()
    {
        StartCoroutine(BowSystem.instance.DelayThrowArrow(2));
    }
}
steel stirrup
#

Is AttackBehavior inheriting from monobehavior?

atomic holly
steel stirrup
atomic holly
steel stirrup
#

If you don't want to inherit from monobehavior, then instead you can create a singleton that you pass all your coroutines to

atomic holly
#

I thinked that Coroutine is from C# and not need to can interact with the engine

#

But now, I have this warning in Unity : ```
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all

#

Because I have this : ```c#
private void SetAttackBehavior()
{
switch (attackType)
{
case weaponAttack.Bow:
attackBehavior = new BowAttackBehavior();
break;
case weaponAttack.Sword:
attackBehavior = new SwordAttackBehavior();
break;
case weaponAttack.MagicBook:
attackBehavior = new MagicBookAttackBehavior();
break;
case weaponAttack.Sarbacane:
attackBehavior = new SarbacaneAttackBehavior();
break;
case weaponAttack.Axe:
attackBehavior = new AxeAttackBehavior();
break;
}
}

steel stirrup
#

Don't convert your class to a mono, just pass the coroutines to a singleton instead

half egret
#

Alternatively, are you sure you need coroutines? you could use async/await

steel stirrup
half egret
#

Gotta start somewhere 😝

#

At this point he's going to have to make a lot of changes to implement coroutines

half egret
#

when he could save a lot of time learning async/await and use that instead if it's just simple delay/waiting

steel stirrup
modest dust
half egret
modest dust
#

Being messy is one thing, that's a bad design fault

#

Making it work is another thing

paper sable
#

hey, i have a question about the input system. i was thinking that it wouldnt be very good to keep creating a new instance of the input class in each script i need to use it so i just made one instance in my GameManager class and referenced it from there in a script, but im getting a object reference not set to an instance of an object error when i press start. did i do anything wrong? is this thing that i did with the GameManager even a good thing?

lavish gate
paper sable
#

in my game manager class i have a static GameManager variable called instance which is assigned to the object itself in the start method, and the GameManager class is attached to an object in the scene. when im referencing the input class in my scripts im using GameManager.instance.input.

half egret
#

You should Initialize the singleton in awake not start

languid spire
half egret
#

And then you're likely referencing the singleton before it's been initialized

#

If you try to reference it in start/onwards when the singleton is initialized in awake, it should avoid those reference errors

lavish gate
#

i forgor about singletons, you guys are probably more equipped to answer his questions than i am

paper sable
#

ohhh alright, i assigned it in awake and now it works properly

#

thanks for the help guys

lavish gate
eternal falconBOT
lavish gate
#

Alright

languid spire
lavish gate
#

probably wiser to share my entire script instead

#

here we are

atomic yew
#

While I was testing my game yesterday, the fps started at 60 and dropped below. While testing my game today, my game, which normally starts at 60 fps, started with 2 fps. Thinking that the reason was due to the project, I opened my old projects and the same problem occurred there too. I wonder what's the problem? What causes this? If you look at the screenshot I sent, everything is on the ceiling in Profiler.

steel stirrup
#

check that you're not out of disk space

slate haven
#
    {
        if(other.gameObject.tag == "Elevation")
        {
            rb.AddForce(transform.up * 5f, ForceMode.Impulse);
        }

        if (other.gameObject.tag == "Attractable")
        {
            
            hitCount++;
            if (hitCount >= 3)
            {
                isAlive = false;      
                op.DeactivateGameObject(gameObject.tag, gameObject);
                hitCount = 0;
            }
        }
    }```

I have set this code such that if the object of tag "Attractable"  is thrown to the zombie and it collides with it, zombie gets killed. Also I dont destroy the attractable/throwable item as Player can reuse it.

The problem is if the throwable item is lying on ground as it is, and if zombie walks and collides with it then it gets killed automatically. Please help!
cinder crag
#

can someone help mew ith the new input system , how can i check if the mouse button is Up like canceled ? checking if im pressing works fine , its just the mouse button up idk how to check for that, tried to make bools _isLeft/RightMouseButtonCanceled and then turning it false and true in the respective methods so im not sure what to do

teal viper
modest dust
slate haven
modest dust
#

There are a few ways

slate haven
#

oh

cosmic dagger
modest dust
#
bool m_canDamage = true;

...
if (hit && m_canDamage)
{
  // Damage whatever you hit
  m_canDamage = false;
}```
slate haven
#

got it

shell herald
#

is there a good way to remap values? ideally with curves i can controll outside the script? i have a value that goes from -2.5 to 0 and for the ui i would need it to go to something like 2 to 1

shell herald
#

im currently on that page but i still havent quite figured out how to implement

languid spire
teal viper
topaz niche
#

Hello guys. Maybe someone can recommend tutorial on Youtube about doing inventory like in Minecraft?

shell herald
cinder crag
teal viper
shell herald
teal viper
shell herald
#

its a time value that fluctuates between -2.5 and 0

languid spire
topaz niche
teal viper
languid spire
cosmic dagger
#

Even so, they can evaluate the curve and pass in t . . .

pastel flume
#

making a system where the cinemachine camera shakes when the player starts running

right now it works by broadcasting an event when the player starts running and one when the player stops running to display the screenshake
but i'm struggling to get it working well with other features like jumping which i just added

wintry quarry
steel stirrup
pastel flume
pastel flume
steel stirrup
#

So, simplest solution, is there any reason why your camera shake (headbob?) can't just check if you're grounded or not?

pastel flume
#
public class CameraShake : MonoBehaviour
{
    [SerializeField]
    private CinemachineBasicMultiChannelPerlin perlin;
    private Coroutine _currentCoroutine;

    private void Awake() {
        perlin = GetComponent<CinemachineBasicMultiChannelPerlin>();
    }
    private void HandleSprintChanged(bool isSprinting) {
        if (_currentCoroutine != null) {
            StopCoroutine(_currentCoroutine);
        }
        float targetAmplitude = isSprinting ? runAmplitude : walkAmplitude;
        float targetFrequency = isSprinting ? runFrequency : walkFrequency;

        _currentCoroutine = StartCoroutine(LerpPerlinValues(targetAmplitude, targetFrequency));
    }
    
    private void HandleJumpChanged(bool isJumping) {
        if (_currentCoroutine != null) {
            StopCoroutine(_currentCoroutine);
        }
        float targetAmplitude = isJumping ? walkAmplitude : runAmplitude;
        float targetFrequency = isJumping ? walkFrequency : runFrequency;

        _currentCoroutine = StartCoroutine(LerpPerlinValues(targetAmplitude, targetFrequency));
    }
    private IEnumerator LerpPerlinValues(float targetAmplitude, float targetFrequency) {
        float startAmplitude = perlin.AmplitudeGain;
        float startFrequency = perlin.FrequencyGain;
        float elapsedTime = 0f;

        while (elapsedTime < transitionDuration) {
            perlin.AmplitudeGain = Mathf.Lerp(startAmplitude, targetAmplitude, elapsedTime / transitionDuration);
            perlin.FrequencyGain = Mathf.Lerp(startFrequency, targetFrequency, elapsedTime / transitionDuration);
            elapsedTime += Time.deltaTime;
            yield return null;
        }

        perlin.AmplitudeGain = targetAmplitude;
        perlin.FrequencyGain = targetFrequency;
    }
}
pastel flume
#

also how do i check for that
usually it's a raycast from the rigibody to the floor in an update frame but that sounds like a performance cost

steel stirrup
#

and you're going to need it for a lot of different things in all likelihood, so yes I'd make it public and if you want to cover all your bases just set it up as a property that shoots on an on change event

#

Also, totally up to your personal taste, but in general you don't use perlin noise for this, you use a sine curve to emulate how the head naturally moves

pastel flume
#

i'm currently just working with what cinemachine provided

#

the preset handheld shake noise

steel stirrup
#

Is there a specific reason you're using cinemachine? Or is it just a learning project

pastel flume
#

i'm new to unity

steel stirrup
#

Don't use cinemachine to start with

#

Learn to do things with the basic camera first, cinemachine is its own entire ecosystem

#

Nothing wrong with it, but you're basically diving straight into the deep end, and you really do not need it for a first person view

steel stirrup
#

Take a shot at figuring out how to do the grounded check and ask if you have any questions

pastel flume
pastel flume
steel stirrup
#

Use raycasts instead of collisions

#

Try to use a layermask too, check the docs if you haven't tried that before

steel stirrup
void thicket
# muted narwhal

You just need to turn on "control child size" on the parent for size fitter to work, and shouldn’t have size fitter on child

#

Anyhow this doesn’t look like code problem

topaz mortar
#

is Application.wantsToQuit a good way to save data to the server before the player exits the game?

void thicket
neat bay
#

does anybody know why this happens to my scene when baking lighting an dturning on "contribute to global illumination" on my GameObject?

#

for reference this is what it looks like without baked lighting