#💻┃code-beginner

1 messages · Page 549 of 1

long jacinth
#

in building.GetComponent<BuildingStats>().level < 0 im not referencing the copied buildings but the types

stuck palm
#

how can i fix these errors? using a sub class here

verbal dome
#

Need more info ofc.

#

Is it your own code/code that you can modify?

#

And show the code that those errors refer to @stuck palm

stuck palm
#

its just this repeating for a bunch of other field names

verbal dome
#

So you are using an asset for outlines?

#

Seems like that's where it's coming from

#

Or did you inherit from a class related to outlines

stuck palm
verbal dome
#

Did you add outlineWidth to the inherited class?

stuck palm
#

it did when i took that screenshot, but when i took it out, the issue still persists

#

code still works as expected, though

verbal dome
#

What asset/package is this?

stuck palm
#

Quick Outline

verbal dome
#

The error suggests that they are doing something like cs class OutlineBase { [SerializeField] float xyz; } class Outline : OutlineBase { [SerializeField] float xyz; }

#

Can you edit the source code?

#

Or view it

stuck palm
#

Outline, in my case, is the OutlineBase in your example

stuck palm
#

outline just inherits from monobehaviour

verbal dome
#

What is StylisedOutline?

#

Oh thats your class

stuck palm
#

yeah

verbal dome
#

It all suggests that StylisedOutline has some duplicate field declarations. But if thats not the case then idk.

#

Could try recreating the StylisedOutline components and see if the message goes away

swift crag
#

Or any parent class

verbal dome
#

But that could be a pain if you have a lot of them

swift crag
verbal dome
#

So I'm stumped

stuck palm
#

the base class uses properties, could that be something?

#

the errors dont seem to be happening anymore for some re ason

verbal dome
#

Not sure when those particulat errors appear, it feels a bit inconsistent

stuck palm
#

yeah

#

i suppose its fixed now

severe onyx
#

I have a script that automatically loops my background graphic when it's autoscrolling by shuffling a copy back to the right of the camera once it leaves the visible area to the left, but over time the two graphics start becoming misaligned... I tried solving this by moving the code from Update() using Time.deltaTime into FixedUpdate() and it mitigated it somewhat but there's still ugly seams visible every now and then and Im unsure how to guarantee the graphics will always stay at the same exact distance from one another. any ideas?

opaque owl
#

its happened again after upgrading then clearing my library folder (the only thing that could possibly be causing it is debugging in rider?, ive tried closing it though and it still wont reload properly)

update:
looks like its just the package manager not responding (in task manager)?

-# 6000.0.31f1

verbal dome
#

If that's the issue here even

#

Though you should show your code

