#💻┃code-beginner

1 messages · Page 388 of 1

swift crag
#

no, this is also very wrong

#

that's not an array of Vector3

polar acorn
#

You should probably look up how to make a list instead of guessing and waiting for us to tell you the guess is right

ivory bobcat
#

In C# the square brackets would be aligned with (next to) the type rather than the name.

remote osprey
#

@swift crag ?

swift crag
#

The individual components can subscribe and unsubscribe

#

But you can also have the input manager decide whether or not to call methods, yes

ivory bobcat
#

The usual choices are (assuming every object being polled needs to be polled):

  • individual polling: straight forward and easy to perceive what is happening/not-happening
  • events: subscription based, where you're able to flexibly change whether or not objects should continue to be polled.
    It's simply a design choice - you'd have to write (create) some sort of state base manager if you're wanting to later add removable polls as a feature.
#

It's a preference (other than doing more than simply polling)

torn vapor
#

i think ive run into a unity bug, i pressed the visibility icon on the object, but it doesnt get hidden, in fact no object gets hidden. Do you guys know how to fix this?

ivory bobcat
torn vapor
#

yuyp yup

#

its scene view

ivory bobcat
#

Maybe hit the toggle up top in the scene view

torn vapor
#

oh lol

#

didn't realise that was an option

#

well that was silly

strange prawn
#

Im having issues with unity/unity hub, I was working on something until I got an error saying " Assertion failed on expression: 'res == EAGAIN II !HasAbortingErrors()’ ”, I deleted unity hub & unity editor, deleted the unity file out of my finder, reinstalled unity 2019.4.31f1, the iOs support & android package & I opened unity hub, added the package back to my projects tried opening it to reimport it all, everything is gone when I open it & I closed unity, went back to unity hub & tried to fix the manifest.json but it didnt work, it keeps telling me that theres an error with the indepence named accessibility that's stopping all my imports from importing & im still getting an error that says: "Assertion failed on expression: 'res == EAGAIN II !HasAbortingErrors()'" how do I fix both of these?

teal viper
strange prawn
# teal viper You'll need to share some screenshots of the errors and more context on what's h...

this is my manifest.json code: {
"dependencies": {
"com.unity.ai.navigation": "2.0.0",
"com.unity.burst": "1.8.13",
"com.unity.collab-proxy": "2.3.1",
"com.unity.formats.fbx": "5.1.1",
"com.unity.ide.rider": "3.0.28",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.ide.vscode": "1.2.4",
"com.unity.mathematics": "1.3.1",
"com.unity.test-framework": "1.4.3",
"com.unity.timeline": "1.8.6",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.cloth": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.umbra": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
}
}

teal viper
#

You can share code-like text the same as !code

eternal falconBOT
teal viper
#

Also, I'm not sure what that manifest is supposed to explain?

strange prawn
#

this is what happened after i tried clicking continue & reimporting everything

teal viper
timid oriole
strange prawn
teal viper
strange prawn
teal viper
#

Move it to the disk root or somewhere nearby.

strange prawn
queen adder
#

is it acceptable to project scale make void Reset a [Conditional("UnityEditor")]?

teal viper
strange prawn
#

Im not sure where to find that..

wintry quarry
summer stump
subtle orbit
#

I need help where do I go from here

wintry quarry
subtle orbit
#

Make a game

#

I am new

summer stump
wintry quarry
subtle orbit
#

Ok

summer stump
#

You make or open the project, then... make the game

subtle orbit
summer stump
#

There is a lot to do after that of course, so it is hard to say anything specific

summer stump
wintry quarry
#

that was my first instruction

subtle orbit
wintry quarry
summer stump
#

To be clear, none of this is to be done on any website

summer stump
wintry quarry
#

well - downloading the hub is on a website

#

after that, no websites

summer stump
#

Ah yeah, thought they had it already. True true

subtle orbit
#

Ok done

wintry quarry
#

after you install the hub, open it

#

insstall the latest editor version

#

then click to create a project

strange prawn
#

It won't let me move it there...

#

Unless I put it under system or another folder.

wheat wave
wintry quarry
summer stump
summer stump
strange prawn
queen adder
#

is it just me, or there really isnt a docs for this attribute

slender nymph
#

it is undocumented

queen adder
#

hope it works tho, this code of mine is dependent on it :3

#

everything dependent on OnENable, and dont wanna make a mini coroutine/delayedcall pattern to call them

slender nymph
#

it does work, all it does is set a default order for the script execution order for that type

ruby ember
slender nymph
#

animate it?

slender nymph
#

slerp the rotation

ruby ember
slender nymph
#

you don't need to animate the rotation, that doesn't actually make much sense. just keep track of the target rotation and slerp to it

ruby ember
#

i know i don't need to animate the rotation

slender nymph
#

then why did you?

summer stump
#

slerp the rotation

ruby ember
# slender nymph then why did you?

look

the thing is that when i click a button but when you rotate a different direction it plays but it needs to rotate the pose as it needs to be as the animation

just watch the second video

slender nymph
#

what do you mean by that

ruby ember
#

watch the 2 videos

#

you might understand

slender nymph
#

i did. i still don't understand the issue you are experiencing because you refuse to actually describe what is happening in a way that makes any fucking sense

ruby ember
queen adder
#

is there a way to select a preset here via code?

#

do have to manual each?

slender nymph
ruby ember
slender nymph
#

you start by googling "unity slerp rotation"

ruby ember
#

bruh this is no help

#

fine

slender nymph
#

you are required to put effort into your issue or you won't get it fixed. i am not about to do the work for you

queen adder
#

can we do this wothout custom editor?

#

or hopefully an attributed string that I can use to any other script

summer stump
# ruby ember bruh this is no help

You were given direction. That is the kind of help you get here. If, after you put in effort and learn a bit, you can come back and show what you tried and we can guide you more from there.

Slerping is definitely the right choice for this. It was a good direction

slender nymph
summer stump
queen adder
#

just as long as there's a text that the user will laways see

#

probably clean as well (for presentation purposes)

verbal dome
#

Header attribute is the closest that comes to mind

queen adder
#

hmmm.. that is quite a little acceptable maybe

#

actually, I can try to make an asset of it

#

with a prop drawer

#

aight imma do that Ig

slender nymph
#

should be pretty trivial to create something like that using a decorator drawer

queen adder
#

oooh what's that

#

fiest time heard of

slender nymph
#

property drawer is for drawing properties, decorator drawer is similar it draws information or other decorations. the Header attribute is an example of one

queen adder
#

Im currently leaning to make it likecs public DisplayString xsd123 = "This is a tutorial covered by a box"; is that deco drawer better than prop drawer?

slender nymph
#

it's not "better", it accomplishes a similar, but different, function. and you wouldn't need extra data in your class, just an attribute attached to a field and the string can be passed to the attribute's ctor instead of being stored as part of the class

queen adder
#

hmm, imma go with prop on this one ig, it will be more versatile for the purpose(as it can be placed on classes that dont have fields), can turn it into a conditional compilation to not hurt runtime if that's just the drawback

#

thanksuu

slender nymph
#

can be placed on classes that dont have fields
how though because you have to create a field for it

queen adder
#

ah i get it

#

yea, but it doesnt directly require you to make something else UnityChanOops

slender nymph
#

then where is the display string coming from if not from "something else"

queen adder
#

prop vs decor?

slender nymph
#

also why would you have inspector documentation for something that doesn't have anything in its inspector anyway? that's what normal documentation is for

queen adder
#

basically a small text explaining what the thing can do :>

#

like notes thingy

#

ohhh can a class be decorated? Rather than fields?

#

if it can it would be like better

slender nymph
#

yes i understand what the point of the tutorial text you are trying to create is for. but why would it be on something that has nothing at all in its inspector?
if it has nothing in the inspector at all its documentation would preferably be with the rest of your actual documentation and not require someone to stumble across the component and add it to an object just to find out what it is

queen adder
#

just extra ways to tell peeps what things can do cause my naming skills is bad UnityChanOops

slender nymph
#

right so your actual documentation that you ship with the asset should contain that info

queen adder
#

is that enuff tho?

verbal dome
#

Your inspectors could have links to the doc

#

Like a small "?" Button

slender nymph
ivory bobcat
#

I wouldn't want to have to randomly add components to see what each component does.

queen adder
#

quite insecure my inspector is ugly, figured imma add just extra stuff to .... make it look a little detailed

ivory bobcat
#

A lookup document would suffice and be preferable.

slender nymph
verbal dome
#

Nice

queen adder
#

aight UnityChanWIP

slender nymph
# queen adder quite insecure my inspector is ugly, figured imma add just extra stuff to .... m...

this is not an example of the type of component i was referring to. this has stuff that needs to be configured in the inspector so having some text explaining it there would be helpful to supplement the documentation (but not replace it)
i was referring to a component that has no fields since your complaint about the decorator drawer was specifically the need to add a field to that class for that purpose, which i pointed out was what you were required to do for the property drawer anyway

final plover
#

is there any way to make a script update faster or something? Basically i have little smoke sprites that appear as "trail" behind the missile. At slow speeds it works nicely but at high speeds it barely shows and theres massive gaps. Any ideas?

slender nymph
#

Update runs every frame already. that's about as fast as updating a component will go. it seems like there may be some issue with whatever logic you use to do that

spare mountain
#

most likely

final plover
#

okay. I think i need to limit the linear velocity tbh. The missile controls feel fine until it gets going real fast. It doesnt feel like theres enough drag or resistance (i havent taken physics yet idk the term)

verbal dome
#

If you'd use the particle system then it would handle it for you, theres a 'Rate over distance' setting

final plover
timber tide
#

havent looked into the PS but the problem is you need some linear interpolation

#

vfx graph I do some of that as it'll leave gaps for those quicker projectiles

sage escarp
#

hi guys, i can't create a prefab variant of this prefab cause the option isnt in the menu.. i followed the docs... but i dunno why its not showing up

timber tide
#

drag it on the scene, rename it then drag it back into assets

chrome shadow
#

what does "static" in scripting mean?

eternal needle
queen adder
#

did unity provide a code for these presets? Manually writing them by code is grindy

strange prawn
queen adder
#

id call a foul on unity for this one

#

why not make an accessible codes/api for it when it is already written

#

it looks nice tho, thanks for these (and the author)

charred spoke
#

Like every piece of software Unity is no where near perfect. You can make a suggestion on the public roadmap.

#

This probably falls in the category of not worth supporting since people can bang it out in 20 mins for their own projects

dreamy relic
#

Hey,

I'm trying to implement moving my character using the CharacterController. I have the same code from https://docs.unity3d.com/ScriptReference/CharacterController.Move.html) and it works.

But now I want my character to be always facing in one direction (to the front), but when I click 'a' or 'd' to move it to the left o right, it start facing those directions. I'm a bit stuck on how to achieve this while using ´controller.move´

slender nymph
#

please see #854851968446365696 for what to include when asking for help. you haven't actually specified what part of that you are struggling with nor have you provided relevant code

woven holly
#

why when i add this line of code does it randomly start giving me the error: "'Random' is an ambiguous reference between 'UnityEngine.Random' and 'System.Random'"

#

also idk if im even doing that right i just looked it up

#

but when i remove that line of code my Random.range(x,x) works fine

slender nymph
cosmic dagger
charred spoke
#

‘’’if (move != Vector3.zero)
{
gameObject.transform.forward = move;
}’’’ this piece of code turns your character in the direction of movement

woven holly
#

oh my bad i see now

cosmic dagger
woven holly
#

So why does it give me the error only when i type that line of code? is it because I dont use one of the namespaces until i reference Convert or smth like that?

#

and then it starts using it?

slender nymph
#

Convert is a class in the System namespace

woven holly
#

so i must not use anything in the System namespace until now then?

slender nymph
#

did you not bother reading the link i sent?

cosmic dagger
woven holly
woven holly
slender nymph
#

but like i said, the Convert class is in that namespace, although i don't really see the need for the Convert.ToInt32 call here, just cast

woven holly
#

okay so when i use convert then it starts calling system and thats when it sees two versions of Random, yes?

#

im trying to understand how the code works as well as fix it

slender nymph
#

it's not "calling" System. you've added the using statement for the System namespace so now it sees those two Random types with conflicting names. this part is all spelled out in that link i sent

woven holly
cosmic dagger
slender nymph
woven holly
#

ohhhh

#

it added it for me? i did not know it did that

slender nymph
#

yes, when you autocompleted the type name for Convert

woven holly
#

i see now, thank you

woven holly
slender nymph
#

Mathf.FloorToInt

#

or just cast the result of the Math.Floor call to int using (int) which is literally what Mathf.FloorToInt does anyway

edgy needle
#

Do i need mac to export my game to macOS?

charred spoke
#

Yes

hasty sleet
cosmic dagger
# woven holly it added it for me? i did not know it did that

you'd only add the namespace to your script if you are accessing many methods from within that namespace. this is easier than using the fully qualified name, like UnityEngine.Rigidbody or UnityEngine.Transform every time you want to declare a variable . . .

woven holly
#

oh okay so i can call the namespace without the Using script?

cosmic dagger
slender nymph
hasty sleet
charred spoke
charred spoke
#

Again no piece of software is API complete so just deal with it

#

🤷‍♂️

edgy needle
hasty sleet
#

That's a bold statement

#

Embrace change and improvements, yes?

#

I like this philosophy more.

charred spoke
eternal needle
hasty sleet
cosmic dagger
hasty sleet
#

"Just deal with it" is not quite helpful and not very empowering

charred spoke
#

I also find it dumb that this api is missing yes. Like a said it warrants a suggestion on the public roadmap

woven holly
#

but Travis answered

cosmic dagger
#

this is how you can start separating your code into modules for reusability and modularity . . .

cosmic dagger
slender nymph
iron wing
#

if im understanding this right, is it possible to get a specific axis from a vector3 variable?
for instance. i have the variable 0.00, 0.00, 0.50 can I get only the z value from this variable? or the third, 0.50 value. im still trying to wrap my head around this, sorry if im asking stuff weirdly

charred spoke
hasty sleet
slender nymph
edgy needle
#

does anyone here runs linux to test my game?

slender nymph
edgy needle
#

ooh okay

mild lake
#

Hey! i'm making a pretty simple character system and i just wanted some advice. So far I've made a simple character class, and a couple other classes that inheriet from it, and set some basic data. How can I make a list of these inherited classes to choose between? Or does anyone have any better ideas on how to create a better frame work for handling data like that.

At the moment i'm setting a bunch of basic stats, like health, move speed, ect, then i'm trying to assign the class to the player, read the information off the class, and use it accordingly

raw token
#

Sounds to me like a job for Scriptable Objects 🦸

hasty sleet
#

If you put serialized fields in your scripts, you can set these values from the inspector. If you want to pre-set them, you can use prefabs, and if you want to store configuration in a script, then consider using scriptable objects

mild lake
#

hmm.. Scriptable Objects seemed awesome for the more primative data, but i'd also like each class to have functions written into it that can be ran. For instance, if the player pressed f, it would pull the function from the child class and then run it. Can i do something like that with scriptable objects?

#

I'm coming over from lua so i have an odd way of thinking about C# lol

hasty sleet
#

I would make the PlayerController script hook up the logic in its OnEnable function such that OnPlayerPressedF --> DoTheActionOnF

mild lake
#

It's not the performing of the action i'm stuck on exactly, moreso how the function will be accessed to be ran

hasty sleet
#

Composition is a fine way to do this. The script can access another component OtherController and run a function stored in another script

#

It is hard to give specifics without a clearer understanding of your intended architecture / outcomes

#

The main question that needs to be answered is: What outcome should this have? Phrase it in terms of a use case, like "A player should be able to", and it will be clearer for me

mild lake
#

I'm trying to make a framework (for a lack of a better word) that has inputs for basic information such as health,speed,attack,ect and then more complex information like functions (onAttack, onSpecial, onDeath) and then i'd like to use this framework to make classes that fill in these blanks to be used. Once my classes are done, i'd like to make some sort of handler script to read the data off the class, then process it. So again, if the player pressed "F" it would read the function onSpecial() from the child class, and then perform it

#

That's just the idea in my brain though, i don't know how feasible it is

hasty sleet
#

The logic is 100% feasible, but implementation methodology is critical

#

So I'll explain how my architecture works, and you can see if this makes sense to you:

PlayerStats --> Mostly a data container.

PlayerHealthController --> PlayerDeathHandler
PlayerInputController --> PlayerMovementController
                     \--> PlayerInputController

PlayerUIController (Handles input and routes it to UI actions)

(Input) <--> (Affect Change) <--> (Store Data)
InventoryView <--> InventoryController <--> InventoryModel
#

It is not perfect and may become more organized as time goes on, but there is a clear separation between components.

mild lake
#

What do the arrows represent?

hasty sleet
#

If you want HealthController to be able to invoke a Death mechanic, you can store it in another script, and when HealthController's Health goes below 0, it can call a method in PlayerDeathHandler, or emit an event that PlayerDeathHandler listens to

#

The arrows represent the flow of input and action, just like you wanted to direct the flow between player input (pressing F) and action (movement, UI interaction, etc.)

#

In terms of storing data, you should do this with scripts that are intended to store data. In my example, it is the InventoryModel which is entirely focused on storing data, while InventoryController is focused on changing data

astral falcon
#

Did you check the unity learn courses?

#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

hasty sleet
#

Like this

mild lake
#

(currently)

hasty sleet
#

I think it might be best to embrace the ECS architecture and turn this into a data class instead.

public class PlayerStats : Monobehaviour
{
  public string name = "Default"
  public int health = 150;
  public float speed = 5.0f;
  public float jumpHeight = 2.0f;
}

public class PlayerInputHandler : Monobehaviour
{
  private PlayerControls playerControls;
  private AbilityController abilityController;

  private void Start()
  {
    abilityController = GetComponent<AbilityController>();
    if (!abilityController)
    {
      Debug.LogError("No ability controller found.");
      return;
    }
  }

  private void OnEnable()
  {
    playerControls.Player.UseAbility.performed += UseAbility;
  }

  private void UseAbility()
  {
    Debug.Log("aaaa I'm using an ability");
    // Or, alternatively
    abilityController.UseAbility();
  }
}
#

Does this make sense?

mild lake
#

PlayerStats is the only thing confusing me, because i'm still thinking about how different classes would have different stats. Everything in PlayerInputHandler i understand very clearly

hasty sleet
#

I actually have my stats separated by class, too. I clumped them together for example

#

I have my JumpHeight and Speed in my MovementController
I have my Health in my HealthController
I have Strength, Dexterity, Constitution, etc. in my StatsModel.

#

And they communicate with one another by reading each other's data

mild lake
#

For ease of access and creation, I'm trying to have all of the classes stats, functions, you name it in simple place. In lua i had one massive keyed table, with other tables inside it, holding the type of data i was mentioning. Then i'd just go to that key in the array and pull the function when i needed to run it. So i could simpy type [Classname].function() to execute an ability

#

I don't know if that's possible with c#, or even something close, but that's what i'm trying to recreate

hasty sleet
#

It's possible, but your class will grow to multiple hundreds of lines long and you're going to wish you separated them

#

if you want to put thousands of lines in one script file, then be my guest, but separating them is considered good for modularity.

mild lake
#

I was getting pretty worried about the massive scale, which is why i'm now trying to split them into sub classes/children of a base class

hasty sleet
#

I would advise against using subclasses by default

#

While you can use inheritance, I think it's the wrong tool most of the time in Unity

#

The architecture is ECS, Entity-Component System, where components are scripts, the glue that holds everything together. If you use inheritance, things can get complicated and tightly coupled very quickly.

#

There's a saying, "Prefer composition over inheritance"

#

A script is a component, so it's preferable to inheritance.

#

What you appear to be doing is accomplishing ECS but through extra steps via inheritance

mild lake
#

Hmm, i am pretty new to coding as whole. I've done it for a very long time, but i never delved into the truly serious side of things. Do you have any resources to further teach what you're describing?

hasty sleet
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

hasty sleet
#

This is solid for Unity in general

#

But if you want to touch on the theory-side of coding, it is quite complex, so I recommend starting off with tailored questions when you search for answers.

#

Entity component system (ECS) is a software architectural pattern mostly used in video game development for the representation of game world objects. An ECS comprises entities composed from components of data, with systems which operate on the components.
ECS follows the principle of composition over inheritance, meaning that every entity is def...

#

The #1 way to learn, however, is simply to build.

#

Start off small and build a movement system. Then build a health system. Then build an enemy that just flies at you. Make the enemy damage you. Etc. Keep adding on and building things, and the principles will make more sense once you have the experience to understand the meaning behind them

mild lake
#

And i have the movement and health system currently, i'm trying to set their variables

hasty sleet
#

I think you are in a tunnel right now, and if you just take one step back and pick a different path, you will still be stuck in the tunnel. I highly highly highly recommend you just do things the "Unity way" and accomplish your objectives this way.

#

You are doing things the OOP way instead of the ECS way.

#

I don't think you'll make it far if you try to headstrong pure OOP into Unity

#

I did the same thing when I started and I regret it

#

It won't take longer than 20 minutes if you just follow a tutorial to get the basics up and running and take it from there.

fossil drum
hasty sleet
#

Plus, my project is deeply in progress. I might consider pivoting if I finish my current one

eternal needle
# mild lake PlayerStats is the only thing confusing me, because i'm still thinking about how...

Do you mean different numbers for the stats, or like actual different stats where some things may have X while others dont?
Id really just go with 1 stats class, regardless of if the character is using every single stat. Scriptable objects is a really good way of plugging in different numbers, instead of the example class you showed above. It would just copy values from an SO, suddenly everyones different stats can be represented by an asset in your folder.

mental aspen
#

When I build game, suddenly some changes appear in these files:
URP-HighFidelity.asset
BurstAotSettings_StandaloneWindows.json
CommonBurstAotSettings.json

It occurs everytime I build a game. Should I commit these changes?

fossil drum
#

Hmm, personally I dislike suggesting ECS for the normal monobehavior way that Unity works with.
Either work OOP in normal Unity, or ECS in DOTS.

hasty sleet
#

I think you should not default to inheritance in Unity scripts.

mild lake
#

I'll be honestly, this all sounds quite out of my league. I'm by no means new but I'm pretty lost as to what most of this means haha. ECS seems preferable, but i don't think i have the means of skill to delve into it just yet

eternal needle
hasty sleet
#

I suppose technically it would be GameObject-Component

#

I didn't look into DOTS ECS but components for composition is the essence of default Unity

#

OOP is certainly not the default design pattern

eternal needle
hasty sleet
#

Retroactively consider my mentions of "ECS" to be "Composition over inheritance"

#

Google is telling me it's GameObject-Component by default, which seems reasonable

mild lake
mild lake
#

Specfically regarding an interger number, and a function of sorts

#

To mean, it sounds like the "abilities" i'm trying to make in ECS would be individual classes, but i feel like i missunderstood

hasty sleet
#

You don't necessarily need ability to be a class; it can be a function. My recommenation was to put abilities into a separate class if you plan on swapping them between PlayerControllers, and then simply swapping the mapping between the PlayerController and AbilityManager class, or what have you

mild lake
#

I did suffer from a few issues in Lua, with my god object. For instance, adding anything to the massive array would require me recode a lot of stuff, and every class needed to have the same inputs, so it wasn't very flexible. I assume i'd have similar issues with class inheritance

#

try not to cringe coder edition haha. I mean it worked, and i was just goofing off in a multiplayer game me and my buddies played, so it served it's purpose

eternal needle
# mild lake Just so i can get a better grasp, could you apply this to the situation i'm in r...

For a character system, i really wouldnt inherit at all. Everything about a character is really just unique functionality you can attach to an object. Like for movement, theres probably some standard things you can do. Lets say, move jump and knockback. The character itself shouldnt implement this, it should just reference another component that does it. This would be composition, you attach a movement script logic to your character. Things may be able to call like
character.ApplyKnockback(whatever) and then the character script could apply that to its movement script. The movement script itself could use inheritance. Lets say things want to move in different ways, one character flies and another cant. Either way the functions are the same, move jump and knockback. Jump in this case might just be going higher while flying

#

Even the stats system you dont need inheritance, the character script can just hold a reference to the stats. The stats can get all of its information from scriptable objects

#

I like to make my code in a way where i can fully define an enemy in editor. Excluding the need for unique abilities of course

astral falcon
#