severe onyx
#
        {
            backgrounds[i].transform.Translate(Vector2.left * (ScrollSpeed * Time.deltaTime));
            if (backgrounds[i].transform.position.x <= -1 * width)
            {
                backgrounds[i].transform.position = new Vector2(19 * (backgrounds.Count - 1), 0);
            }
        }```
#

reverted back to Update() over FixedUpdate() while testing possible solutions

verbal dome
#

Also try an empty scene

swift crag
#

let's imagine that it resets the position when X < 0

severe onyx
#

oh I already noticed a mistake I made in there anyways

swift crag
#

the problem is that, no matter how far you got past 0, the resulting position is always the same

#

Consider adding to the X position instead of just setting it

#
if (whatever.x < 0) {
  whatever += Vector3.right * 20;
}
#

This is a common error in code that accumulates a value over time

#

it's like doing this

#
delay -= Time.deltaTime;

if (delay <= 0) {
  delay = interval;
  // do something
}
#

It should be delay += interval; instead

#

and, even more accurately

#
while (delay <= 0) {
  delay += interval;
  // do something
}
#

in case the interval is so small that things need to happen many times per frame

sharp wyvern
edgy schooner
#

!bug

eternal falconBOT
#

🪲 To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.

📝 If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click ‘Report a problem on this page’!

💡If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.

For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting

severe onyx
#

seems to work fine now but Ill keep an eye on it, ty

feral verge
#

Is there alternatives for drag in rigidbody3d?

rough lynx
#

If you search up lineardrag intellisense will know what you're trying to write

#

Yeah it's lineardrag

feral verge
#

Oh ok thx 👌

swift crag
#

It's called "linear damping" now

rough lynx
#

I was wrong rip

feral verge
#

Yeah

rough lynx
#

Seems like an awfully unhelpful name change. I would understand linear drag

swift crag
#

It's more accurate -- air drag is proportional to the square of your speed, but I'm pretty sure Unity's "drag" is proportional to your speed

rough lynx
#

Ah ok that makes sense

opaque owl
sharp wyvern
opaque owl
#

stopping the debug session and closing rider didnt fix it when it was frozen

#

ill try see if i can trigger it while not debugging

verbal dome
#

Rider performance is a bit sluggish for me, I wonder if it can even handle a debugger

grand snow
#

I get infinite domain reloads in 2022 I just kill unity and re open 😦

opaque owl
#

i cant remember how often it happens or whats happening when it happens because it feels random

sharp wyvern
grand snow
verbal dome
#

Oh yeah - I used to have lots of issues caused by burst

verbal dome
#

Crashes too

opaque owl
#

is there a way to disable it if its buggy then?

steep rose
#

remove it's package

sharp wyvern
opaque owl
#

the button is grayed out

grand snow
#

It's depended on soo they cannot

opaque owl
steep rose
#

just now saw that

opaque owl
#

alteast i think it didnt?

grand snow
#

I reported this as a bug months ago they never responded to me 😭

sharp wyvern
opaque owl
#

what if i delete package forcibly thinksmart

#

jk unity will die i think

#

whats this?

sharp wyvern
opaque owl
#

oh hey guys im gonna try this

grand snow
opaque owl
#

ill say if it works

#

(disabling burst)

verbal dome
opaque owl
#

6000.0.31f

verbal dome
#

Oh oops its right there in the screenshot

opaque owl
#

yea lol

#

it didnt fix it :(

#

i swear its when i try to playtest + debug + i did a script change

verbal dome
#

Did you ever use the profiler to check what is happening?

opaque owl
#

also i gotta go but please tell me for when i come back 🙏

verbal dome
#

Then you recompile

opaque owl
#

Wont it freeze with unity though?

verbal dome
#

It should still be collecting info in the background

verbal dome
swift crag
#

well, if unity never comes back to life, then you're hosed

opaque owl
still elm
#

Osmal, thanks for before I solved my isssue. You probobly do not remember but thanks.

#

Also another question

verbal dome
#

Does unity ever recover from the reloading domain state?

#

Like is it completely lost or does it just take long

still elm
#

I want players to enter a username upon player sprite death. Currently after death the main menu is shown, where users can quit or play again. However, Is it easier to create a new scene (containing an text input element) that displays before the main scene or to modify the main scene to display an input element after player died? Or is there another sollution I have not thought of...

grand snow
#

May be a rider specific thing

opaque owl
verbal dome
#

Will probably take even longer with profiler enabled

#

Check rob's link though, seems like it would give good info here.

swift crag
opaque owl
grand snow
lament agate
#

Hello, newbie in coding here. Can someone give me a tip about what to do in situation with null ? I tried to google it, but i dont really understand it. From my understanding null is lack of .. data? I have a script , but i dont understand how would it be a null, i followed every step in tutorial.

#

https://www.youtube.com/watch?v=SMWxCpLvrcc&ab_channel=Unity this is the tutorial i have been following for that

The AI navigation system in Unity allows non-player characters (NPCs) to move intelligently through a game environment by calculating and following optimal paths and avoiding obstacles.

In this video, you’ll learn how to get started by setting up a NavMesh surface and how to set up the AI Navigation system package in Unity 6.

More resources:
...

▶ Play video
swift crag
#

Can you show us the script?

#

!code

eternal falconBOT
slender nymph
lament agate
swift crag
#

(in the future, please use a paste site -- we don't get line numbers in Discord desktop, and it doesn't work well at all on mobile)

slender nymph
#

called it. animator is never assigned

swift crag
#

okay, notice how this script uses GetComponent<NavMeshAgent>() to find an agent

#

but it doesn't do that for the Animator

#

forgor

verbal dome
#

So this sample script just has a massive fault?

#

How did that slip thru?

lament agate
#

@swift crag oh it was that, indeed lol. Thank you.

verbal dome
#

Or did you make this script

untold shore
#

Hey quick question, what code do I use to get an image inside a script?
I have a script called "CardDisplay", and I want to get an image called cardSprites in it. But when I do this in the script I want to have access that image:

cardSprites = GameObject.Find("Cards/CardDisplay").GetComponent<Image>();

It won't get the image because of "Object reference not set to an instance of an object." Any ideas?

lament agate
#

@verbal dome are u asking me ?

verbal dome
#

Yeah

runic lance
opaque owl
lament agate
#

@verbal dome the script comes from AI navigation package sample . I just simply followed the tutorial

slender nymph
rough lynx
#

unity.huh.how

#

That's a gold domain name

untold shore
#

Thanks!

#

Literally lol.

grand snow
opaque owl
#

oh ok

opaque owl
#

(i didnt ping bc idk if u wanted a ping)

verbal dome
#

I dont see anything that takes more than ~12 milliseconds there

verbal dome
opaque owl
#

yea because i waited a reasonable(?) amount of time

#

normally domain reloads take less than 16seconds

#

for me atleast

verbal dome
#

I assume that it logs things only after they are completed

#

So killing it while it is frozen would not let it log the thing that is actually taking long

#

Just assumptions though.

opaque owl
#

i enabled that thread thing rob was talking about too

grand snow
#

I presume it will log that if the unity person bothered to even post that.

verbal dome
#

I would let it take as long as it takes and then check the logs

opaque owl
#

it hangs tho?

swift crag
#

Yeah, you generally need to get past the bad part

#

I guess you could start stabbing at unity with a debugger

verbal dome
grand snow
#

When I get this it never completes it's broken for ever

opaque owl
visual linden
#

Waiting a minute for a domain reload Is a reasonable time. Make sure you're on the latest version of Unity and investigate to see if perhaps one of your plugins or assets is what's causing the long domain reload. Occasionally it's an editor bug, but a lot of the time it's code hooking into reload callbacks.

opaque owl
#

i waited like 20-23 mintues

#

and i killed it because i forgot i left it open

rich adder
#

delete library folder, refresh
always fixes weird hangs for me

swift crag
#

we're trying to figure out if anything useful appears in the logs

swift crag
#

there is an Evil Gremlin

grand snow
#

Best I figured out was burst compiler threads were still running when I last looked into it

verbal dome
#

Just let it do the whole domain reload and check thelogs afterwards.

swift crag
#

It doesn't die if you have a compile error, right?

swift crag
#

I'd add a gratuitous typo and then load into safe mode

opaque owl
swift crag
#

actually, that would stop pretty much all asset importing, so that might not be useful

opaque owl
#

is my unity just cursed sfm style 😭

grand snow
#

I'm soo used to it I kill unity if it takes more than like 10s and re open

verbal dome
#

Standalone profiler could help too.
(You can use that for edit mode, right?)

swift crag
#

I used to experience a lot of random freezes in 2022-ish Unity

#

no more, though

opaque owl
#

ill try again

verbal dome
#

Wdym didnt do anything

#

It didnt collect data?

opaque owl
#

well it just didnt report anything new ig?

#

one sec ill redo

verbal dome
#

I guess it won't report anything until it unfreezes

still elm
#

Is it possible to call a method from one scene in anoter scene?

verbal dome
#

So yeah, problematic

opaque owl
#

is this bad?

#

it just appeared when i loaded the profiler not during the reload

verbal dome
#

Do you use probuilder?

#

If not, remove it

opaque owl
#

no

#

ok

verbal dome
#

Yeet it

dusty ember
#

Does anyone have a tutorial for moving 2d instantiated objects forward the direction they're facing?

swift crag
#

(transform.forward would be into the screen in a 2D game)

#

This tells you which direction you want to move in

wintry quarry
swift crag
#

You actually have two smaller problems here!

#
  • How do I know which way to move?
  • How do I move?
#

The second point will vary. Maybe you have a Rigidbody2D, or maybe you're just pushing transforms around

opaque owl
#

also removing probuilder didnt fix it

#

i think if i am
in play mode + just was debugging a script with breakpoints in rider + make a change to said script THEN
stop playmode (i have only compile after playmode on iirc) -> reload domain freeze

swift crag
#

I wonder if attaching a debugger to unity would reveal anything interesting

#

I was doing that while trying to diagnose editor freezes

#

(it's very confusing and complicated)

runic lance
#

does that happen on an empty project?

opaque owl
#

can #nullable enable cause issues?

runic lance
#

it shouldn't, never seen it cause any issues

brittle maple
#

Ok, I have been banging my head on this problem for the last few hours, im working on a first person camera, the code is correct but the camera just moves 2 or less degrees and then instantly resets to 0, has anyone else encountered this problem?

swift crag
#

Show us your code, as well as the inspector for the player object.

#

!code

eternal falconBOT
brittle maple
swift crag
swift crag
#

Nothing in here is setting the rotation of the camera

verbal dome
#

Theres two scripts

swift crag
#

Oh

brittle maple
#

Ye xD

verbal dome
#

Sneaky

swift crag
#

You're directly setting the rotation of the player's transform

#

This is a problem because the Rigidbody also does that every frame

#

It's going to clobber whatever changes you tried to make

#

Consider setting the rigidbody's rotation!

verbal dome
#

You are using the mouse delta for camera rotation

swift crag
#

oh, that too

verbal dome
#

This will not be added together over time, it's just how much your mouse moved this frame

brittle maple
#

hmmmm yes yes, very valuable info.

verbal dome
#

I usually keep track of the camera's X and Y angles in the camera script and add the mouse input to those values

#

While clamping them

#

Then I apply that rotation to my camera

swift crag
#

yep -- just sum up the changes over time

verbal dome
brittle maple
#

I will try...

#

ok but where the hell is the rotation of the rigidbody being reset? Or where is the rigidbody resetting the rotation of the camera?

swift crag
#

the rotation of the camera is proportional to that frame's mouse input

#

if you stop moving the mouse, the camera goes to [0,0,0]

#

because lookX and lookY are zero

#

that's why you need to add up values over time

#

You also have a problem with the rigidbody, though. Since Interpolate is on (which you want), it's updating the transform's position and rotation every frame

#

Whatever changes you make are ignored

#

You'll need to get the player's rigidbody and set its rotation for the left-and-right rotation

verbal dome
#

Plus, you want to do camera rotation in Update or LateUpdate instead of FixedUpdate

swift crag
#

yeah, it'll look gross otherwise

verbal dome
#

Otherwise it might not update each frame

#

Since FixedUpadte isn't necessarily called each frame

swift crag
#

I like to force the camera to look in exactly the right direction in LateUpdate (not just setting the up-and-down rotation)

brittle maple
#

I did add them up, now the Player (aka rigidBody) is rotating but the camera isnt.

verbal dome
#

Show updated code

brittle maple
#

ye sry, i updated the links ( the code), idk if I did it correctly 😅

verbal dome
#

This is not addition:

brittle maple
#

Wait, I got it to work, only the X is reversed but I can just reverse it back, and rigidbody's movement is not good...

verbal dome
#

Yeah, there are more issues

#

You are rotating your player with player.transform.rotation = Quaternion.Euler(0, lookY, 0);
Since the player has a rigidbody this is incorrect, you shouldn't modify a rigidbody's transform directly

#

Use something like rigidbody.MoveRotation() instead, and enable interpolation on the rigidbody

#

Although, the camera rotation relying on the rigidbody's rotation is just asking for trouble..

#

Also you are still rotating the camera in fixedupdate

brittle maple
verbal dome
#

Post new link here, it's easier than going back and forth

#

What type of game is it btw, first person? 3rd person?

brittle maple
#

Im just making anything, so I can learn syntax for when I actually start working on a game

verbal dome
#

Start with rotating the rigidbody correctly instead of using transform

brittle maple
verbal dome
#

What did you do?

brittle maple
#

swapped rigidbody.transform with moveRotation

rigidBody.MoveRotation(Quaternion.Euler(0, cameraY, 0));

still elm
#

I have a scoreTable script called scoreTable in my main Scene. It is attached to an empty gameObject. I want to from my other scene where the game is running on be able to from a script there to call a method from the scoreTable, called AddHighScireEntry. is it possible?

#

Thanks in advance

steep rose
brittle maple
steep rose
#

just use rb.linearvelocity.y or rb.velocity.y where the zero should be

still elm
brittle maple
rich adder
# still elm Maybe dontdestroyonLoad would work?

DontDestroy just puts the gameobject into its own scene called DDOL.
Anything there CAN be accessed from other scenes, but not through the inspector , You can access it with a singleton or clever Dependency Injection

#

afaik something like FindObjectByType only works in the Active scene

still elm
#

is that the best way to do it do you think?

still elm
#

Thanks

#

I will read

untold shore
#

Hey, how do I change the source image to a new sprite from the "Card Image Randomization" Script?
Here's the code from the Randomization Script. Whenever I look at trying to figure out how to change source images, it keeps being weird.


    public void Start()
    {
        AddCardImage();
        
    }

    public void AddCardImage()
    {
        cardSprite = mainCardSprites[Random. Range(0, mainCardSprites.Length)];
    }
}

Thanks

#

Oh hey spawn!

rocky canyon
#

imageComponentReference.~~image ~~sprite = yourimage;

#

for a sprite renderer its spriteRenderer.sprite = yoursprite;

swift crag
#

Image also uses the sprite property

swift crag
#

Your code selects a random sprite from the list and then puts it into cardSprite. It doesn't do anything eles.

untold shore
swift crag
#

well, yeah

#

you aren't doing anything to the Image component

#

so nothing will happen

#

you equally should not expect the color to suddenly become red!

untold shore
#

That's true 😅 Sorry, Im very new, didn't even know it was going to be image component. Thanks!

flat sphinx
#

where's hte "set up UT" button

#

oh ok i need apackage for this

slender nymph
#

what is "UT" in this context?

slender nymph
#

did you forget where you are again?

untold shore
slender nymph
untold shore
#

Hey Spawn and Fen, don't know if yall are still in here but wanted to say thanks for the help!

flat sphinx
slender nymph
rocky canyon
# swift crag `Image` also uses the `sprite` property

you right.. it is sprite for either or.. idk why i was thinking .image
also.. is this that "intellicode" i keep hearing about? lol..
first time using visualstudio in ages. i disabled Co-Pilot but had forgotten about intellicode..

flat sphinx
#

need a random unit test for "da grade" and am assuming unity made it more convoluted than "just doing a unit test in cshart"

rocky canyon
#

i was like "daaaang.. studio has gotten smarter since last i used it" 😅

flat sphinx
#

oh

#

found it

#

yeah scrap that question

#

ok an actual question this time around
how do i access obj instances through a test script without making said script execute every frame

#

(which i assume [UnityTest] is doing)

slender nymph
#

you should really read the documentation about the test runner package

rich adder
slender nymph
#

considering there is an entire course that takes you through exactly how to use the package with excellent examples, exercises to complete (and their solutions) right in the package documentation, i sincerely doubt that it doesn't help much

flat sphinx
#

can you juts tell me how do i reference my GameManager from a test

slender nymph
#

does it exist in the test?

flat sphinx
#

take a guess

slender nymph
#

no

flat sphinx
#

correct

slender nymph
#

so if it does not even exist, it isn't a matter of getting a reference to it, you need to instantiate it

#

crazy how that works, right?

flat sphinx
#

well i cant instantiate it if it doesnt even recognize its type

slender nymph
#

ah and here we come to the actual problem. you didn't read the documentation about setting up asmdefs for your project.

slender nymph
#

sure, if "go read the actual instructions instead of asking redundant questions that are answered by the instructions" is the same as "get bent" then yes, get bent

#

your idea of "the instructions don't help because i didn't read them" is not appreciated here

queen adder
#

why does this thing have to exist, is this even useful?

white yew
rich adder
queen adder
flat sphinx
slender nymph
white yew
flat sphinx
#

i assume its tangentially related to "hey use this stuff"

slender nymph
#

don't make assumptions. make an effort to learn

native flame
#

Holy crap you guys are toxic

#

Yikes

swift crag
#

OK

slender nymph
rich adder
#

new profile, checks out

flat sphinx
steep rose
slender nymph
#

"read the documentation" is not toxic.

native flame
#

But you are

rich adder
#

spoonfeeding every step would be more "toxic" because they wont learn

swift crag
flat sphinx
native flame
#

I would strongly recommend making some friends

#

They help when it comes to social skills

flat sphinx
#

also no im not forming conclusions on the server as a whole on you alone

rich adder
slender nymph
swift crag
#

importantly, they also include a list of assemblies that'll be referenced

flat sphinx
slender nymph
# flat sphinx it is how you word it

right so you decided to specifically say that the documentation was not helpful, then you almost immediately demonstrated that you didn't bother reading it and assumed i was just telling you to get bent.
the toxicity is on your end, mate. but that's okay i don't have to help you

swift crag
slender nymph
queen adder
#

🍿

flat sphinx
#

oh

#

fuck im blind

#

yeah mb

rich adder
#

too busy ragin, less reading

swift crag
flat sphinx
#

wait nvm it is the convoluted shit

rich adder
#

tbh personally dont find unit test as useful in games as I do in regular apps

swift crag
#

I prefer other kinds of analysis

#

I wrote some tools to scan for missing serialized references, for example

#

a bunch of validators!

rich adder
#

there are just so many possibles with games its diffcult to unittest

white yew
flat sphinx
rich adder
#

they can but there are better ways imo

swift crag
north kiln
#

The answer is that if you're not using assembly definitions across your project you won't be able to reference that content

flat sphinx
swift crag
#

If a script does not have an assembly definition, it gets thrown into Assembly-CSharp, which you can't reference explicitly

flat sphinx
#

or texture validification or such

swift crag
#

which is a problem, because the Unity Test Framework looks for tests in code that's explicitly put into an assembly

#

You can, however, just throw everything into a new assembly definition. That's roughly how my game is set up right now.

#

Everything in the scripts folder is in the "GameName" assembly by default

north kiln
#

Except you'll need to handle Editor folders

swift crag
#

I punted the editor folder out of the scripts folder 😛

swift crag
#

A folder named "Editor" puts its scripts into the Assembly-CSharp-Editor assembly by default.

#

which references Assembly-CSharp

north kiln
swift crag
#

I'd have done an explicit editor asmdef if I had anything more complex going on

runic lance
#

why not create a proper editor asmdef?

flat sphinx
#

any place to peek the defined assemblies?

swift crag
#

i haven't had a reason to yet!

swift crag
north kiln
#

But yeah a single root for runtime scripts and one for editor (if any) per logical group is the typical asmdefs setup

swift crag
#

You can also search the project window for t:asmdef

flat sphinx
swift crag
#

see..."Solution Explorer"?

#

yeah, there should be a Solution Explorer window

#

you can focus on it from the command palette if needed

flat sphinx
#

OH

#

yeah i see it

swift crag
#

I dunno if Unity has a straight-up list of the assemblies it knows about

north kiln
flat sphinx
#

assumed theres nothing in the explorer view besides files cuz of how barebones it typically is agony

rich adder
swift crag
#

(well, I made my giant game assembly auto-referenced, at least)

north kiln
#

Oh right that makes sense

swift crag
#

so the default editor assembly eventually sees it

north kiln
#

Trash, but makes sense lol

swift crag
#

I don't think I have anything inside Assembly-CSharp!

#

nevermind, one random constants file mad

#

(used by a build tool)

swift crag
#

none game with left beef

flat sphinx
rich adder
swift crag
#

.asset is a generic extension used by many unity assets

#

I have a ton of localization tables that all use that extension

#
% find Assets -name '*.asset' | wc -l
    2423
#

kersplat

flat sphinx
#

eee @swift crag like this?

swift crag
#

every scriptable object asset will also be an .asset file

swift crag
rich adder
#

in file explorer only thing that doesnt are raw files like .cs or .png etc.

north kiln
swift crag
#

just having a peek, I imagine

flat sphinx
#

ama restart vsc or sm then cuz intellisense still refuses to gimme the class

north kiln
#

But yeah you can see that the default assembly will reference everything, but references can't be two way so there's no way for the test assembly to reference it

swift crag
#

If you want to run tests on your game's code, you'll need to throw all of your game's script assets into a new assembly (an asmdef in the "Scripts" folder will do). This will cause a giant pile of errors.

You then need to explicitly reference each assembly your code depends on. It should be pretty intuitive based on the names of the assemblies and the errors you're getting

#

You can then reference your game assembly from the test assembly

#

mmm, assemblies!

flat sphinx
ebon sapphire
#

Hey so i got a question... I'm wanting to learn coding so i don't have to rely on outside sources, but where can I go to do so?

flat sphinx
#

if so then yes thats what im doing

flat sphinx
swift crag
#

consider following the tutorial, then

flat sphinx
#

graaargghghh fiiiiine

north kiln
swift crag
#

the test assembly references the game assembly

flat sphinx
#

vsc wont pick up intellisense in the test folder anymore

swift crag
#

I would kill VSCode, regenerate project files (Preferences -> External Tools), then reopen VSCode

#

I'm pretty sure I had to do that after creating a new assembly

flat sphinx
#

fun

swift crag
#

I also had a really funny issue once where all of my .csproj files had everything in them twice for

#

some reason

#

even when regenerating project files! it was very weird

#

I just nuked all of the .csproj files to fix that

flat sphinx
#

well it works now

#

now i can actually write the test

#

yippie!

#

ok so how do i tell if a class' member is actually set and not the weird voodoo not-set that unity seems to populate non-nullable GameObject vars with

#

field w/e

short hazel
#

field != null will do it

#

== and != are overriden by Unity so they check for the "fake null" state of Unity objects

flat sphinx
short hazel
#

As a complement, avoid using x is null, ?., ??, ??= on Unity types (the ones deriving from UnityEngine.Object) - these bypass the fake null check and you can get exceptions with these, as the object will be destroyed but not null yet

flat sphinx
#

noted

#

probably wont be using most of these anyways
besides ?., im a big fan

#

buzzkill

rich adder
#

?. only works on c# objects System.Object

#

like Action

#

etc

#

coroutines you can use ?? since they are regular Coroutine(YieldInstruction object) / IEnumerator methods

short hazel
#

Debug.Log(myVariable is not UnityEngine.Object): with this you can know whether you can use the null-operators on the type. If you get "True", all good, else avoid

flat sphinx
north kiln
flat sphinx
#

so how do i wait until Start() has executed

#

yield return null before stuff?

#

nop that didnt work

#

prolly breaks cuz its not initing it in the first place but then uhhhhghghhghg how do i init it proper

#

cuz the Initialize() whatever it was called i don t think includes editor mods

teal viper
#

If you can't provide a dependency, you'd usually use a dummy object.

#

Or refactor your code such that it works well without that dependency.

#

Which might make the test useless. Honestly, I wouldn't get into automated tests as a beginner.

heavy knoll
#

Anyone know how to go about using inheritance for mineable/harvestable resource nodes for a survival game? Should i have a base class called resources and then a derived class for stone/gold/iron/wood/logs? Or should i sort it even more by having a base resources class then stone and wood each deriving from it and then from stone have iron/gold deriving from stone and then from wood have logs or different tree types deriving from wood?

thorny basalt
heavy knoll
#

oh i just mean like resource nodes as in mineable objects in a survival game

rich adder
#

they're trying to abstract their game objects

thorny basalt
#

Oh wait nevermind.

rich adder
thorny basalt
ripe shard
#

i.e. gameobjects + components

rich adder
#

Resource : ScriptableObject Wood : Resource
etc.

swift crag
#

If each kind of resource "behaves" the same way, there is no need to have a class for each resource

#

just create a scriptable object asset for each one and reference that whenever you need to identify a resource type

rich adder
#

true

swift crag
#

You can attach things like the name and the graphics to that asset

#

To me, a "resource" is just an identifier

#

You staple a name, description, sprite, etc. to the identifier

heavy knoll
swift crag
#

This could be a property of the "resource nodes" rather than the resource itself

#

but if it is a property of the resource, then you can just add more fields to Resource

rich adder
swift crag
#

Also having each resource have a different set amount of items it can drop, the resource name, description.

so hang on a second...

#

You're describing a thing you can go and break to receive items

heavy knoll
#

different kinds of stones/ores/trees and stuff

swift crag
#

I see. I misunderstood your original question

#

I was thinking about the things you get from mining, not the things you mine

heavy knoll
#

ooh all good

thorny basalt
swift crag
#

I'd consider putting that data into the "resource node" prefab

#

You can have a list of valid ways to gather than resource node

#

maybe "pickaxe with at least 50 power"

thorny basalt
swift crag
#

Yeah, no inheritance here at all

#

unless you have complex resource-gathering mechanics

#

in which case you'd have different classes for different "modes"

heavy knoll
#

oh i thought this would be a good spot to use inheritance

#

oops

swift crag
#

like, if you have a deeply complex wood-chopping simulation, then yeah -- you're going to need code for that

#

But if every node is harvested by smacking it with a tool, then you don't need any special logic

thorny basalt
heavy knoll
#

i mean wood might be different than stone as i'd need an axe to mine it or a pickaxe to mine the stone

swift crag
#

you're just smacking it with a different tool

#

"different" would be something like requiring a unique minigame to be played

#

vs. just beating the crap out of the rock

heavy knoll
#

wait so how do i do different resource nodes like that though without having to make an entirely new script from scratch for each one?

swift crag
#

You'd have one ResourceNode class that stores a few things

#
  • What you get for breaking the node
  • What you need to break the node

notably

#

The way I see, there's a spectrum.

One end is "unique class for every single thing". This is ridiculous because there's probably a lot of common behavior between different things in your game -- a blue skeleton works a lot like a red skeleton.

One end is "one class for everything". This is ridiculous because this class has to be flexible enough to do absolutely everything, even though it's very unlikely that every "thing" in your game needs to be able to do every possible interaction.

wintry quarry
thorny basalt
heavy knoll
#

so i'd just have the ResourceNode script that'll have all the important data and stuff in variables about the nodes stats and some methods on in involving the breaking of it?
and i just use that same script on each gameObject?

swift crag
#

Right. You'd have one ResourceNode component.

#

Now, each prefab could have very different art assets on it

#

one might just be a rock; another could be a very large crystal with an elaborate animation when it breaks

#

This is a very important skill: realizing when two things that look different are actually the same concept

heavy knoll
#

what if i wanted the tree to be a bit different from the stone in the future though like only the tree could get burned down by some fire element damage and if it got burned down than it wont drop anything or something like that

rich adder
#

put a Flammable component or something that destroys object when consumed by flame

flat sphinx
#

dont care for all the ci fluff surrounding it

heavy knoll
#

also what about inheritance with items like tools armor and just normal items

#

should i use it with that

#

like items class

thorny basalt
flat sphinx
#

is annoying that i have to jump through hoops when i just want to check if vars in a list arent null

heavy knoll
#

then armor and weapons or consumables and resources

thorny basalt
teal viper
flat sphinx
flat sphinx
#

that part i have down already

#

just need a test as a last-minute slapon

thorny basalt
flat sphinx
teal viper
flat sphinx
#

which would be fine if half of its vars werent slapped on through the editor

#

as for "write a different one" am failing to think of any that wouldnt be pointless

teal viper
flat sphinx
#

ok
so if im to do that im back to the "how do i set a gameobject variable through code"

acoustic sequoia
#

Hey 🙂
I have a question about how to handle and gameplay-pause and unpause system i'm trying to create. it's simple and it sounds like this:

first event: player levels up.

UpgradeSelectionUIAnimation() <--- waited for the pause to finish.

next event: player selects upgrade.

await GamePauseAnimation(!isPausing) <---- waited for the selection animation to finish before resuming.

this is the system i want to create and i've already create the player levels up bit.. but i made it using Coroutines...

Question:
should i be using async/await Task or continue using coroutines. I think i see an issue with this using coroutines.. but not sure exactly.

any help would be great. thanks

teal viper
flat sphinx
teal viper
#

In various ways. The ideal one is assigning it in the inspector. The less ideal ones are using the Find methods to find it by name or to tag.

flat sphinx
#

i mean i can if i assign stuff directly

#

i think

#

but here im trying to test game_manager and that itself has its stuff set through inspector

cerulean bear
#

when I press play my character falls through the map and I can still jump no matter where my character is how to fix it

flat sphinx
#

and thats enough layers of editorening for the "working around it" making me ask if im testing the code or the test

cerulean bear
flat sphinx
#

to the floor

#

either that or uncheck is trigger

rich adder
#

they are not solid

flat sphinx
#

dont collide*

#

tho ye in his case they just dont

rich adder
#

you would need two colliders if you want it to Collide with solids while still using OnTrigger

cerulean bear
#

wait so ground didn't have rigidbody

rich adder
#

Rigidbody is for moving objects

#

usually

#

colliders are what create solid ground/walls/objects..

cerulean bear
#

oh I just had to check provides contacts

#

but thx for the help

rich adder
#

uhh what

lament agate
#

Can someone give me a tip how to add this receiver? My "AI script" has target and i filled it with my other character. My animator has transition between Attack and Run. Unity newbie here

green flame
#

Can someone explain me how to dynamically create a GameObject ?
I would like to create this alien from c# and not from here (this will be a wave of mob) ^^

lament agate
#

@slender nymph im trying to understand it. I have three components, one is animator , one navmesh system, one AI target script. "Make a method matching the name of the event", what is an event? Is it like a parameter in Animator?

rich adder
#

98% of the time you do not need to create a GameObject at runtime
(thats using the constructor as such. GameObject go = new() )

slender nymph
green flame
rich adder
lament agate
#

@slender nymph yeah, i was searching for it. But the problem is.. i dont know where to find it : D Can it be in the animator?

slender nymph
#

it's on your animation
like the guide i linked even gives links to explain what window you need to open

flat sphinx
#

is there a "review my code" channel

#

i want ppl to dunk on my math

green flame
rich adder
#

explicitly ask for review

flat sphinx
#

specifically the update_aim part

#

im not convinced the math cnat be done easier

dusty needle
#

hey guys, im super new to all of this, and I was following along to a tutorial, and in the tutorial, the word Input goes green and the script works, but for some reason it doesnt work for me

slender nymph
#

configure your !IDE

eternal falconBOT
rich adder
dusty needle
rich adder
#

yes you

dusty needle
#

uhh how do I do that? sorry im very new to all this 😭

rich adder
#

a configured IDE is what highlight the proper classes

#

click the Link

rich adder
eternal falconBOT
restive ember
flat sphinx
dusty needle
#

thanks

rich adder
# flat sphinx ? y so

heard there are sus malicous stuff going on, also the layout is fucking horrid, half the realestate space is wasted on "other scripts" and usually its crypto scams

lament agate
#

@slender nymph Sorry i know im dumb when it comes to Unity. But i ve searched all these lines and i cant find this PlayStep event anywhere here. Im on the GrenadierWalkFast clip, so its right place. Or am i in the wrong place?

heavy knoll
#

Anyone know how to fix this warning from popping up? Assets\KinematicCharacterController\Examples\Scripts\StressTestManager.cs(41,29): warning CS0618: 'Physics.autoSimulation' is obsolete: 'Physics.autoSimulation has been replaced by Physics.simulationMode'

slender nymph
rich adder
#

ops beat me to it 🦥

heavy knoll
#

i tried changing the Physics.autoSimulation to Physics.simulationMode and it didnt work

flat sphinx
#

well anyways

rich adder
#

and did you save after?

lament agate
#

@rich adder @slender nymph Thank you. Its indeed that.But i am unable to delete it. I guess its cuz of the clip being in the "read only" mode hmm....

rich adder
flat sphinx
rich adder
flat sphinx
#

math-wise i mean

#

i suck at trig and kinda just botched stuff until it worked

rich adder
#

oh damm yeah you lost me at "math"

flat sphinx
#

damn SKULL

rich adder
#

jk but yeah im bad with trig.. maybe make a thread or post in #archived-code-general . its gona probably get buried here

flat sphinx
#

kk

#

ama do that tmrw tho

lament agate
#

@rich adder ok thx

rich adder
flat sphinx
#

wayyy too fucked to take nay advice

verbal dome
#

What type of game is this, like what perspective?

flat sphinx
verbal dome
#

Why is there a 90 degree offset in the x axis

rich adder
#

this snake casing is driving me mad

flat sphinx
verbal dome
#

Thats why i asked what perspective your game uses

#

Like is it 3D topdown, or just 2D

flat sphinx
#

ah fair

#

3d topdown

#

camera along the y axis, pointing down

verbal dome
#

Ok so things move in the X and Z plane

flat sphinx
flat sphinx
flat sphinx
#

dooo it

verbal dome
#

You could replace a lot of that with... cs Vector3 direction = mouse - transform.position; direction.y = 0; transform.forward = direction;

#

That's all you need to do to rotate

#

But ofc it does similiar trigonometry under the hood

rich adder
#

Ill tell you silly stuff , like cache your Renderer instead GetComponent doing it every frame

flat sphinx
#

yyeaaha i probably should

heavy knoll
verbal dome
rich adder
#

the Asset creator never updated for the new API i guess

#

also those are just Obsolete warnings, they are not game breaking usually

heavy knoll
flat sphinx
#

that'd probably be better yeah

heavy knoll
#

i tried changing it to Physics.simulationMode like it said and it got the red squiggly lines under it and gave an error when trying to save

flat sphinx
#

any way to retrieve the coords from that to pass onto the shooting code tho?

swift crag
#

you can't just stop at "i saw an error"

heavy knoll
slender nymph
#

if you don't use the example stuff you can also just delete it

swift crag
#

you've tried to take the logical negation of an enum

#

which is non-meaningful

#

it's like asking for "not 3"

#

idk...6?

flat sphinx
heavy knoll
swift crag
#

Cannot implicitly convert type 'UnityEngine.SimulationMode' to 'bool'

#

You have an object of type UnityEngine.SimulationMode

#

You tried to use the ! operator on it

#

The ! prefix operator only works with a bool

#

Therefore, C#'s only optino is to try to convert a UnityEngine.SimulationMode into a bool

#

It's an implicit conversion because you didn't do anything to try to convert it

#

a lot like writing int x = 1; float y = x;

#

x implicitly converts from int to float

swift crag
rich adder
#

since you cannot negate a enum like a bool as mentioned

#

also now you have those 3 modes so you have to know which one you need and more importantly why

swift crag
#

An enum type represents a set of options

rich adder
#

I have not used KCC recently so not sure

swift crag
#
public enum Color {
  Red,
  Green,
  Blue
}
#

They're commonly used for making a choice

rich adder
#

My guess, flopping between FixedUpdate and Script with current option

heavy knoll
rich adder
#

since this has to do with physics, you're just switching betwene fixedupdate and script

heavy knoll
rich adder
#

simple if/else statement, or something more fancy with bitshift ig?

heavy knoll
#

ok

rich adder
#

disabled = physics.simulationMode == SimulationMode.Script

#

assuming disabled wants that and not the opposite disabled = physics.simulationMode != SimulationMode.Script

heavy knoll
rich adder
#

why are you declaring enum in there

heavy knoll
rich adder
rocky wyvern
#

It looks like you’re trying to define some data

rich adder
#

irrelevant , you still need a field for it

rocky wyvern
#

That has sort of ‘default’ values for a type of node

#

Like an iron node always needs x tool level and drops 10 iron is that correct?

#

In that case monobehaviours that you attach to objects doesn’t really seem like what you want to be doing

swift crag
#

the premise here is to have a single ResourceNode component type

#

each prefab will have a different configuration of the ResourceNode

heavy knoll
light pelican
#

sorry to interrupt here guys but I've got a quick question about mouse input data.
I get lastMousePosition = Input.mouseScrollDelta; on RMB button down.
I then look for Vector2 mouseMovementDelta = (Vector2)Input.mousePosition - lastMousePosition; Debug.Log(mouseMovementDelta);
the debug log shows that the initial press of RMB each time returns the distance between 0, 0 on my screen and the mouse. So I can leave my mouse still and right click a bunch and my camera (which is supposed to pan, and works great once held) teleports hundreds or thousands of units at a time. what's going on here?

#

oh

#

hold on a second I might be stupid

rich adder
swift crag
#

If you want to be fancy, you could give tools different kinds of "tool powers"

#

a pickaxe would have lost of "break" power and a little "dig" power

#

a shovel would have a lot of "dig" power and a little "break" power

verbal dome
light pelican
#

yep I'm stupid I had mouseScrollDelta as a leftover instead of mousePosition lmao fuck

swift crag
#

splat

rocky wyvern
swift crag
#

classic 🦆 moment

light pelican
#

it's always the second you ask for you help that you realize your mistake isn't it

#

if I hadn't asked I'd have been here for hours!

rocky wyvern
swift crag
rocky wyvern
#

Funny because this was just the conversation in code general

rocky wyvern
flat sphinx
rocky wyvern
#

Without really any benefits except ‘it’s slightly easier’ than storing a reference to an so in the prefab instead

heavy knoll
#

yea i dont really know what's right for me lol

#

i dont wanna get locked into some way and not be able to do something down the line

rich adder
heavy knoll
#

because i did it a certain way to start

flat sphinx
#

it also had.. i dont remember if it was bitflags or just an enum for tool behaviours (f.e wirecutters, hammer, etc)

rocky wyvern
#

I would look into scriptable objects and see if that’s what you need

heavy knoll
#

i just know i want the system to be very modular and easily changeable if i need to do anything more with it

flat sphinx
swift crag
flat sphinx
#

do the iterations bruv

swift crag
#

you know what isn't trivial to fix?

#

not having made a game at all!

flat sphinx
rocky wyvern
#

If you have 20 different node types with relevant data in monobehaviours on prefabs it’s not completely trivial to have to convert all of those to sos if you then decide to swap

rich adder
#

awkwardsweat me with 100GB of projects on "hiatus"

rocky wyvern
#

I suppose you could write a helper script but

flat sphinx
rocky wyvern
#

I don’t personally see the benefit of using monobehaviours here except saving 5mins of time writing the so class

flat sphinx
#

havent touched it in 3 months

#

(the last update was a minor tweak)

swift crag
rich adder
heavy knoll
#

bro my brain hurts from all this XD

flat sphinx
heavy knoll
rocky wyvern
heavy knoll
#

just make it inherit from scriptable object instead of monobehaviour?

swift crag
flat sphinx
#

im just stuck on the same refactor i wanted to do half a year ago agony

rich adder
#

sometimes its easier to just redo than refactor

flat sphinx
#

it was a redo

#

well

#

redo for what i could have redone

#

everything else is so entangled it needs its own refactor

rich adder
#

if it works, refactor only when its absolutely illegible

rocky wyvern
flat sphinx
#

dont do 5 years of out-of-date kids

flat sphinx
swift crag
#

A ResourceNode and a ResourceNodeDefinition would be very tightly coupled together

flat sphinx
#

features["hair"]

#

and it stores a color

#

encoded as "FFF"

#

not even a leading pound

#

or well SOMETIMES it has it

#

but you cant tell so you have to pass it into a sanitizer each time

swift crag
#

One advantage I can foresee is that changing the definitions will work properly with old saved data

#

since the individual nodes wouldn't have any of the actual configuration in them

flat sphinx
#

SO IF YOU READ YOU JTS GET NULL

rocky wyvern
#

When you’re hitting iron ore with ur pick axe you don’t care about the default definition in the so for iron ore

#

The monobehaviours for your ore don’t need to be coupled to the default data at all

swift crag
#

this isn't "default data", though

#

it's just...data

#

this kind of ore node drops 30 iron ore

flat sphinx
#

or cshart idk

#

wanna see how well that paradigm translates over to a non-baby lang

heavy knoll
#

would it be better to just go with inheritance and use a different class for each type of ResourceNode i want so i could have more flexibility in the future, like if i want certain types of nodes to apply special things or do special things to the player, like for example if i eventually wanted to add a ResourceNode called uranium that hurts the player if he gets close to it unless the player has some sort of resistance to the radiation.

heavy knoll
#

i dont really get how to do it, cause i could just have the ResourceNode Script how i have it atm with all the important variables and do scriptable objects for each type of ore/tree or something and just change the values for each one

#

but i dont think that would work because some of them would be different

#

like uranium wouuld have special effects with it

#

but then im making a bunch of derived classes that are basically doing the same thing except for like one or two specific types of different nodes that i want

flat sphinx
#

if you want an item that can switch between an axe and a pickaxe, yeah you could do a transforming subtype but that's one hell of an entrance into subtype hell

teal viper
flat sphinx
#

inheritance is easier than modding in a trait check or even a hook

#

if you're just doing a one-off, yeah just do a subtype

#

just know when to bail on it and dont go off the deep end with children of children of children

teal viper
#

Again, composition is not the opposite of inheritance. These concepts work together like a charm.

#

Composition simply means that you split one module into many smaller once. There can(and usually should) be inheritance within these modules.

flat sphinx
#

🤨
i understand composition as how unity does components

#

or using hooks or traits or such

heavy knoll
#

im so confused XD

lavish nexus
#

Composition is more of has-a relationship rather than an is-a one right?

heavy knoll
#

idk the best way to do it for what im planning to do with different resources around my game that the player can mine/break

flat sphinx
#

analysis paralysis is aids

heavy knoll
#

i just wanna have different things around my game like different trees different stones different ores and stuff but some ores may have different features than others and same with the trees or other things that my player can mine/break

heavy knoll
lavish nexus
#

as lemons said just do it, don't worry about premature optimizations. Get a prototype made and then you can optimize and refactor later.

flat sphinx
#

yeah you want the bestest possible implementation but you quite literally cannot anticipate every usecase you'll think of
and trying to do so paradoxically just leads to more shitcode

white yew
heavy knoll
#

and im still relatively a beginner so idrk what's correct for my vision

flat sphinx
#

theres this one dude i know, very epic, knows his shit
holy fuck does he overengineer his code

white yew
flat sphinx
#

he did like parrying/blocking code and it had some 8 return value flags, 7 parameters for entry stuff

#

overrides for everything

#

NOTHING used it

#

out of those 8 flags only some 2 were used

#

dont be him
just make it work

heavy knoll
flat sphinx
white yew
#

I don't even know what your game is about, let alone talk about these tiny details that stopping you from starting.

flat sphinx
#

do you have ore, period, yet?

heavy knoll
flat sphinx
#

do you have regular blocks?

heavy knoll
#

but also have similar features to them still

heavy knoll
flat sphinx
#

i assume you want some minecraft/terraria-esque mining whatever

#

didnt read into the convo much

heavy knoll
#

Yeah same concept with the survival aspect but not blocky, more like a open world terrain maybe procedurally generated in the future but ill worry about that later lol

#

and those ores/tree types will be scattered around the map and mineable

flat sphinx
#

what do you have so far

heavy knoll
#

each dropping their respective item drop that will fall out onto the floor as a type of rigidbody that i can than pickup

heavy knoll
flat sphinx
#

ok nvm its 3:30 am someone else smack him

#

i need to eep

cosmic dagger
heavy knoll
#

XD thx for the help so far though, i apprecate it

flat sphinx
#

👌

cosmic dagger
#

but yeah, just starting scripting out the ores now. make a SO class, create a few different ore assets, then work on unique traits that different ores will have . . .

white yew
# heavy knoll i dont really get how to do it, cause i could just have the ResourceNode Script ...

Scriptable Object are used like prefabs - They spawn into your world with specific information attached to them. Once they are spawn, they should have information to describe what the object is about.

Looking at your pastebin earlier in the chat - https://paste.ofcode.org/hzCbYxY8XtjZ3mRGX6rUDj
This is too simple, ambiguous, and confusing. You're limiting the players to only have two enums, when there could be plenty of other tools type. If you want an ore to break easily with certain tools, then I would suggest looking into bitflags to help identify which tooltype best to work with.

The name and description can be used in a separate class, but not resource node. You can make a class as Item which holds the string name, description, and other things that describe the object in general. Even include rarity, weight, power, etc.

If you want your system to be modular, then start by keeping it simple. Try to use interface to help create composition for unique class and structure to make objects more interesting and complex.

#

E.g. a Ore class would require a item class, but compose of IBreakable + IBlockable + ICollectable + IPlaceable
Then in your So, you can describe that in your terrain generation process, that orb must spawn around moutain/rocky area of your map. That's entirely up to you in terms of how you play with data in a procedural generation process.

#

imho, start something small. Try generating the terrain and see what data you need to create/customize. That data that you play with can be saved into SO.

junior ivy
#

Hello, I have very simple problem. My TextMeshProUGUI property is null.

using TMPro;
using UnityEngine;

public class DebugInfo : MonoBehaviour
{
    private TextMeshProUGUI text;

    void Start()
    {
        Debug.Log(text); // null
    }
}

I have script assigned to the tmp component

#

Thanks for help 😉

slender nymph
#

it's private. if you want it to appear in the inspector it needs to be marked with the SerializeField attribute or be made public (first option is typically better)

junior ivy
#

I made it [SerializeField] public TextMeshProUGUI text; and it's still null 😦

white yew
white yew
twilit mica
#

Hey everybody, new to Unity but have been programming for years.

Looking for a point in the right direction and topics to research.
I am trying to make a rougelike system where cards can interact with each other.
Example: Using one card makes the next one cheaper, changes the way the next card fires, which element it applies etc.

So far, I've found people suggesting Serialized Objects.
Is that what I should be focusing research on, or do you guys have any other suggestions?

rich adder
#

if its not showing up, you likely have compile errors

upper prawn
#

I'm still struggling to figure out how to handle crop stages for my farming game. I've made an empty GameObject, and drug the FBXs for each of my crop stages under it. On a script on the empty object, I'm trying to write a void plantCrop(string name) method. My idea is that this method would simply find the child with name name + "-seed", and activate it, which would make that model visible. When the day advances, I could deactivate it, find the name-stage1 child, and activate it.
However it looks like the only way to get children is via the transform component? And its indexed, not a search-by-name? Is my idea just not feasible to execute?

white yew
#

Would recommend looking into state machine example to help achieve this process.

ripe shard
twilit mica
#

I'm sorry, what is unclear about it?

#

I'll try to expand on it

ripe shard
#

everything

ripe shard
#

You’re basically asking how to architect a game but give barely any info on its design and features

junior ivy
twilit mica
#

I understand, apologies^^

#

trying to expand on it currently

white yew
slender nymph
slender nymph
white yew
upper prawn
twilit mica
#

@white yew @ripe shard
This is Rounds, by Landfall.

My game is taking inspiration from it.
Currently, the gun object the player has initializes the bullet prefab with values such as Dispersion, Bullet Speed, Size, Damage, etc

This has been easy to make, as it is simply changing values.

But how would I go about changing behaviors, for example, how the damage is applied (DoT instead of instant), how the bullet moves instead of using physics (maybe it tracks the mouse, etc)

white yew
junior ivy
slender nymph
# upper prawn I agree with that but I'm struggling to figure out how to "store" the GameObject...

there are many ways you can accomplish this. one way is you could make a scriptable object that will represent the data for the plants that stores each stage, how long it takes to get to that stage, whatever other data you need. then your seed objects just need to reference the scriptable object to pass it to the actual plant when it is planted, then at each "update" (this would be when your events fire) the plant will check the scriptable object to see what stage it should be at.
of course you can find plenty of tutorials for things like this if you want to explore other options

white yew
# twilit mica <@328641530203996170> <@544260011430248467> This is Rounds, by Landfall. My ga...

One best use of this would be the tag system in DOTS. Now granted, this is a little bit more advance subject, but the principle is there. When you activate the card, you can apply tags to specific target your card instructs to. That target will have either a tag for DOTS to process unique behaviour for your entity, or new components added to your game objects. That component/tag defines new behaviour in your game.

upper prawn
slender nymph
#

it's really the same concept. and you can absolutely use prefabs for that, just instantiate the correct stage and destroy the old stage when it updates

#

or even just have each stage all as part of the same prefab and disable/enable the relevant stages

slender nymph
eternal falconBOT
#

:teacher: Unity Learn ↗

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

junior ivy
#

maybe it's good in a game dev to just get something out of nowhere inside a class

slender nymph
#

wtf are you going on about? how does any of that make any sense in regards to the advice to use GetComponent?

junior ivy
#

I'm used to to DI and instantiate everything or use IoC to have dependencies in my class constructor

slender nymph
#

well guess what, the inspector is a form of DI. just not some big DI framework

white yew
junior ivy
slender nymph
#

it's almost like there are methods specifically for setting up your object's state at the beginning of its lifetime

white yew
#

This seems to lean towards X/Y problem here.

slender nymph
#

and that would be the best place to call GetComponent. you will also be using GetComponent (or the superior TryGetComponent) a lot in your code anyway so you may as well get used to it

white yew
#

We've help answered your problem initially, but you're complaining about a problem entirely not related to your initial problem.

junior ivy
#

ok I guess I will have to use Awake with GetComponent and pretend that it's a autowiring 😄

slender nymph
white yew
floral estuary
#

There are some third party extensions that can add a [GetComponent] or [GetComponentInChildren] attribute that will grab it for you. I do find it a bit odd Unity doesn't have that by now

#

Oh reading things back it seems like you're just asking about DI, which, Zenject is kinda the go-to for Unity DI but it feels like extra bloat to me to add in-depth DI tools on top of what's already there

junior ivy
# white yew Taking a step back here - Why do you need a debuginfo? Didn't you instantiate th...

because I don't get the question tbh

Why do you need a debuginfo?
of course I need DebugInfo to be able to write a script based on magically injected TextMeshProUGUI property

Didn't you instantiate the Text UI somewhere in your code?
I didn't instantiate anything in my code

Don't you already have a reference to that object anyway?
what reference to what object? I have a reference to TextMeshProUGUI but what is wrong with that?

floral estuary
#

It does kinda sound like you want to use Unity but you're heavily resisting the workflow. You're gonna have a bad time fighting the current like that :p

junior ivy
#

To sum things up:
I have to configure my serializable properties because they are not autowired automatically.

slender nymph
#

just drag them in. unity has no way of knowing what object you want to reference

floral estuary
slender nymph
#

or you can use the RequireComponent attribute and call GetComponent in Reset which is called automatically when the component is added in the editor

junior ivy
#

I thought unity has some default behavior for that so my bad

floral estuary
slender nymph
#

note that it is only called when this component is added to an object in the editor or when the component is explicitly reset in the editor

#

Reset is not called in any other context (including when adding components at runtime)

cosmic dagger
#

i do all my component checks and assignments in Reset and call that in Awake . . .

floral estuary
#

I think the conversation mostly revolves around the fact that it's a bit extra that we have to do some of that tho :p

#

there COULD be better defaults for getting references to things, it's not like it's not an important function haha

slender nymph
#

it's also super trivial to write some code generator that adds all this for you (and thereby implementing your own GetComponent attribute or whatever)

floral estuary
white yew
# junior ivy because I don't get the question tbh `Why do you need a debuginfo?` of course I...

My question was clear and simple.

Nothing in unity is magically injected. You either reference it in a class structure that can be access by other class or don't. If you are not instantiating the text element, then how are you spawning the gameobject? You should be able to instantiate a class that holds all of those information available for you to use without having to use GetComponent<T>. If you already have a reference to TextMeshProUGUI then having DebugInfo seems unnecessary as you already have that component to play with?

floral estuary
white yew
#

FWIW, stop thinking C# like it's PHP.

slender nymph
floral estuary
#

but regardless, it's also trivial to do it by hand. That doesn't mean it's not a frequent-enough that it's reasonable to expect some default behaviour around it

floral estuary
signal mango
#

Writing a code generator is definitely not trivial if you want it to handle all cases properly (partial types, name resolution conflicts, etc)

floral estuary
#

like, it's easy to have my own string class, right? just use char[] or List<char>

#

but I wouldn't call it trivial

#

why should I have to do that for the basics

slender nymph