and even unique abilities could be tailored into that system if built up carefully

mild lake
#

Seems like we're on the same page then. I pretty much have everything besides the most basic stats separated into unique classes "playermovement, healthsystem, playermanager, playerclass(parent), defaultclass(child). The player manager assigns the class, and the player movement refrences that assigned class for it's speed stats. That's the way I'm currently trying to make it at least

#

I already had scriptable objects set up too, the only reason i didn't use it was because i couldn't add the unique code

astral falcon
#

Why do you have a default class inheritance for your playerclass? Your player should be your players base.

mild lake
#

i don't understand, player?

eternal needle
hasty sleet
#

For context, WendigoJr is used to using Lua and is not familiar with Unity's style of doing things, so they're coming from a pure OOP perspective

astral falcon
#

Nothing wrong with OOP being used in unity

#

So what is playerclass doing, what is playermanager doing?

hasty sleet
#

Never said it was. It's just not a good default approach for their use case.

eternal needle
#

meh it still is OOP, just we are defining instances of objects in editor vs defining it in code.

mild lake
#
public abstract class PlayerClass : MonoBehaviour
{
    public string className;
    public HealthSystem health;
    public float speed;
    public float jumpHeight;
    public GameObject playerModel;
    public System.Action ability;
    public System.Action onDeath;
    public bool canUseAbility;
    public float abilityCooldown; // Cooldown time in seconds

    public virtual void Start()
    {
        health = new HealthSystem(5); // Default max health
        canUseAbility = true;
    }

    public abstract void UseAbility();
}
hasty sleet
#

Eh, I guess that's accurate

#

Weird to think of that as the "object"

astral falcon
mild lake
#
public class DefaultClass : PlayerClass
{
    public DefaultClass()
    {
        className = "Default";
        health = new HealthSystem(150);
        speed = 5.0f;
        jumpHeight = 2.0f;
    }

    public override void UseAbility()
    {
        Debug.Log("Playing default class");
    }
}
eternal needle
#

scriptable objects here completely replaces the need for this derived classes

#

Along with attaching abilities compared to what you're doing of defining it in code as inheritance

hasty sleet
#

I usually imagine "object" as a type that stores data and methods, not a game object that seems distinct from manually-defined objects

#

It's a bit abstract, I guess

astral falcon
#

your playerclass could hold a list of abilities that you can assign. Same goes for items, armory or temporary effects. You should write down what type of properties you need on your player that will change through the course of your game

mild lake
#

Again i wanna applogize because i feel like i'm going in circles lol, but how would i code unique functionality for each class that falls outside the definitions of the scriptableobject?

summer stump
eternal needle
hasty sleet
summer stump
mild lake
# mild lake Well actually- let me clarify

Specfically just the ability, because i imagine it would be like "summonbomb.cs" with just a few lines of code, which seems inconvient to me to do for every ability, or anything unique

eternal needle
#

Thats actually desired in most cases

astral falcon
astral falcon
hasty sleet
raw token
astral falcon
hasty sleet
#

I don't know if there was confusion earlier

edgy needle
#

project worked n dis jus appeared idk wth is dis script

astral falcon
summer stump
hasty sleet
#

I mentioned that staple OOP features shouldn't be the default approach to solving a problem in Unity, as composition is pretty much the go-to default problem solving approach.

#

If you approach solving a problem, subclassing should not be the go-to for most problems.

edgy needle
hasty sleet
#

Then bawsi said game objects in the scene are objects in OOP, then I made the distinction above.

astral falcon
summer stump
edgy needle
#

where is library folder located

eternal needle
# mild lake Specfically just the ability, because i imagine it would be like "summonbomb.cs"...

This is better, usually abilities would inherit from some methods. You describe it as inconvenient but consider it the other way around, you would have the capability of writing only a few lines of code and an entire new game mechanic.
just to note this would be completely different from scriptable objects. Scriptable objects literally just save you from having to define stuff in code. For example this is my entire scriptable object code for defining the default stats a character can have. https://gdl.space/wujesiqeru.cs And one method is literally just editor utility to auto populate the stats with 0.

summer stump
raw token
hasty sleet
summer stump
edgy needle
#

even more errors after restarting

hasty sleet
edgy needle
#

facebook try to make anything actually work challenge impossible

astral falcon
timber comet
edgy needle
#

i didnt eeven start implemeting it

radiant sail
#

??
i dont have any errors

edgy needle
eternal needle
radiant sail
#

oh lmaoo

#

ty

eternal needle
#

your IDE should be pointing these compile errors though, unless the error is not from your code

timber comet
#

And it doesn’t work with the one you are using

#

Just guessing

astral falcon
#

the screenshots look quite old, maybe its outdated

radiant sail
eternal needle
eternal falconBOT
radiant sail
#

ill do later, right now the things its pointing out for me are helpfull

edgy needle
astral falcon
last orbit
#

Hey,
Can someone happen to give me a script what changes an animation by clicking on a bottom and this name indicates the animation on the cube?

Or generally help me with the topic?

astral falcon
mild lake
# eternal needle This is better, usually abilities would inherit from some methods. You describe ...

Would it be wise to overide a abstract function inside my movement script? So lets say i wanted to make a class make a sound when they jump, i could just make a file and then code my unique functionality inside it, hooking into the method i had defined to trigger it, and then possibly refrence that in the scriptable object? I don't know if i'm cooking or this is dumb haha, my brain is turning to mush

mild lake
#

Fair

summer stump
last orbit
eternal needle
# mild lake Would it be wise to overide a abstract function inside my movement script? So le...

this part is really hard to suggest because movement systems are complex. Thats definitely a possibility but usually you'd want some central way of moving and inheriting just to only add a sound would feel a bit weird.
I would do this the other way, have every character possibly play a noise or animation on jump. If you dont attach a noise or animation, it simply doesnt do that logic

edgy needle
eternal needle
#

An enum which simply says when to play it, when its charging, when the ability is used, when the ability exits. How long it should take etc

mild lake
#

No problem whatsoever though if you'd prefer not to

#

haha, i'm reading the latest hytale blog and they're discussing the exact same thing as we are. very odd coincidence

astral falcon
#

Its not an easy topic, especially about players with abilities like in an rpg or similar. You have to keep track and know, what your code is doing. So its good, you think about it a lot.

mild lake
eternal needle
# mild lake Again, just to get a better idea of what's going on here, could i see the melee ...

this logic is actually on my AbilityBase, this is the part for inheritance. the melee script doesnt have any logic related to animations. I dont mind sharing snippets, its really simple. There is one thing i do backwards for simplicity in how the code is written. Basically on charge up, ill try calling the animation code with AnimationTiming.StartChargeUp and check if it matches the one chosen in inspector. If not, return. Same for ability, and exit ability.
https://gdl.space/rukaladexo.cs

astral falcon
eternal needle
#

for the snippet above, I could easily do it like

    void AbilityInternal()
    {
        if(animationTiming == AnimationTiming.Ability)
          HandleAnimation();
        Ability();
    }

i just didnt want to

#

the script is quite long so i excluded a lot like where i define my fields and the enums but you can definitely figure that part out :p

mild lake
#

Gotcha. Thank you all so much

#

i'ma isten to twentacle and get some sleep

blazing ruin
#

btw. Do you know when I have 3 levels, but have similar menu, have 'basic' similar elements for each, for instance on the screen. Is not weird create prefab on Level Base object, which contains UI, Coin Manager Selector. You get it? @teal viper

teal viper
blazing ruin
teal viper
feral sapphire
#

how can i fix this issue? all i know is that the number is to high.. but i havent found a way yet to solve this issue.

teal viper
feral sapphire
teal viper
#

You'd need to save it as a string though

feral sapphire
#

So i have to put int into string and back?

teal viper
burnt vapor
#

Although you can also learn JSON Serialization and use that to write strings to PlayerPrefs

junior finch
#

I have a question, When do you use shaders and when do you use shader graphs. I understand shaders are mainly vertex and fragment. but if i want to make a special effects i use a shader graph. I might also be explaining it wrong

teal viper
#

You use shader graph, when you don't know how to write shader code and are too lazy to learn. Or for convenience

junior finch
#

hmmm, that explains it

#

Then i have a question, I want to make bullets that look like lasers. From there I am guessing it is more of a vfx thing than a material

teal viper
#

The simplest one would probably be a line renderer

junior finch
#

hmm let me look that up real quick

#

hmm i see

late yew
#

In my current project I want the player to unlock multiple 'charges' of their dash ability, and I have them regenerating in update. with my current function it just permanently sets the timer to max, so it's never counting down, but I can't work out how to fix it. If I use a coroutine will that keep getting reset as well?

if (availableDashes < maxDashCount)
{
    dashCooldownTimer = dashCooldown;
    if (dashCooldownTimer > 0)
    {
        dashCooldownTimer -= Time.deltaTime;
        if (dashCooldownTimer <= 0)
            availableDashes++;
    }
}
blazing ruin
ivory bobcat
late burrow
#

removerange second arg at 0 removes nothing?

burnt vapor
#

Sounds like your code has issues

abstract saddle
#

Im a complete beginner, where should i start? also is it a good idea to ask chatgpt for codes?

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

abstract saddle
#

ok ty!

burnt vapor
timid hinge
#

hi guys i have a question why did w show on inspector but dont show on game?

broken cargo
timid hinge
#

thanks

sleek timber
#

please explain how to get normal shader in urp why it is gltchy how to remove?

timid lagoon
#

can I use webgpu in unity? if so how do I create a project with it. Need to impress my teacher with something dxd

broken cargo
torn pier
#

!vc

eternal falconBOT
#
Using version control in Unity

Unity Version Control

git Git

Get the latest .gitignore file from here. It should be placed at the root of your Unity project directory.

torn pier
remote osprey
#

hey peeps

#

so I"m making a card game and I want to queue up all my animations and actions in a way that waits for each to end before starting another one

#

Thing is, I still want for user interaction to be possible while the animations happen

#

My friend recommended me to use Coroutines but I also heard of Async

#

So my question is, which one do I use for the animation in a way that doesn't lock user input until they finish?

broken cargo
remote osprey
#

So coroutines won't take all processing away then?

#

They still share it with other routines like input detection and the like

#

Because I saw in a video that the coroutine is run in the mainthread

broken cargo
remote osprey
#

Ok, thank you!

broken cargo
remote osprey
#

Got it

#

Thanks for the info!

burnt vapor
#

And with new Unity there are Awaitables which make asynchronous programming even easier

broken cargo
swift crag
#

This sounds like two different questions:

  • How do I use the new input system?
  • How do I add new features to a movement component?
#

A dash is a dash; it doesn't matter if it's triggered when Input.GetKeyDown(KeyCode.LeftShift) returns true or when you get a callback from the "Dash" action

#

it's hard to answer that question because my answer would just be "i learned how to do it" 😉

#

Try thinking about how you'd implement that movement feature completely on its own

#

so, not as part of a more a complicated character controller

#

you could implement a character controller script that does nothing but dash

#

when you press shift, you look at the current movement input

#

store that and move in that direction for half a second

vast sandal
#

In addition to what fen said:
Try tinkering with the code.. make the jump higher, try to get the logic thats underlying..

try to code something you've allready seen.. like a jump maybe, without looking too much at the code.. could you get the jump working in a different axis? is that maybe close to a dash?
how could you tweak it to behave like a dash..?

#

Lots of stuff in the beginning is just "tinkering" and picking stuff up you've seen somewhere.. squash stuff together and see what happens.. just what smaller kids do, they see something, try themselves and see what happens 😄

timid oriole
# abstract saddle ok ty!

I kinda disagree don't go through the entire thing I think once you learn the basics from it move on

#

also I suggest learning about c# if you intend on programming too as I'm new as well I found it helped me a lot

#
pastel sinew
#

There are no examples sadly.

wintry quarry
swift crag
#
Unity.Cinemachine.CinemachineCore.CameraUpdatedEvent.AddListener(...);
remote osprey
#

This seems wayyy too complicated for a State Machine in my very questionable newbie opinion

pastel sinew
pastel sinew
swift crag
#

oh, this is a component

#

stick it on the object that has your virtual camera and then add listeners as usual

young smelt
#

What does it mean for me too be getting this from play console after I just updated it to mention that I will be using advertizing:

1 Error
Error
Your advertising ID declaration in Play Console says that your app uses advertising ID. A manifest file in one of your active artifacts doesn't include the com.google.android.gms.permission.AD_ID permission.

If you don't include this permission in your manifest file, your advertising identifier will be zeroed out. This may break your advertising and analytics use cases, and cause loss of revenue. Learn more

You can remove these errors by updating your advertising ID declaration

Apps that target Android 13 (API 33) without the AD_ID permission will have their advertising identifier zeroed out. This may impact advertising and analytics use-cases. Learn more

swift crag
#

the message clearly explains how to solve the problem

young smelt
#

And I already added it to my manifest yet it's still saying all that:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools">

<!-- Add the necessary permissions -->
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<uses-permission android:name="com.android.vending.BILLING" />

<application>
    <!-- Add the Google Mobile Ads application ID -->
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="some specail code"/>

    <activity android:name="com.unity3d.player.UnityPlayerActivity"
              android:theme="@style/UnityThemeSelector">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
</application>

</manifest>

swift crag
#

this is also not a code problem -- it should go in #📱┃mobile , most likely

young smelt
young smelt
#

damn the other places are ghost towns. Ok then

robust turret
#

hello

#

'''cs
//
public void startGame()
{
startGameScreen.SetActive(false);
GameObject.FindGameObjectWithTag("Player").SetActive(true);
GameObject.FindGameObjectWithTag("Respawn").SetActive(true);
}
'''

#

how can I reffer to the tagged game objects without setting an object for them?

teal viper
#

!code

eternal falconBOT
young smelt
robust turret
#

so here is how it is...
Whenever start game button is clicked, I want startGame screen to deactivate, which it does.
Then spawn the player and obstacles tagged as respawn

#

public playerScript player;

player = GameObject.FindGameObjectWithTag("Player").SetActive(true);

#

instead of this

#

is there any way to directly reffer to them?

astral falcon
willow scroll
#

It that right?

willow scroll
young smelt
robust turret
willow scroll
astral falcon
#

Or let it subscribe itself to your "GameManager"(?) , if it is changing because you are destroying it or whatever

astral falcon
willow scroll
#
private GameObject yourObject;

private void Awake() => yourObject = FindGameObjectWithTag("YourObject");
astral falcon
#

Also if there is only one player alive anytime, you can just use the singleton logic to access it

robust turret
#

how u write it?

willow scroll
robust turret
willow scroll
astral falcon
#

You dont need to search for it again, when you assigned player once

#

` copy paste this three times 😉

willow scroll
#

` <- this symbol should be on the left side of your key 1

robust turret
#

oh gotcha

#

I was using quote sign

#

near l

timid fulcrum
#

hey, if i want to send a long code i need to do it in pastebin?

willow scroll
eternal falconBOT
timid fulcrum
#

ok, so i have this code - https://gdl.space/yayocuhapu.cs
it's from a wall ride youtube video - https://www.youtube.com/watch?v=WfW0k5qENxM&t=1s

and i want to be able to not jump on the same wall twice.
i'm on it for 2 hours already trying many different approaches with no avail.
i know i need to store the wall im riding on as a variable and then compare the next wall im riding on to the last wall but the

(wallLeft || wallRight) 

is messing me up.
can someone think of a way i can do it?

WALL JUMPING & CAMERA EFFECTS - Unity Tutorial

As a continuation to my wall run tutorial last week, I'm now going to show you how to add wall jumping and smooth camera effects (fov change and cam tilt).

If this tutorial has helped you in any way, I would really appreciate it if you leave a like in return. And you can also subscribe to this cha...

▶ Play video
swift crag
#

That evaluates to true if wallLeft or wallRight is true

#

What is the problem?

astral falcon
swift crag
#

ah, you're asking how to add an extra condition to what you already have

#

yeah, you can save the wall you found in CheckForWall

#

that'll be in rightWallHit / leftWallHit

#

You could also just remember if the last wall you were on was a left wall or a right wall

astral falcon
#

As long as you can not turn around on the wall 😉

timid fulcrum
#

i'll try and update

swift crag
#

Although that could make you fall down if you pass from one wall to another

vagrant ledge
#

guys how do I check if an animation is playing in an if statement?

swift crag
#

(that is, the built-in Animator)

timid fulcrum
#
private void CheckForWall()
    {
        wallRight = Physics.Raycast(transform.position, orientation.right, out rightWallHit, wallCheckDistance, whatIsWall);
        wallLeft = Physics.Raycast(transform.position, -orientation.right, out leftWallHit, wallCheckDistance, whatIsWall);
        if (wallRight) currWall = wallRight;
        else currWall = wallLeft;
    }

so like that?

swift crag
#

This would set currWall before you even start a wallrun

#

so you'd never get to do a wallrun at all

#

You'd need to set the current wall when you stop a wallrun, I think

timid fulcrum
#

so i can try to add another bool to check if i touched a wall before already and set it to true

#

once wallride for the first time

#
private void CheckForWall()
    {
        wallRight = Physics.Raycast(transform.position, orientation.right, out rightWallHit, wallCheckDistance, whatIsWall);
        wallLeft = Physics.Raycast(transform.position, -orientation.right, out leftWallHit, wallCheckDistance, whatIsWall);
        if (touchedAWallAlready)
        {
            if (wallRight) currWall = wallRight;
            else currWall = wallLeft;

        }
    }

// in state machine vvv
if ((wallLeft || wallRight) && verticalInput > 0 && !playerMovement.grounded && !exitingWall)
        {

            if (!playerMovement.wallRunning)
            {

                StartWallRun();
                touchedAWallAlready = true;

            }

vagrant ledge
#
//Drop if equipped, "Q" is pressed and fpsCam is playing the "Idle" animation 
if (equipped && Input.GetKeyDown(KeyCode.Q)) Drop();
#

how Do I do This ??

#

I wanna call the drop function if the fpsCam is playing the Idle Animation

languid spire
vagrant ledge
languid spire
vagrant ledge
languid spire
#

so ?

#

scripts can reference eachother or you can pass the bool via a singleton/manager

gleaming kraken
#

is there a better way to do this

#

im really starting to feel like yandere dev

languid spire
#

Enums and Arrays

swift crag
#

If all you're doing is calling AddListener on each button in your Awake method, you can just hook up the events on the Button components instead.

gleaming kraken
#

cant really use an array

languid spire
#

yes you can

swift crag
#

actually, this is the perfect place to do so

gleaming kraken
#

an array is a single value though

swift crag
#

you aren't trying to do specific things with each button

gleaming kraken
#

i should use a dict

swift crag
#

no, you should make a class that holds a button and a text component

burnt vapor
swift crag
#
[System.Serializable]
public class RebindingButton {
  public Button button;
  public TMP_Text text;
}
#

now you can serialize a List<RebindingButton>

gleaming kraken
swift crag
#

Even better, you could really just generate the rebinding interface from a list of input controls

gleaming kraken
#

that might actually be better

swift crag
#

I generate my control lists from my input actions. Each entry is a prefab.

swift crag
#

I do often use a struct in this kind of situation

naive pawn
burnt vapor
burnt vapor
naive pawn
#

why not?

swift crag
#

it's just not very important here

vast vessel
#

Agent.speaker?.SaySentence("Death");
will this null check work instead of an if statement, if Agent.speaker is a monobehavior?

swift crag
#

No, it would not behave correctly.

#

?. only cares about genuine null references

vast vessel
#

what can i do instead that is also short

burnt vapor
# naive pawn why not?

Struct behavior can be very complex and unexplainable for beginners. It also makes negligible difference here when it comes to performance like what structs would have

swift crag
#

When you destroy a unity object, it becomes equal to null, but it's not actually magically turning into a null reference

naive pawn
swift crag
#

other than that it's going to look and feel the same

burnt vapor
naive pawn
#

if you know classes, you're already 90% the way to a struct

swift crag
#

It's just a bundle of a button and a text component.

burnt vapor
#

Not in this question, but who said that it was purely going to be done through the editor?

vast vessel
naive pawn
swift crag
#

Consider getting rid of the field access entirely

burnt vapor
swift crag
#

perhaps you should just tell the agent to say something

vast vessel
#

damn

naive pawn
swift crag
#

the behavior is also irrelevant for a "bag of data" type

naive pawn
#

if your "average beginner" can't adapt to structs, then they barely knew classes to begin with

burnt vapor
#

It answers absolutely nothing about the question, so it's pointless

naive pawn
#

familiar class based approach instead
literally the same thing

swift crag
#

I'd just use a class because it doesn't really matter at all here

#

If you have two options, go with the more familiar one

burnt vapor
#

This is not a channel for code reviews

naive pawn
#

we're discussing beginner-related coding concepts, aren't we

#

i see no reason to bar beginners from using structs

burnt vapor
#

Does it fall under their question?

vapid trellis
#

Hi

naive pawn
#

no, does it have to?

naive pawn
burnt vapor
#

So why bother changing an answer that works fine and point them to use a more complex system? Structs makes no difference here and suggesting it over classes is just going to make it confusing in the future why stuff suddenly doesn't work they expect them to.

naive pawn
#

you answered with something i didn't understand, so im starting a discussion

timid fulcrum
swift crag
#

that way you can't accidentally, say, write "NocurrWall" and have it break

#
public enum WallState {
  None,
  Left,
  Right
}
#

This creates a new type -- WallState -- with three values

naive pawn
swift crag
timid fulcrum
#

@swift crag good idea

burnt vapor
naive pawn
#

but clearly you aren't interested in the discussion further than just pushing your own point, so sure, let's drop it

#

tf you just said to stop the conversation lmao

#

what do you want

burnt vapor
#

Awake runs before anything else, and is generally the point where you get your components, unless it's deliberately done

spare mountain
timid fulcrum
#

@swift crag actually i dont think i'll use it since it complicates things for me and it works right now. also i am positive i will not set it to "NoCurrWall" by mistake 😄

burnt vapor
swift crag
#

Yes, it's only an issue when multiple components are interacting with each other

burnt vapor
#

So when you do the initialization in Start, there's a chance the component reference remains null

swift crag
#

Suppose you have this setup:

burnt vapor
#

In Unity it's not guaranteed that one script runs before another, so it could randomly break because of it

swift crag
#

A.Start: use GetComponent to get a component

#

B.Start: tell A to do something that needs the component

#

If B.Start runs first, you'll get an error

#

Of course, what you should really do is just assign the references in the inspector ahead of time

#

setting yourself up in Awake and then interacting with other things in Start is just a useful rule of thumb

gleaming kraken
burnt vapor
#

There's also DefaultExecutionOrder attribute

#

You're right though

queen adder
#

while playing i'm supposed to click on a stone and the rock will be placed in the inventory. but when there are many rocks nearby, when i click on a single one all of them get picked up. Any solutions please?

slender nymph
#

you'd have to show your code. but most likely you just need to rethink how you are going about it.
a raycast to get just the one you are looking at is typically sufficient and you just call a method on only that object to interact with it

polar acorn
queen adder
#

and this is a script attached to every interactble item like the stones

slender nymph
#

yeah so you're just checking for input on every single interactable object and assuming the player is looking at that object while in range. perform the interaction from the component that does the raycast.

polar acorn
# queen adder

If you're checking if the ray hits an object, why not just actually call a function on that object instead of just setting a boolean and let every rock try to guess if they're the reason the bool was set?

queen adder
#

Thanks for your help guys i'll look into it and hopefully it works

late burrow
#

ok so i have type1 which holds type2, how i make type2 take values from type1 on new() without referencing type1

#

since i cant put type2 constructor into type1

gaunt ice
#

you cant assign some value without knowing value
you can pass (reference of) type1 instance to type2 stored in type1 or pass what type2 needs, when constructing type2 outside type1 struct/class constructor

wintry quarry
#

"type1 holds type2" is really vague and doesn't really explain much BTW

#

It could mean it's a nested type, or there's a field of that type, or who knows what

#

But either way, you either pass params or set from outside.

late burrow
#

thought i can mark parent class to always have parent variable accessible

raw token
#

so type2 extends type1?

If so, type2 can access any public or protected members from type1

polar acorn
wintry quarry
#

You are being too vague

#

Like I said "holds type 2" isn't very meaningful or specific

polar acorn
stuck palm
#

how can i delete a script from an object at runtime>

stuck palm
#

thank you

#

doesnt that destroy the object too or?

raw token
rich adder
#

components inherit from Object so those are included

stuck palm
#

i see, thanks

polar acorn
#

but if you call it on a component it destroys that component

polar acorn
verbal dome
#

The "refuses to elaborate further" is real with this one

swift crag
#

fun game: destroy random stuff you found with Resources.FindObjectsOfTypeAll<UnityEngine.Object>()

#

this eventually causes an editor crash

lost hamlet
#

My friend found something stupid to try a while ago. I haven't tested it but basically patching Time.deltaTime with Harmony to return a random float

#

What could that exactly break

swift crag
#

everything that is time-dependent

lost hamlet
#

Everything?

swift crag
#

since the amount of time that passe per frame will now be a random quantity

swift crag
#

no, things that are not time dependent (e.g. something that deals damage to you once when you touch it) will behave as usual

swift crag
#

it's for C# in general, but it's designed for game modding

lost hamlet
#

You could use it in your own game for some stupid things

lost hamlet
#

I had a use for it a while ago but forgot what

late burrow
#

since when i try create type2 it asks for type1 parameters

brave compass
#

Yeah, I use it for editor scripting sometimes, like to hook into editor GUI that isn't otherwise accessable.

lost hamlet
#

Right that was it

swift crag
#

I've used it before for Rimworld modding. Very nice system.

brave compass
raw token
summer stump
#

Perhaps provide the information that was requested

stuck palm
#

I have this code that adds all the movement vectors of a controllers to influence one marker. Why is it if one controller (red) is moving up and the other (green) is moving down, then the resulting movement is orange?

 void Update()
    {
        Vector2 combinedVector = Vector2.zero;
        foreach (PlayerInputController pic in _controllers)
        {
            combinedVector += pic.markerMove;
        }
        
        combinedVector.Normalize();
        
        _transform.anchoredPosition += combinedVector * (speed * Time.deltaTime);
polar acorn
late burrow
#

first class holding array of second class and second class should have access to first class stuff

verbal dome
slender nymph
summer stump
stuck palm
verbal dome
#

Zero?

stuck palm
#

the vector goes in all directions as its coresspending to the joystick

summer stump
verbal dome
stuck palm
#

im trying to make that

#

clamp makes sense

chrome tide
#

is it a good practice to use Scriptable Object to hold data that needs to be accessible across the game scenes?

polar acorn
# chrome tide is it a good practice to use Scriptable Object to hold data that needs to be acc...

In general, modifying a scriptable object at runtime is a bad idea, because it behaves differently in the editor as it does in a build, which can make debugging difficult. In the editor, changes to the ScriptableObject at runtime persist forever. It modifies the asset on disk and those changes are permanent. In a build, though, it will only modify the SO for that run of the program. Closing the program and re-opening it will reset the values to what the project was built with

polar acorn
swift crag
#

unless you manually edit it some more in the inspector, I believe

#

i tested this a while back because the behavior of scriptable objects was driving me nuts

swift crag
polar acorn
#

Really? And you're referencing that specific asset, not one made with CreateInstance?

swift crag
#

Right.

#

It doesn't get dirtied

timber tide
#

yeah what does it exactly do? Create some temp instance and persists till you restart the editor?

polar acorn
swift crag
#

because the object doesn't get unloaded

polar acorn
#

do they still persist between sessions?

timber tide
#

I just ran into that issue when I wanted to see if I could save persistent data during playtime to SOs ;p

swift crag
#

If you load a new scene and nothing is still referencing the object, it gets unloaded

polar acorn
swift crag
#

Right

#

I store some mutable data in ScriptableObjects. I put them in a dictionary when the game starts and keep them there forever, so they never get unloaded

swift crag
polar acorn
#

Neat! I learned something today 🌈 ⭐

slow knot
#

Soo, hello! I've been making a clicker game in Unity 2D, and not sure how I can make that button teleport inside an object, I've tried to code it, but ended up glitched in different screen sizes.

slow knot
# rich adder show current code you tried

After it ended up like that I tried to make it like this, it spawns inside "Main Camera" but realized now when screen size changes it again glitches

  te = "Button has decided to MOVE!";
                Vector3 newPosition = new Vector3(Random.Range(0f, Screen.width), Random.Range(0f, Screen.height), 0f);
                Vector3 worldPosition = Camera.main.ScreenToWorldPoint(newPosition);
                Vector3 localPosition = transform.InverseTransformPoint(worldPosition);                Object.transform.localPosition = localPosition;```
rich adder
#

also what do you mean it glitches, can you show what happens?

slow knot
slow knot
swift crag
#

This is computing a position that's 0 meters in front of the camera

naive pawn
whole parcel
#

heyo guys!! im creating a pacman in unity as my first project. i've created all the pacman logic and created the maze using a tilemap. i was working on the ghosts now and in order to perform my a star algorithm, i need to get the tilemap down into code as my grid. anyone know how i can do that?

naive pawn
#

that's a pretty broad question. the tilemap already holds a grid, what part are you stuck on exactly? referencing the tilemap? accessing the grid?

whole parcel
#

accessing the grid

willow scroll
naive pawn
naive pawn
willow scroll
whole parcel
#

oh yes

#

that helps a lot

#

tysm everyone!!

willow scroll
whole parcel
#

matrix would be preferred

#

bc im doing an a star right

willow scroll
whole parcel
#

hmmm i see

willow scroll
#

This means, you cannot have

0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0 0
#

Only a rectangle form.

whole parcel
#

yea i dont hv that

#

it's in a rectangular form

willow scroll
#

Sure, then you can indeed use a matrix

whole parcel
#

this is how it looks

#

it should be fine right?

willow scroll
#

Those where there are no tiles

whole parcel
#

yeaaa

stuck palm
#

How can i check time since a scene is loaded? just learnt Time.time is for application.

whole parcel
#

that should be fine

#

so how do i get matrix?

stuck palm
#

looks good, thanks

willow scroll
naive pawn
#

if directly from the Tilemap, Vector2Int is also an option

willow scroll
#

Fixed

whole parcel
#

smth like this?

willow scroll
whole parcel
#

alrightyy tysmm

willow scroll
#

I also tend to do extension methods to not parse VectorInts all the time

public static TileBase GetTile(this Tilemap tilemap, Vector2Int position) =>
    tilemap.GetTile((Vector3Int)position);
willow scroll
remote osprey
#

Is there a way to separate my class logic from the class, like, for example, creating a custom object that carries the logic when an event happens then attaching this object to a scriptable object (for example, an npc)?

remote osprey
#

Allowing me to have an event logic and scripting separately?

rich adder
remote osprey
#

That's what I'm trying to do!

#

But i'm very stuck

rich adder
#

in what way?

remote osprey
#

I just don't know how to insert the custom logic in my NPC SO, for example

#

oh wait, I just had an idea

stuck palm
remote osprey
#

Maybe I should create a SO inside my NPC folder then write a class that extends my Event SO, then just attach the script to a variable that will hold that class?

#

maybe that could work

rich adder
remote osprey
#

Hmm okay, but that would still be all code I guess

#

which is not bad I guess

rich adder
#

I mean yeah everythin you do is gonna be all code

summer stump
rich adder
#

how you piece them together is what matters I think.

remote osprey
#

I guess I can do a script that is gonna be located in the NPC folder

rich adder
#

well yeah its easier to switch out behaviors if lets say its an SO

remote osprey
#

That should keep my architecture organized nicely

rich adder
#

they all have Execute method or somehing common you can call, but they each do something else. You just swap them

remote osprey
#

Okay!

#

Thanks for the help, friend!

rich adder
#

goodluck 🫡

remote osprey
#

Hey, i just had another question hahaa

#

What if I need a DrawCard Behaviour but its different for each card, making a different class for each behaviour seems weird

#

Is there an elegant solution to this?

#

I guess making a method for each card and putting them on a delegate but that's bloated

rich adder
#

it really depends

#

certain things I just use an enum tbh it speeds up the process for me

#

i'm making a game after all not some code masterpiece

#

as long as it works and it works well, it doesn't matter how you do it tbh

remote osprey
#

I see what you mean

#

I'm taking my time tho to learn SOLID well since I never did that before during uni

#

Although in a real project, yeah, just do what's easier/faster

rich adder
#

yes SOLID is good but remember these are general guidelines, they are not meant to be followed to a T always

verbal dome
remote osprey
verbal dome
#

Like what differences do the cards have for example

remote osprey
#

I'm copying hearthstone so

#

Every card has a different behaviour

#

which makes the architecture complex

rich adder
#

working on a card game also myself, i see what you mean

swift crag
stuck palm
#

how can i create an error code? if something happens in my game that isnt meant to happen?

swift crag
swift crag
#

i'm not sure how an "error code" would be used

timber tide
#

big red text that plague the user's screen

verbal dome
#

Lebug.DogError

slender nymph
#

you can also just create your own exceptions and throw those

swift crag
stuck palm
timber tide
#

You can keep development mode console going and it'll print the errors in a console

summer stump
swift crag
#

i'd really just show a coherent error message

rich adder
#

make a const of error codes or something then use a dictionary to print out what they mean

stuck palm
slender nymph
swift crag
remote osprey
swift crag
#

or mean nothing

stuck palm
swift crag
summer stump
swift crag
#

You re-use simple behaviors.

swift crag
summer stump
#

is X possible
Yes

rich adder
swift crag
remote osprey
slender nymph
swift crag
#

You may still have behaviors that are only used by one card

remote osprey
swift crag
#

(just like how MTG has rules that are there for a single card)

#

Now, architecting this isn't trivial

#

It'd be a useful place for [SerializeReference]

stuck palm
swift crag
#

I have a bunch of places in my game that need to "score" things (e.g. decide how much an entity wants to pull a lever)

rich adder
swift crag
#

I use [SerializeReference] to store (nested) scoring methods

summer stump
#

That is composition

#

And it be strong

slender nymph
verbal dome
remote osprey
#

I remember it, Aethenosity, it's just that I'm doing a completely diferent code, before i was using delegates and built-in methods for everything, now I"m trying to make my code more SOLID

#

So i'm tripping a bit on concepts still

swift crag
summer stump
#

Fair

#

There is a lot to it all

swift crag
#

The MovedFrom attribute lets you tell Unity what a class used to be named, or where it used to be found

#

I have used this to refactor before

swift crag
verbal dome
swift crag
#

It was very hard to find lol

#

It's in UnityEngine.Scripting.APIUpdating

verbal dome
#

Undocumented too, ofc

swift crag
#

boing

verbal dome
#

Okay thanks this will be helpful

swift crag
#

the alternative is to just rewrite the YAML lol

swift crag
verbal dome
#

Gotcha

dusty silo
#
private void buildBranches() {
        float angle = 180, angleTwo;
        List<float> inputAngles = new(), outputAngles = new(), angleRatios = new(); 
        for (int i = 0; i < 360; i++) {
            angleTwo = Geometry.angleBetweenVectors(extrude(Vertecies[4]), extrude(Vertecies[4], i)) * Mathf.Rad2Deg;
            inputAngles.Add(i);
            outputAngles.Add(angleTwo);
            angleRatios.Add(i / angleTwo);
        }
        printList(inputAngles);
        printList(outputAngles);    
        printList(angleRatios);
    }
private Vector2 extrude(Vertex v) {
        Vector2 dir = v.position.normalized;
        //NCvertex(dir * 2 + v.position).connectTo(v);
        return dir * 2 + v.position;
    }
    private Vector2 extrude(Vertex v, float angle)
    {
        Vector2 dir = Geometry.rotateAroundArbitraryCenter(angle, v.position.normalized, v.position).normalized;
        //NCvertex(dir + v.position).connectTo(v);
        return dir + v.position;
    }
// In Geometry Class:
public static Vector2 rotateAroundOrigin(float theta, Vector2 dir) { 

        theta *= Mathf.Deg2Rad;
        float x = dir.x * Mathf.Cos(theta) - dir.y * Mathf.Sin(theta); 
        dir.y = dir.x * Mathf.Sin(theta) + dir.y * Mathf.Cos(theta);
        dir.x = x;
        return dir;
    }

    public static Vector2 rotateAroundArbitraryCenter(float theta, Vector2 dir, Vector2 ctr)
    {
        theta *= Mathf.Deg2Rad;
        float x = (dir.x - ctr.x) * Mathf.Cos(theta) - (dir.y - ctr.y) * Mathf.Sin(theta) + ctr.x;
        dir.y = (dir.x - ctr.x) * Mathf.Sin(theta) + (dir.y - ctr.y) * Mathf.Cos(theta) + ctr.y;
        dir.x = x;
        return dir;
    }
dusty silo
# dusty silo ```cs private void buildBranches() { float angle = 180, angleTwo; ...

The attached image shows the relation ship between the desired angle (x-axis) and the actual resultant angle between the extrude(vector) and extrude(vector, angle) (y-axis). I don't understand why there is such a large difference between the intended result and outputs. There could be something I'm missing with regard to the rotation function, or something else entirely. Any help woul be appreciated, thanks.

swift crag
#

instead of doing the trig yourself, you can just use Quaternion.AngleAxis to create a rotation

#

that'll make it a bit more concise, at least

#

see also Vector2.Angle

dusty silo
#

Do you think that will fix it, if so, why?

swift crag
#

No, but I just try to not re-implement what Unity already gives me!

#

(and there could nominally be an error in your rotation code, but it looks okay)

#

also, I believe I see the problem

#

Vertecies[4] is a point at, say, [3,0]

#

Suppose you extrude by 1 meter to get [4,0]

#

Then you extrude by 1 meter with a 90 degree rotation to get [3,1] (let's say that's a counter-clockwise rotation)

#

The angle between [4,0] and [3,1] is not 90 degrees

#

you wound up with these vectors

#

The angle between [4,0] - [3,0] and [3,1] - [3,0] is 90 degrees

dusty silo
#

I have also tried adding the direction vector pre rotation to the vertex's position and then rotating about the vertex, but that just makes a cool circle in the middle of the shape

swift crag
#

Your rotation is fine, but your expectations about the resulting angles are wrong

swift crag
dense root
#

Without creating another script how do I avoid the game object being overriden by the another door using the same script?

    private void Start()
    {
        // Scene setters
        previousScene = thisScene;
        thisScene = SceneManager.GetActiveScene().name;

        if (thisScene == "KawagishiScene" && hasEntered)
        {
            player.transform.position = doorPos.transform.position + offset;
            Debug.Log("doorPos: " + doorPos);
        }
    }
dense root
#

I manually set the door position with an offset to avoid colliding with the entrance again

rich adder
#

eg if player went in that trigger, it stores player as the one whos in the trigger

#

if it leaves then the reference should be maybe null so u can return early when null.
or make a bool that only goes true when player is near it/intrigger of that door

swift crag
dusty silo
rich adder
#

player position is setting frrom another door

#

i think

dense root
#

Correct

#

So the player is exiting from the wrong door

rich adder
#

well they all have player

swift crag
#

but these are two separate doors

#

i don't get it

#

if they all have a player reference then they'll all try to set the player's position, I guess

rich adder
#

yup. either kill the reference when not near or make a simple flag for when is in that building

dense root
swift crag
#

You need to indicate which door is being exited from

#

One option would be to give each door an ID, and to have a static field that stores the target door's ID

#

I remember talking about this with you a few weeks ago

dense root
#

Yeah I just started trying to fix it today, sorry

astral falcon
#

Or let the player decide where to go instead of moving the player from the door script. As you know what door the player entered, you should have a reference to the door already or like a synced door in your next scene preferably

rich adder
#

Is Building not its own class?

#

would make it so much easier to just store the Building/door it currently "belongs" to

#

or otherway around, store door /building object in the player

swift crag
#

yes, having the door yank the player over to it sounds very weird

dense root
#

Thanks for the hints, I'll see what I can do

slender nymph
#

oh lol i see you mentioned that nvm then

mortal obsidian
#

Hi, I'm a programmer, not too advanced but neither too bad, kinda in between, im currently pursue a degree in CS. That's my background, now, my question was regarding starting as a unity/unreal engine dev, I would like to start with android games and eventually javascript games(I suppose you'll have to use js for that). So what books/sources do you recommend? I still don't know C++ nor C# yet, but I usually learn fast and kinda know C, and do know java. So, any recommendations for learning C++/C# fast for game development is welcome as well.

rich adder
#

y javascript game ?